使用vagrant创建一个3节点的主机集群,主机信息如下:
master:192.168.100.100
node1 :192.168.100.101
node2 :192.168.100.102
具体脚本请见 [Vagrantfile]
1.1 关闭防火墙
systemctl disable firewalld.service
systemctl stop firewalld.service
1.2 关闭selinux
getenforce
sestatus -v
setenforce 0
vim /etc/selinux/config
SELINUX=disabled
1.3 ntp 时间同步 ntpdate -u cn.pool.ntp.org
1.4 安装docker
systemctl enable docker
systemctl start docker
vim /lib/systemd/system/docker.service
ExecStartPost=/sbin/iptables -I FORWARD -s 0.0.0.0/0 -j ACCEPT
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["mirror 镜像地址"]
}
EOF
systemctl daemon-reload
systemctl restart docker
1.5 配置内核参数
cat <<EOF > /etc/sysctl.d/usernetwork.conf
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl -p /etc/sysctl.d/usernetwork.conf
2.1下载合适的发行包, 将etcd和etcdctl复制到/usr/bin
2.2应用配置
mkdir /etc/etcd/
cat <<EOF > /etc/etcd/etcd.conf
ETCD_NAME=default
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_CLIENT_URLS="http://127.0.0.1:2379,http://192.168.100.100:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.100.100:2379"
EOF
2.3服务配置
mkdir /var/lib/etcd
cat <<EOF > /usr/lib/systemd/system/etcd.service
[Unit]
Description=Etcd Server
After=network.target
[Service]
Type=simple
WorkingDirectory=/var/lib/etcd/
EnvironmentFile=-/etc/etcd/etcd.conf
ExecStart=/usr/bin/etcd
[Install]
WantedBy=multi-user.target
EOF
2.4启动服务
systemctl enable etcd
systemctl start etcd
ETCDCTL_API=3
etcdctl put foo bar
3.1 下载合适的发行包, 解压, 将flanneld复制到/usr/bin
3.2 应用网段配置
etcdctl --endpoints "http://192.168.100.100:2379" \
set /coreos.com/network/config '{"NetWork":"10.0.0.0/16", "SubnetMin": "10.0.1.0", "SubnetMax": "10.0.20.0"}'
3.3 服务配置
cat <<EOF > /usr/lib/systemd/system/flanneld.service
[Unit]
Description=Flanneld
After=network.target
Before=docker.service
[Service]
User=root
ExecStart=/usr/bin/flanneld \
--etcd-endpoints=http://192.168.100.100:2379 \
--iface=192.168.100.10x \
--ip-masq
Restart=on-failure
Type=notify
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl start flanneld
flanneld 在启动的时候坑最多, flanneld需要export etcdctl的API version 为2, endpoints前后不需要""
A.切换yum镜像源
备份: mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
更新: wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
B.设置时区
tzselect