ETCD集群安装
本文使用vultr虚拟主机实现
邀请注册链接:http://www.vultr.com/?ref=6940267
购买三台位于东京的主机,东京的主机下载速度比较快
每个主机安装一下常用的软件
yum upgrade -y
yum install -y tree git wget p7zip bridge-utils net-tools vim unzip
配置这三台主机的内网IP地址
参考 www.vultr.com 页面中 Sample Network Configuration
修改主机名
修改/etc/sysconfig/network 不生效
配置各机器的主机名
echo "HOSTNAME=vultr.guest-10" >> /etc/sysconfig/network
echo "HOSTNAME=vultr.guest-11" >> /etc/sysconfig/network
echo "HOSTNAME=vultr.guest-12" >> /etc/sysconfig/network
三台机器同时配置
echo "10.99.0.10 vultr.guest-10" >> /etc/hosts
echo "10.99.0.11 vultr.guest-11" >> /etc/hosts
echo "10.99.0.12 vultr.guest-12" >> /etc/hosts
直接修改各机器的以下这两个文件让hostname生效
echo "vultr.guest-10" >/proc/sys/kernel/hostname
echo "vultr.guest-10" >/etc/hostname
echo "vultr.guest-11" >/proc/sys/kernel/hostname
echo "vultr.guest-11" >/etc/hostname
echo "vultr.guest-12" >/proc/sys/kernel/hostname
echo "vultr.guest-12" >/etc/hostname
hostname
创建工作目录
mkdir -p /opt/etcd/
download etcd
wget https://github.com/coreos/etcd/releases/download/v3.1.3/etcd-v3.1.3-linux-amd64.tar.gz
tar -xvf etcd-v3.1.3-linux-amd64.tar.gz
cp -r etcd-v3.1.3-linux-amd64/etcd /opt/etcd/
cp -r etcd-v3.1.3-linux-amd64/etcdctl /opt/etcd/
ls -l /opt/etcd/
在三个节点机器上创建etcd启动文件
cat <<EOF >/lib/systemd/system/etcd.service
[Unit]
Description=ETCD
[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/etcd
ExecStart=/opt/etcd/etcd \$ETCD_NAME \\
\$INITIAL_ADVERTISE_PEER_URLS \\
\$LISTEN_PEER_URLS \\
\$ADVERTISE_CLIENT_URLS \\
\$LISTEN_CLIENT_URLS \\
\$INITIAL_CLUSTER_TOKEN \\
\$INITIAL_CLUSTER \\
\$INITIAL_CLUSTER_STATE \\
\$ETCD_OPTS
Restart=on-failure
EOF
more /lib/systemd/system/etcd.service
设置etcd配置
三台机器各配置一遍(修改一个IP,使用内网IP)该文件为服务的配置文件,三台主机的ETCD_NAME、INITIAL_ADVERTISE_PEER_URLS和ADVERTISE_CLIENT_URLS参数各不相同
ETCD_NAME注意与INITIAL_CLUSTER中的配置一致
cat <<EOF >/etc/sysconfig/etcd
# configure file for etcd
# -name
ETCD_NAME='-name k8sETCD0'
# -initial-advertise-peer-urls
INITIAL_ADVERTISE_PEER_URLS='-initial-advertise-peer-urls http://10.99.0.10:2379'
# -listen-peer-urls
LISTEN_PEER_URLS='-listen-peer-urls http://0.0.0.0:2379'
# -advertise-client-urls
ADVERTISE_CLIENT_URLS='-advertise-client-urls http://10.99.0.10:2378,http://10.99.0.10:2380'
# -listen-client-urls
LISTEN_CLIENT_URLS='-listen-client-urls http://0.0.0.0:2378,http://0.0.0.0:2380'
# -initial-cluster-token
INITIAL_CLUSTER_TOKEN='-initial-cluster-token k8s-etcd-cluster'
# -initial-cluster
INITIAL_CLUSTER='-initial-cluster k8sETCD0=http://10.99.0.10:2379,k8sETCD1=http://10.99.0.12:2379,k8sETCD2=http://10.99.0.11:2379'
# -initial-cluster-state
INITIAL_CLUSTER_STATE='-initial-cluster-state new'
# other parameters
ETCD_OPTS=''
EOF
more /etc/sysconfig/etcd
--------
cat <<EOF >/etc/sysconfig/etcd
# configure file for etcd
# -name
ETCD_NAME='-name k8sETCD1'
# -initial-advertise-peer-urls
INITIAL_ADVERTISE_PEER_URLS='-initial-advertise-peer-urls http://10.99.0.11:2379'
# -listen-peer-urls
LISTEN_PEER_URLS='-listen-peer-urls http://0.0.0.0:2379'
# -advertise-client-urls
ADVERTISE_CLIENT_URLS='-advertise-client-urls http://10.99.0.11:2378,http://10.99.0.11:2380'
# -listen-client-urls
LISTEN_CLIENT_URLS='-listen-client-urls http://0.0.0.0:2378,http://0.0.0.0:2380'
# -initial-cluster-token
INITIAL_CLUSTER_TOKEN='-initial-cluster-token k8s-etcd-cluster'
# -initial-cluster
INITIAL_CLUSTER='-initial-cluster k8sETCD0=http://10.99.0.10:2379,k8sETCD1=http://10.99.0.11:2379,k8sETCD2=http://10.99.0.12:2379'
# -initial-cluster-state
INITIAL_CLUSTER_STATE='-initial-cluster-state new'
# other parameters
ETCD_OPTS=''
EOF
more /etc/sysconfig/etcd
----------
cat <<EOF >/etc/sysconfig/etcd
# configure file for etcd
# -name
ETCD_NAME='-name k8sETCD2'
# -initial-advertise-peer-urls
INITIAL_ADVERTISE_PEER_URLS='-initial-advertise-peer-urls http://10.99.0.12:2379'
# -listen-peer-urls
LISTEN_PEER_URLS='-listen-peer-urls http://0.0.0.0:2379'
# -advertise-client-urls
ADVERTISE_CLIENT_URLS='-advertise-client-urls http://10.99.0.12:2378,http://10.99.0.12:2380'
# -listen-client-urls
LISTEN_CLIENT_URLS='-listen-client-urls http://0.0.0.0:2378,http://0.0.0.0:2380'
# -initial-cluster-token
INITIAL_CLUSTER_TOKEN='-initial-cluster-token k8s-etcd-cluster'
# -initial-cluster
INITIAL_CLUSTER='-initial-cluster k8sETCD0=http://10.99.0.10:2379,k8sETCD1=http://10.99.0.11:2379,k8sETCD2=http://10.99.0.12:2379'
# -initial-cluster-state
INITIAL_CLUSTER_STATE='-initial-cluster-state new'
# other parameters
ETCD_OPTS=''
EOF
more /etc/sysconfig/etcd
-----------
启动时出现 “没有到主机的路由” 错误
centos7.0(默认是使用firewall作为防火墙,如若未改为iptables防火墙,使用以下命令查看和关闭防火墙)
查看防火墙状态:firewall-cmd --state
关闭防火墙:systemctl stop firewalld.service
firewall-cmd --state
systemctl stop firewalld.service
参考:
http://www.bubuko.com/infodetail-1013314.html
启动ETCD集群
systemctl daemon-reload
systemctl start etcd
检查etcd版本号
curl -L http://10.99.0.10:2380/version
curl -L http://10.99.0.11:2380/version
curl -L http://10.99.0.12:2380/version