安装部署主控节点服务 -- etcd
部署master节点服务
部署etcd集群
集群规划
主机名 角色 ip
a2 ectc lead 192.168.7.12
a3 ectc follow 192.168.7.21
a4 ectc follow 192.168.7.22
在运维主机a5上创建基于根证书的config配置文件
[root@a5 ~]# vi /opt/certs/ca-config.json
{
"signing": {
"default": {
"expiry": "175200h"
},
"profiles": {
"server": {
"expiry": "175200h",
"usages": [
"signing",
"key encipherment",
"server auth"
]
},
"client": {
"expiry": "175200h",
"usages": [
"signing",
"key encipherment",
"client auth"
]
},
"peer": {
"expiry": "175200h",
"usages": [
"signing",
"key encipherment",
"server auth",
"client auth"
]
}
}
}
}
profiles
client 客户端和服务端通信需要证书
server server端需要证书
peer互相通信 需要证书
P地址为有可能装ETCD的主机,多一个IP为预备
host是可能在那些机器上部署etcd 必须为ip 不能接端口
[root@a5 ~]# vi /opt/certs/etcd-peer-csr.json
{
"CN": "k8s-etcd",
"hosts": [
"192.168.7.11",
"192.168.7.12",
"192.168.7.21",
"192.168.7.22"
],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"ST": "hunan",
"L": "changsha",
"O": "xixi",
"OU": "haha"
}
]
}
[root@a5 certs]# cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=client client-csr.json |cfssl-json -bare client
在etcd主机上创建etcd用户
# useradd -s /sbin/nologin -M etcd
# id etcd
# cd /opt/src/
启动etcd需要三个证书
下载etcd软件,建议用不超3.3的版本
# ls
etcd-v3.1.20-linux-amd64.tar.gz
# tar xfv etcd-v3.1.20-linux-amd64.tar.gz -C /opt/
# cd ..
# mv etcd-v3.1.20-linux-amd64 etcd-v3.1.20
创建软链接方便以后更新版本
[root@hdss7-12 opt]# ln -s /opt/etcd-v3.1.20 /opt/etcd
# ll
总用量 0
lrwxrwxrwx 1 root root 17 12月 10 16:45 etcd -> /opt/etcd-v3.1.20
drwxr-xr-x 3 478493 89939 123 10月 11 2018 etcd-v3.1.20
drwxr-xr-x 2 root root 45 12月 10 16:41 src
etcd最重要etcd启动文件 etcdctl控制工具
创建目录,拷贝证书、私钥
# mkdir -p /opt/etcd/certs /data/etcd /data/logs/etcd-server
将运维主机上生成的ca.pem etc-peer-key.pem etc-peer.pem 拷贝到/opt/etcd/certs目录中,私钥文件权限为600
[root@a2 certs]# scp a5:/opt/certs/ca.pem .
[root@a2 certs]# scp a5:/opt/certs/etcd-peer.pem .
[root@a2 certs]# scp a5:/opt/certs/etcd-peer-key.pem .
更改属主属组
# cd /opt/etcd/certs
# chown -R etcd.etcd /opt/etcd/certs /data/etcd /data/logs/etcd-server
chown -R etcd.etcd /opt/etcd-v3.1.20/
创建etcd服务启动脚本
赋予执行权限
chmod +x /opt/etcd/etcd-server-startup.sh
更改属主属组
chown -R etcd.etcd /opt/etcd-v3.1.20/ /data/etcd /data/logs/etcd-server
用supervisor管理etcd
yum install supervisor -y
systemctl start supervisord
systemctl enable supervisord
更改supervisord的配置文件
vi /etc/supervisord.d/etcd-server.ini
[program:etcd-server-a2]
command=/opt/etcd/etcd-server-startup.sh ; the program (relative uses PATH, can take args)
numprocs=1 ; number of processes copies to start (def 1)
directory=/opt/etcd ; directory to cwd to before exec (def no cwd)
autostart=true ; start at supervisord start (default: true)
autorestart=true ; retstart at unexpected quit (default: true)
startsecs=30 ; number of secs prog must stay running (def. 1)
startretries=3 ; max # of serial start failures (default 3)
exitcodes=0,2 ; 'expected' exit codes for process (default 0,2)
stopsignal=QUIT ; signal used to kill process (default TERM)
stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)
user=etcd ; setuid to this UNIX account to run the program
redirect_stderr=true ; redirect proc stderr to stdout (default false)
stdout_logfile=/data/logs/etcd-server/etcd.stdout.log ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=64MB ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=4 ; # of stdout logfile backups (default 10)
stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
stdout_events_enabled=false ; emit events on stdout writes (default false)
创建后端启动etcd
在a3 a4上做类似配置 a2为lead a3 a4为follow
检查集群状态