day1----安装k8s之部署nginx反向代理(2)
一、安装部署主控节点服务部署master节点服务部署etcd集群集群规则:主机名角色IPhdss7-12.host.cometcdlead10.4.7.12hdss7-21.host.cometcdfollow10.4.7.21hdss7-22.host.cometcdfollow10.4.7.22注意:这里以12为例子,其他两台参考安装1、创建基于根证书的config配置文件首先在hdss7-2
·
一、安装部署主控节点服务
部署master节点服务
部署etcd集群
集群规则:
主机名 | 角色 | IP |
---|---|---|
hdss7-12.host.com | etcd lead | 10.4.7.12 |
hdss7-21.host.com | etcd follow | 10.4.7.21 |
hdss7-22.host.com | etcd follow | 10.4.7.22 |
注意:这里以12为例子,其他两台参考安装
1、创建基于根证书的config配置文件
首先在hdss7-200上做出证书
1、下面就是改配置etcd了需要在hdss7-200进行操作
#配置证书
cat > /opt/certs/ca-config.json <<EOF
{
"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"
]
}
}
}
}
EOF
cat > /opt/certs/etcd-peer-csr.json <<EOF
{
"CN": "k8s-etcd",
"hosts": [
"10.4.7.11",
"10.4.7.12",
"10.4.7.21",
"10.4.7.22"
],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"ST": "beijing",
"L": "beijing",
"O": "od",
"OU": "ops"
}
]
}
EOF
2、创建证书。并查看证书是否创建好了
cd /opt/certs/
cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=peer etcd-peer-csr.json |cfssl-json -bare etcd-peer
ll
有下面的内容说明证书已经创建好了
[root@hdss7-200 certs]# ll
total 36
-rw-r--r--. 1 root root 836 May 29 23:15 ca-config.json
-rw-r--r--. 1 root root 993 May 29 17:45 ca.csr
-rw-r--r--. 1 root root 328 May 29 17:32 ca-csr.json
-rw-------. 1 root root 1679 May 29 17:45 ca-key.pem
-rw-r--r--. 1 root root 1346 May 29 17:45 ca.pem
-rw-r--r--. 1 root root 1062 May 29 23:15 etcd-peer.csr
-rw-r--r--. 1 root root 363 May 29 23:15 etcd-peer-csr.json
-rw-------. 1 root root 1679 May 29 23:15 etcd-peer-key.pem
-rw-r--r--. 1 root root 1428 May 29 23:15 etcd-peer.pe
2、创建etcd–分别在三台机上进行创建
首先在12上进行创建
[root@hdss7-12 ~]# mkdir /opt/src
[root@hdss7-12 ~]# cd /opt/src/
[root@hdss7-12 src]# ll
total 0
[root@hdss7-12 src]# useradd -s /sbin/nologin -M etcd
[root@hdss7-12 src]# rz -E
rz waiting to receive.
[root@hdss7-12 src]# ll
total 9620
-rw-r--r-- 1 root root 9850227 May 25 22:31 etcd-v3.1.20-linux-amd64.tar.gz
[root@hdss7-12 src]# tar zxf etcd-v3.1.20-linux-amd64.tar.gz -C /opt[root@hdss7-12 src]# cd /opt/
[root@hdss7-12 opt]# mv etcd-v3.1.20-linux-amd64/ etcd-v3.1.20
[root@hdss7-12 opt]# ln -s /opt/etcd-v3.1.20/ /opt/etcd
[root@hdss7-12 opt]# cd etcd
[root@hdss7-12 etcd]# mkdir -p /opt/etcd/certs /data/etcd /data/logs/etcd-server
[root@hdss7-12 etcd]# cd certs/
[root@hdss7-12 certs]# scp hdss7-200:/opt/certs/ca.pem .
[root@hdss7-12 certs]# scp hdss7-200:/opt/certs/etcd-peer.pem .
[root@hdss7-12 certs]# scp hdss7-200:/opt/certs/etcd-peer-key.pem .
[root@hdss7-12 certs]# cd /opt/etcd
[root@hdss7-12 etcd]# vi etcd-server-startup.sh
[root@hdss7-12 etcd]# cat etcd-server-startup.sh
#!/bin/sh
./etcd --name etcd-server-7-12 \
--data-dir /data/etcd/etcd-server \
--listen-peer-urls https://10.4.7.12:2380 \
--listen-client-urls https://10.4.7.12:2379,http://127.0.0.1:2379 \
--quota-backend-bytes 8000000000 \
--initial-advertise-peer-urls https://10.4.7.12:2380 \
--advertise-client-urls https://10.4.7.12:2379,http://127.0.0.1:2379 \
--initial-cluster etcd-server-7-12=https://10.4.7.12:2380,etcd-server-7-21=https://10.4.7.21:2380,etcd-server-7-22=https://10.4.7.22:2380 \
--ca-file ./certs/ca.pem \
--cert-file ./certs/etcd-peer.pem \
--key-file ./certs/etcd-peer-key.pem \
--client-cert-auth \
--trusted-ca-file ./certs/ca.pem \
--peer-ca-file ./certs/ca.pem \
--peer-cert-file ./certs/etcd-peer.pem \
--peer-key-file ./certs/etcd-peer-key.pem \
--peer-client-cert-auth \
--peer-trusted-ca-file ./certs/ca.pem \
--log-output stdout
[root@hdss7-12 etcd]# chmod +x etcd-server-startup.sh
[root@hdss7-12 etcd]# chown -R etcd.etcd /opt/etcd-v3.1.20/
[root@hdss7-12 etcd]# chown -R etcd.etcd /data/etcd/
[root@hdss7-12 etcd]# chown -R etcd.etcd /data/logs/etcd-server/
[root@hdss7-12 etcd]# sudo yum install epel-release -y
[root@hdss7-12 etcd]# yum -y install supervisor
[root@hdss7-12 etcd]# systemctl start supervisord
[root@hdss7-12 etcd]# systemctl enable supervisord
Created symlink from /etc/systemd/system/multi-user.target.wants/supervisord.service to /usr/lib/systemd/system/supervisord.service.
[root@hdss7-12 etcd]# vi /etc/supervisord.d/etcd-server.ini
[root@hdss7-12 etcd]# cat /etc/supervisord.d/etcd-server.ini
[program:etcd-server-7-12] ; 显示的程序名,类型my.cnf,可以有多个
command=/opt/etcd/etcd-server-startup.sh
numprocs=1 ; 启动进程数 (def 1)
directory=/opt/etcd ; 启动命令前切换的目录 (def no cwd)
autostart=true ; 是否自启 (default: true)
autorestart=true ; 是否自动重启 (default: true)
startsecs=30 ; 服务运行多久判断为成功(def. 1)
startretries=3 ; 启动重试次数 (default 3)
exitcodes=0,2 ; 退出状态码 (default 0,2)
stopsignal=QUIT ; 退出信号 (default TERM)
stopwaitsecs=10 ; 退出延迟时间 (default 10)
user=etcd ; 运行用户
redirect_stderr=true ; 是否重定向错误输出到标准输出(def false)
stdout_logfile=/data/logs/etcd-server/etcd.stdout.log
stdout_logfile_maxbytes=64MB ; 日志文件大小 (default 50MB)
stdout_logfile_backups=4 ; 日志文件滚动个数 (default 10)
stdout_capture_maxbytes=1MB ; 设定capture管道的大小(default 0)
stdout_events_enabled=false ; 子进程还有子进程,需要添加这个参数,避免产生孤儿进程
[root@hdss7-12 etcd]# supervisorctl update
etcd-server-7-12: added process group
[root@hdss7-12 etcd]# supervisorctl status
etcd-server-7-12 STARTING
[root@hdss7-12 etcd]# supervisorctl status
etcd-server-7-12 STARTING
[root@hdss7-12 etcd]# tail -fn 200 /data/logs/etcd-server/etcd.stdout.log
2021-08-25 20:11:36.670777 I | rafthttp: started HTTP pipelining with peer 5a0ef2a004fc4349
2021-08-25 20:11:36.671441 I | rafthttp: started streaming with peer 5a0ef2a004fc4349 (writer)
2021-08-25 20:11:36.672325 I | rafthttp: started peer 5a0ef2a004fc4349
2021-08-25 20:11:36.672351 I | rafthttp: added peer 5a0ef2a004fc4349
2021-08-25 20:11:36.672364 I | etcdserver: starting server... [version: 3.1.20, cluster version: to_be_decided]
........
[root@hdss7-12 etcd]# supervisorctl status
etcd-server-7-12 RUNNING pid 25178, uptime 0:00:59
[root@hdss7-12 etcd]# netstat -luntp |grep etcd 下面说明部署好了
tcp 0 0 10.4.7.12:2379 0.0.0.0:* LISTEN 25179/./etcd
tcp 0 0 127.0.0.1:2379 0.0.0.0:* LISTEN 25179/./etcd
tcp 0 0 10.4.7.12:2380 0.0.0.0:* LISTEN 25179/./etcd
在做一个在21上做etcd
[root@hdss7-21 ~]# mkdir /opt/src
[root@hdss7-21 ~]# useradd -s /sbin/nologin -M etcd
[root@hdss7-21 ~]# cd /opt/src
[root@hdss7-21 src]# pwd
/opt/src
[root@hdss7-21 src]# ^C
[root@hdss7-21 src]# tar zxvf etcd-v3.1.20-linux-amd64.tar.gz -C /opt/
[root@hdss7-21 src]# cd /opt/
[root@hdss7-21 opt]# mv etcd-v3.1.20-linux-amd64/ etcd-v3.1.20
[root@hdss7-21 opt]# ln -s /opt/etcd-v3.1.20/ /opt/etcd
[root@hdss7-21 opt]# cd /opt/etcd
[root@hdss7-21 etcd]# mkdir -p /opt/etcd/certs /data/etcd /data/logs/etcd-server
[root@hdss7-21 etcd]# cd /opt/etcd/certs
[root@hdss7-21 certs]# scp hdss7-200:/opt/certs/ca.pem .
[root@hdss7-21 certs]# scp hdss7-200:/opt/certs/etcd-peer.pem .
etcd-peer.pem 100% 1428 1.2MB/s 00:00
[root@hdss7-21 certs]# scp hdss7-200:/opt/certs/etcd-peer-key.pem .
etcd-peer-key.pem 100% 1679 515.6KB/s 00:00
[root@hdss7-21 certs]# ll
total 12
-rw-r--r-- 1 root root 1346 Aug 25 20:26 ca.pem
-rw------- 1 root root 1679 Aug 25 20:27 etcd-peer-key.pem
-rw-r--r-- 1 root root 1428 Aug 25 20:27 etcd-peer.pem
[root@hdss7-21 certs]# cd /opt/etcd/
[root@hdss7-21 etcd]# vi etcd-server-startup.sh
[root@hdss7-21 etcd]# chmod +x etcd-server-startup.sh
[root@hdss7-21 etcd]# chown -R etcd.etcd /opt/etcd-v3.1.20/
[root@hdss7-21 etcd]# chown -R etcd.etcd /data/etcd/
[root@hdss7-21 etcd]# chown -R etcd.etcd /data/logs/etcd-server/
[root@hdss7-21 etcd]# sudo yum install epel-release -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
base | 3.6 kB 00:00:00
https://download.docker.com/linux/centos/7/x86_64/stable/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: download.docker.com; Unknown error"
Trying other mirror.
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
Package epel-release-7-13.noarch already installed and latest version
Nothing to do
[root@hdss7-21 etcd]# yum -y install supervisor
[root@hdss7-21 etcd]# systemctl start supervisord
[root@hdss7-21 etcd]# systemctl enable supervisord
Created symlink from /etc/systemd/system/multi-user.target.wants/supervisord.service to /usr/lib/systemd/system/supervisord.service.
[root@hdss7-21 etcd]# vi /etc/supervisord.d/etcd-server.ini
[root@hdss7-21 etcd]# supervisorctl update
etcd-server-7-21: added process group
[root@hdss7-21 etcd]# supervisorctl status
etcd-server-7-21 STARTING
[root@hdss7-21 etcd]# tail -fn 200 /data/logs/etcd-server/etcd.stdout.log
[root@hdss7-21 etcd]# supervisorctl status
etcd-server-7-21 RUNNING pid 28560, uptime 0:00:37
等三台等running后去检查先集群的健康情况,在任意一台都行
[root@hdss7-22 etcd]# netstat -luntp |grep etcd
tcp 0 0 10.4.7.22:2379 0.0.0.0:* LISTEN 26655/./etcd
tcp 0 0 127.0.0.1:2379 0.0.0.0:* LISTEN 26655/./etcd
tcp 0 0 10.4.7.22:2380 0.0.0.0:* LISTEN 26655/./etcd
[root@hdss7-22 etcd]# ./etcdctl cluster-health
member 988139385f78284 is healthy: got healthy result from http://127.0.0.1:2379
member 5a0ef2a004fc4349 is healthy: got healthy result from http://127.0.0.1:2379
member f4a0cb0a765574a8 is healthy: got healthy result from http://127.0.0.1:2379
cluster is healthy
[root@hdss7-22 etcd]# ./etcdctl member list
988139385f78284: name=etcd-server-7-22 peerURLs=https://10.4.7.22:2380 clientURLs=http://127.0.0.1:2379,https://10.4.7.22:2379 isLeader=false
5a0ef2a004fc4349: name=etcd-server-7-21 peerURLs=https://10.4.7.21:2380 clientURLs=http://127.0.0.1:2379,https://10.4.7.21:2379 isLeader=false
f4a0cb0a765574a8: name=etcd-server-7-12 peerURLs=https://10.4.7.12:2380 clientURLs=http://127.0.0.1:2379,https://10.4.7.12:2379 isLeader=true
二、部署kube-apiserver
集群规划
主机名 | 角色 | ip |
---|---|---|
hdss7-21.host.com | kube-apiserver | 10.4.7.21 |
hdss7-22.host.com | kube-apiserver | 10.4.7.22 |
hdss7-11.host.com | 4层负载均衡 | 10.4.7.11 |
hdss7-12.host.com | 4层负载均衡 | 10.4.7.12 |
注意:这里的10.4.7.11和10.4.7.12使用nginx做4层负载均衡,用keepalived跑一个vip:10.4.7.10 代理两个kube-apiserver,实现高可用
这里部署文档以hdss7-21.host.com 主机为例,另外的运算节点参考类似
下载软件解压,做软连接
下载地址::
需要安装在10.4.7.21和10.4.7.22上
https://github.com/kubernetes/kubernetes
https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.15.md#downloads-for-v11512
[root@hdss7-21 etcd]# cd /opt/src/
[root@hdss7-21 src]# ll
total 9620
-rw-r--r-- 1 root root 9850227 Aug 25 20:21 etcd-v3.1.20-linux-amd64.tar.gz
[root@hdss7-21 src]# rz -E
rz waiting to receive.
[root@hdss7-21 src]# tar xf kubernetes-server-linux-amd64-v1.15.2.tar.gz -C /opt/
[root@hdss7-21 src]# cd /opt/
[root@hdss7-21 opt]# mv kubernetes/ kubernetes-v1.15.2
[root@hdss7-21 opt]# ln -s /opt/kubernetes-v1.15.2/ /opt/kubernetes
[root@hdss7-21 opt]# ll
total 20
drwx--x--x 4 root root 4096 Aug 24 22:01 containerd
lrwxrwxrwx 1 root root 18 Aug 25 20:22 etcd -> /opt/etcd-v3.1.20/
drwxr-xr-x 4 etcd etcd 4096 Aug 25 20:29 etcd-v3.1.20
lrwxrwxrwx 1 root root 24 Aug 25 20:56 kubernetes -> /opt/kubernetes-v1.15.2/
drwxr-xr-x 4 root root 4096 Aug 5 2019 kubernetes-v1.15.2
drwxr-xr-x. 2 root root 4096 Oct 31 2018 rh
drwxr-xr-x 2 root root 4096 Aug 25 20:53 src
[root@hdss7-21 opt]# cd kubernetes
[root@hdss7-21 kubernetes]# ll
total 27192
drwxr-xr-x 2 root root 4096 Aug 5 2019 addons
-rw-r--r-- 1 root root 26625140 Aug 5 2019 kubernetes-src.tar.gz
-rw-r--r-- 1 root root 1205293 Aug 5 2019 LICENSES
drwxr-xr-x 3 root root 4096 Aug 5 2019 server
[root@hdss7-21 kubernetes]# rm -f kubernetes-src.tar.gz
[root@hdss7-21 kubernetes]# cd server/
[root@hdss7-21 server]# cd bin/
[root@hdss7-21 bin]# ll
total 1548804
-rwxr-xr-x 1 root root 43534816 Aug 5 2019 apiextensions-apiserver
-rwxr-xr-x 1 root root 100548640 Aug 5 2019 cloud-controller-manager
-rw-r--r-- 1 root root 8 Aug 5 2019 cloud-controller-manager.docker_tag
-rw-r--r-- 1 root root 144437760 Aug 5 2019 cloud-controller-manager.tar
-rwxr-xr-x 1 root root 200648416 Aug 5 2019 hyperkube
-rwxr-xr-x 1 root root 40182208 Aug 5 2019 kubeadm
-rwxr-xr-x 1 root root 164501920 Aug 5 2019 kube-apiserver
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-apiserver.docker_tag
-rw-r--r-- 1 root root 208390656 Aug 5 2019 kube-apiserver.tar
-rwxr-xr-x 1 root root 116397088 Aug 5 2019 kube-controller-manager
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-controller-manager.docker_tag
-rw-r--r-- 1 root root 160286208 Aug 5 2019 kube-controller-manager.tar
-rwxr-xr-x 1 root root 42985504 Aug 5 2019 kubectl
-rwxr-xr-x 1 root root 119616640 Aug 5 2019 kubelet
-rwxr-xr-x 1 root root 36987488 Aug 5 2019 kube-proxy
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-proxy.docker_tag
-rw-r--r-- 1 root root 84282368 Aug 5 2019 kube-proxy.tar
-rwxr-xr-x 1 root root 38786144 Aug 5 2019 kube-scheduler
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-scheduler.docker_tag
-rw-r--r-- 1 root root 82675200 Aug 5 2019 kube-scheduler.tar
-rwxr-xr-x 1 root root 1648224 Aug 5 2019 mounter
[root@hdss7-21 bin]# rm -f *.tar
[root@hdss7-21 bin]# ll
total 884660
-rwxr-xr-x 1 root root 43534816 Aug 5 2019 apiextensions-apiserver
-rwxr-xr-x 1 root root 100548640 Aug 5 2019 cloud-controller-manager
-rw-r--r-- 1 root root 8 Aug 5 2019 cloud-controller-manager.docker_tag
-rwxr-xr-x 1 root root 200648416 Aug 5 2019 hyperkube
-rwxr-xr-x 1 root root 40182208 Aug 5 2019 kubeadm
-rwxr-xr-x 1 root root 164501920 Aug 5 2019 kube-apiserver
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-apiserver.docker_tag
-rwxr-xr-x 1 root root 116397088 Aug 5 2019 kube-controller-manager
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-controller-manager.docker_tag
-rwxr-xr-x 1 root root 42985504 Aug 5 2019 kubectl
-rwxr-xr-x 1 root root 119616640 Aug 5 2019 kubelet
-rwxr-xr-x 1 root root 36987488 Aug 5 2019 kube-proxy
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-proxy.docker_tag
-rwxr-xr-x 1 root root 38786144 Aug 5 2019 kube-scheduler
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-scheduler.docker_tag
-rwxr-xr-x 1 root root 1648224 Aug 5 2019 mounter
[root@hdss7-21 bin]# rm -f *.tag
[root@hdss7-21 bin]# ll
total 884660
-rwxr-xr-x 1 root root 43534816 Aug 5 2019 apiextensions-apiserver
-rwxr-xr-x 1 root root 100548640 Aug 5 2019 cloud-controller-manager
-rw-r--r-- 1 root root 8 Aug 5 2019 cloud-controller-manager.docker_tag
-rwxr-xr-x 1 root root 200648416 Aug 5 2019 hyperkube
-rwxr-xr-x 1 root root 40182208 Aug 5 2019 kubeadm
-rwxr-xr-x 1 root root 164501920 Aug 5 2019 kube-apiserver
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-apiserver.docker_tag
-rwxr-xr-x 1 root root 116397088 Aug 5 2019 kube-controller-manager
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-controller-manager.docker_tag
-rwxr-xr-x 1 root root 42985504 Aug 5 2019 kubectl
-rwxr-xr-x 1 root root 119616640 Aug 5 2019 kubelet
-rwxr-xr-x 1 root root 36987488 Aug 5 2019 kube-proxy
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-proxy.docker_tag
-rwxr-xr-x 1 root root 38786144 Aug 5 2019 kube-scheduler
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-scheduler.docker_tag
-rwxr-xr-x 1 root root 1648224 Aug 5 2019 mounter
[root@hdss7-21 bin]# rm -f *_tag
[root@hdss7-21 bin]# ll
total 884640
-rwxr-xr-x 1 root root 43534816 Aug 5 2019 apiextensions-apiserver
-rwxr-xr-x 1 root root 100548640 Aug 5 2019 cloud-controller-manager
-rwxr-xr-x 1 root root 200648416 Aug 5 2019 hyperkube
-rwxr-xr-x 1 root root 40182208 Aug 5 2019 kubeadm
-rwxr-xr-x 1 root root 164501920 Aug 5 2019 kube-apiserver
-rwxr-xr-x 1 root root 116397088 Aug 5 2019 kube-controller-manager
-rwxr-xr-x 1 root root 42985504 Aug 5 2019 kubectl
-rwxr-xr-x 1 root root 119616640 Aug 5 2019 kubelet
-rwxr-xr-x 1 root root 36987488 Aug 5 2019 kube-proxy
-rwxr-xr-x 1 root root 38786144 Aug 5 2019 kube-scheduler
-rwxr-xr-x 1 root root 1648224 Aug 5 2019 mounter
[root@hdss7-21 bin]# pwd
/opt/kubernetes/server/bin
[root@hdss7-21 bin]# mkdir cert
[root@hdss7-21 bin]# cd cert/
[root@hdss7-21 cert]# ll
total 0
[root@hdss7-21 cert]# scp hdss7-200:/opt/certs/ca.pem .
ca.pem 100% 1346 1.9MB/s 00:00
[root@hdss7-21 cert]# scp hdss7-200:/opt/certs/ca-key.pem .
ca-key.pem 100% 1679 1.3MB/s 00:00
[root@hdss7-21 cert]# scp hdss7-200:/opt/certs/client.pem .
client.pem 100% 1363 1.0MB/s 00:00
[root@hdss7-21 cert]# scp hdss7-200:/opt/certs/client-key.pem .
client-key.pem 100% 1675 743.8KB/s 00:00
[root@hdss7-21 cert]# scp hdss7-200:/opt/certs/apiserver.pem .
apiserver.pem 100% 1598 1.0MB/s 00:00
[root@hdss7-21 cert]# scp hdss7-200:/opt/certs/apiserver-key.pem .
apiserver-key.pem 100% 1679 1.1MB/s 00:00
[root@hdss7-21 cert]# ll
total 24
-rw------- 1 root root 1679 Aug 25 21:05 apiserver-key.pem
-rw-r--r-- 1 root root 1598 Aug 25 21:05 apiserver.pem
-rw------- 1 root root 1679 Aug 25 21:05 ca-key.pem
-rw-r--r-- 1 root root 1346 Aug 25 21:05 ca.pem
-rw------- 1 root root 1675 Aug 25 21:05 client-key.pem
-rw-r--r-- 1 root root 1363 Aug 25 21:05 client.pem
[root@hdss7-21 cert]# cd ..
[root@hdss7-21 bin]# mkdir conf
[root@hdss7-21 bin]# cd conf/
[root@hdss7-21 conf]# vi audit.yaml
[root@hdss7-21 conf]# cat audit.yaml
apiVersion: audit.k8s.io/v1beta1 # This is required.
kind: Policy
# Don't generate audit events for all requests in RequestReceived stage.
omitStages:
- "RequestReceived"
rules:
# Log pod changes at RequestResponse level
- level: RequestResponse
resources:
- group: ""
# Resource "pods" doesn't match requests to any subresource of pods,
# which is consistent with the RBAC policy.
resources: ["pods"]
# Log "pods/log", "pods/status" at Metadata level
- level: Metadata
resources:
- group: ""
resources: ["pods/log", "pods/status"]
# Don't log requests to a configmap called "controller-leader"
- level: None
resources:
- group: ""
resources: ["configmaps"]
resourceNames: ["controller-leader"]
# Don't log watch requests by the "system:kube-proxy" on endpoints or services
- level: None
users: ["system:kube-proxy"]
verbs: ["watch"]
resources:
- group: "" # core API group
resources: ["endpoints", "services"]
# Don't log authenticated requests to certain non-resource URL paths.
- level: None
userGroups: ["system:authenticated"]
nonResourceURLs:
- "/api*" # Wildcard matching.
- "/version"
# Log the request body of configmap changes in kube-system.
- level: Request
resources:
- group: "" # core API group
resources: ["configmaps"]
# This rule only applies to resources in the "kube-system" namespace.
# The empty string "" can be used to select non-namespaced resources.
namespaces: ["kube-system"]
# Log configmap and secret changes in all other namespaces at the Metadata level.
- level: Metadata
resources:
- group: "" # core API group
resources: ["secrets", "configmaps"]
# Log all other resources in core and extensions at the Request level.
- level: Request
resources:
- group: "" # core API group
- group: "extensions" # Version of group should NOT be included.
# A catch-all rule to log all other requests at the Metadata level.
- level: Metadata
# Long-running requests like watches that fall under this rule will not
# generate an audit event in RequestReceived.
omitStages:
- "RequestReceived"
[root@hdss7-21 conf]# vi /opt/kubernetes/server/bin/kube-apiserver.sh
[root@hdss7-21 conf]# cd ..
[root@hdss7-21 bin]# ll
total 884652
-rwxr-xr-x 1 root root 43534816 Aug 5 2019 apiextensions-apiserver
drwxr-xr-x 2 root root 4096 Aug 25 21:05 cert
-rwxr-xr-x 1 root root 100548640 Aug 5 2019 cloud-controller-manager
drwxr-xr-x 2 root root 4096 Aug 25 21:08 conf
-rwxr-xr-x 1 root root 200648416 Aug 5 2019 hyperkube
-rwxr-xr-x 1 root root 40182208 Aug 5 2019 kubeadm
-rwxr-xr-x 1 root root 164501920 Aug 5 2019 kube-apiserver
-rw-r--r-- 1 root root 1078 Aug 25 21:09 kube-apiserver.sh
-rwxr-xr-x 1 root root 116397088 Aug 5 2019 kube-controller-manager
-rwxr-xr-x 1 root root 42985504 Aug 5 2019 kubectl
-rwxr-xr-x 1 root root 119616640 Aug 5 2019 kubelet
-rwxr-xr-x 1 root root 36987488 Aug 5 2019 kube-proxy
-rwxr-xr-x 1 root root 38786144 Aug 5 2019 kube-scheduler
-rwxr-xr-x 1 root root 1648224 Aug 5 2019 mounter
[root@hdss7-21 bin]# chmod +x kube-apiserver.sh
[root@hdss7-21 bin]# cat kube-apiserver.sh
#!/bin/bash
./kube-apiserver \
--apiserver-count 2 \
--audit-log-path /data/logs/kubernetes/kube-apiserver/audit-log \
--audit-policy-file ./conf/audit.yaml \
--authorization-mode RBAC \
--client-ca-file ./cert/ca.pem \
--requestheader-client-ca-file ./cert/ca.pem \
--enable-admission-plugins NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota \
--etcd-cafile ./cert/ca.pem \
--etcd-certfile ./cert/client.pem \
--etcd-keyfile ./cert/client-key.pem \
--etcd-servers https://10.4.7.12:2379,https://10.4.7.21:2379,https://10.4.7.22:2379 \
--service-account-key-file ./cert/ca-key.pem \
--service-cluster-ip-range 192.168.0.0/16 \
--service-node-port-range 3000-29999 \
--target-ram-mb=1024 \
--kubelet-client-certificate ./cert/client.pem \
--kubelet-client-key ./cert/client-key.pem \
--log-dir /data/logs/kubernetes/kube-apiserver \
--tls-cert-file ./cert/apiserver.pem \
--tls-private-key-file ./cert/apiserver-key.pem \
--v 2
[root@hdss7-21 bin]# mkdir -p /data/logs/kubernetes/kube-apiserver
[root@hdss7-21 bin]# vi /etc/supervisord.d/kube-apiserver.ini
[root@hdss7-21 bin]# supervisorctl update
kube-apiserver-7-21: added process group
[root@hdss7-21 bin]# supervisorctl status
etcd-server-7-21 RUNNING pid 28560, uptime 0:38:34
kube-apiserver-7-21 STARTING
[root@hdss7-21 bin]# supervisorctl status
etcd-server-7-21 RUNNING pid 28560, uptime 0:38:41
kube-apiserver-7-21 STARTING
[root@hdss7-21 bin]# supervisorctl status
etcd-server-7-21 RUNNING pid 28560, uptime 1:08:56
kube-apiserver-7-21 RUNNING pid 29012, uptime 0:30:29
[root@hdss7-21 bin]# ll
total 884652
-rwxr-xr-x 1 root root 43534816 Aug 5 2019 apiextensions-apiserver
drwxr-xr-x 2 root root 4096 Aug 25 21:05 cert
-rwxr-xr-x 1 root root 100548640 Aug 5 2019 cloud-controller-manager
drwxr-xr-x 2 root root 4096 Aug 25 21:08 conf
-rwxr-xr-x 1 root root 200648416 Aug 5 2019 hyperkube
-rwxr-xr-x 1 root root 40182208 Aug 5 2019 kubeadm
-rwxr-xr-x 1 root root 164501920 Aug 5 2019 kube-apiserver
-rwxr-xr-x 1 root root 1078 Aug 25 21:09 kube-apiserver.sh
-rwxr-xr-x 1 root root 116397088 Aug 5 2019 kube-controller-manager
-rwxr-xr-x 1 root root 42985504 Aug 5 2019 kubectl
-rwxr-xr-x 1 root root 119616640 Aug 5 2019 kubelet
-rwxr-xr-x 1 root root 36987488 Aug 5 2019 kube-proxy
-rwxr-xr-x 1 root root 38786144 Aug 5 2019 kube-scheduler
-rwxr-xr-x 1 root root 1648224 Aug 5 2019 mounter
[root@hdss7-21 bin]# netstat -luntp |grep kube-api
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 29013/./kube-apiser
tcp6 0 0 :::6443 :::* LISTEN 29013/./kube-apiser
[root@hdss7-21 bin]# netstat -atunp |grep kube-api
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 29013/./kube-apiser
tcp 0 0 10.4.7.21:34332 10.4.7.21:2379 ESTABLISHED 29013/./kube-apiser
tcp 0 0 10.4.7.21:34376 10.4.7.21:2379 ESTABLISHED 29013/./kube-apiser
tcp 0 0 10.4.7.21:34178 10.4.7.21:2379 ESTABLISHED 29013/./kube-apiser
tcp 0 0 10.4.7.21:39520 10.4.7.22:2379 ESTABLISHED 29013/./kube-apiser
1、下面就是去22上进行部署 ----和21基本上一样的不再多说
[root@hdss7-22 ~]# cd /opt/src/
[root@hdss7-22 src]# ll
total 9620
-rw-r--r-- 1 root root 9850227 May 25 22:31 etcd-v3.1.20-linux-amd64.tar.gz
[root@hdss7-22 src]# scp hdss7-21.host.com:/opt/src/kubernetes-server-linux-amd64-v1.15.2.tar.gz .
The authenticity of host 'hdss7-21.host.com (10.4.7.21)' can't be established.
ECDSA key fingerprint is SHA256:S8lqSXkRnqiGTHxKRSz2BsEbZ45BZTzgVUg611F56/0.
ECDSA key fingerprint is MD5:bb:9d:b7:1f:be:e3:0a:cc:2a:58:5b:13:56:df:c9:82.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'hdss7-21.host.com,10.4.7.21' (ECDSA) to the list of known hosts.
root@hdss7-21.host.com's password:
kubernetes-server-linux-amd64-v1.15.2.tar.gz 100% 423MB 121.6MB/s 00:03
[root@hdss7-22 src]# ll
total 442992
-rw-r--r-- 1 root root 9850227 May 25 22:31 etcd-v3.1.20-linux-amd64.tar.gz
-rw-r--r-- 1 root root 443770238 Jun 1 23:25 kubernetes-server-linux-amd64-v1.15.2.tar.gz
[root@hdss7-22 src]# tar xf kubernetes-server-linux-amd64-v1.15.2.tar.gz -C /opt/
[root@hdss7-22 src]# cd /opt/
[root@hdss7-22 opt]# mv kubernetes/ kubernetes-v1.15.2
[root@hdss7-22 opt]# ln -s /opt/kubernetes-v1.15.2/ /opt/kubernetes
[root@hdss7-22 opt]# cd kubernetes
[root@hdss7-22 kubernetes]# rm -f kubernetes-src.tar.gz
[root@hdss7-22 kubernetes]# cd server/
[root@hdss7-22 server]# ll
total 4
drwxr-xr-x 2 root root 4096 Aug 5 2019 bin
[root@hdss7-22 server]# cd bin/
[root@hdss7-22 bin]# ll
total 1548800
-rwxr-xr-x 1 root root 43534816 Aug 5 2019 apiextensions-apiserver
-rwxr-xr-x 1 root root 100548640 Aug 5 2019 cloud-controller-manager
-rw-r--r-- 1 root root 8 Aug 5 2019 cloud-controller-manager.docker_tag
-rw-r--r-- 1 root root 144437760 Aug 5 2019 cloud-controller-manager.tar
-rwxr-xr-x 1 root root 200648416 Aug 5 2019 hyperkube
-rwxr-xr-x 1 root root 40182208 Aug 5 2019 kubeadm
-rwxr-xr-x 1 root root 164501920 Aug 5 2019 kube-apiserver
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-apiserver.docker_tag
-rw-r--r-- 1 root root 208390656 Aug 5 2019 kube-apiserver.tar
-rwxr-xr-x 1 root root 116397088 Aug 5 2019 kube-controller-manager
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-controller-manager.docker_tag
-rw-r--r-- 1 root root 160286208 Aug 5 2019 kube-controller-manager.tar
-rwxr-xr-x 1 root root 42985504 Aug 5 2019 kubectl
-rwxr-xr-x 1 root root 119616640 Aug 5 2019 kubelet
-rwxr-xr-x 1 root root 36987488 Aug 5 2019 kube-proxy
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-proxy.docker_tag
-rw-r--r-- 1 root root 84282368 Aug 5 2019 kube-proxy.tar
-rwxr-xr-x 1 root root 38786144 Aug 5 2019 kube-scheduler
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-scheduler.docker_tag
-rw-r--r-- 1 root root 82675200 Aug 5 2019 kube-scheduler.tar
-rwxr-xr-x 1 root root 1648224 Aug 5 2019 mounter
[root@hdss7-22 bin]# rm -f *.tar
[root@hdss7-22 bin]# rm -f *_tag
[root@hdss7-22 bin]# ll
total 884636
-rwxr-xr-x 1 root root 43534816 Aug 5 2019 apiextensions-apiserver
-rwxr-xr-x 1 root root 100548640 Aug 5 2019 cloud-controller-manager
-rwxr-xr-x 1 root root 200648416 Aug 5 2019 hyperkube
-rwxr-xr-x 1 root root 40182208 Aug 5 2019 kubeadm
-rwxr-xr-x 1 root root 164501920 Aug 5 2019 kube-apiserver
-rwxr-xr-x 1 root root 116397088 Aug 5 2019 kube-controller-manager
-rwxr-xr-x 1 root root 42985504 Aug 5 2019 kubectl
-rwxr-xr-x 1 root root 119616640 Aug 5 2019 kubelet
-rwxr-xr-x 1 root root 36987488 Aug 5 2019 kube-proxy
-rwxr-xr-x 1 root root 38786144 Aug 5 2019 kube-scheduler
-rwxr-xr-x 1 root root 1648224 Aug 5 2019 mounter
[root@hdss7-22 bin]# mkdir cert
[root@hdss7-22 bin]# mkdir conf
[root@hdss7-22 bin]# cd cert/
[root@hdss7-22 cert]# scp hdss7-200:/opt/certs/ca.pem .
root@hdss7-200's password:
ca.pem 100% 1346 1.3MB/s 00:00
[root@hdss7-22 cert]# ll
total 4
-rw-r--r-- 1 root root 1346 Jun 1 23:31 ca.pem
[root@hdss7-22 cert]# scp hdss7-200:/opt/certs/ca-key.pem .
root@hdss7-200's password:
ca-key.pem 100% 1679 667.4KB/s 00:00
[root@hdss7-22 cert]# scp hdss7-200:/opt/certs/client.pem .
root@hdss7-200's password:
client.pem 100% 1363 321.8KB/s 00:00
[root@hdss7-22 cert]# scp hdss7-200:/opt/certs/client-key.pem .
root@hdss7-200's password:
client-key.pem 100% 1675 665.0KB/s 00:00
[root@hdss7-22 cert]# scp hdss7-200:/opt/certs/apiserver.pem .
root@hdss7-200's password:
apiserver.pem 100% 1598 652.1KB/s 00:00
[root@hdss7-22 cert]# scp hdss7-200:/opt/certs/apiserver-key.pem .
root@hdss7-200's password:
apiserver-key.pem 100% 1679 1.5MB/s 00:00
[root@hdss7-22 cert]# ll
total 24
-rw------- 1 root root 1679 Jun 1 23:33 apiserver-key.pem
-rw-r--r-- 1 root root 1598 Jun 1 23:33 apiserver.pem
-rw------- 1 root root 1679 Jun 1 23:32 ca-key.pem
-rw-r--r-- 1 root root 1346 Jun 1 23:31 ca.pem
-rw------- 1 root root 1675 Jun 1 23:33 client-key.pem
-rw-r--r-- 1 root root 1363 Jun 1 23:32 client.pem
[root@hdss7-22 cert]# cd ../conf/
[root@hdss7-22 conf]# scp hdss7-21.host.com:/opt/kubernetes/server/bin/conf/audit.yaml .
root@hdss7-21.host.com's password:
audit.yaml 100% 2224 2.1MB/s 00:00
[root@hdss7-22 conf]# ll
total 4
-rw-r--r-- 1 root root 2224 Jun 1 23:35 audit.yaml
[root@hdss7-22 conf]# vi audit.yaml
[root@hdss7-22 conf]# ll
total 4
-rw-r--r-- 1 root root 2223 Jun 1 23:36 audit.yaml
[root@hdss7-22 conf]# cd ..
[root@hdss7-22 bin]# ls
apiextensions-apiserver cloud-controller-manager hyperkube kube-apiserver kubectl kube-proxy mounter
cert conf kubeadm kube-controller-manager kubelet kube-scheduler
[root@hdss7-22 bin]# pwd
/opt/kubernetes/server/bin
[root@hdss7-22 bin]# scp hdss7-21:/opt/kubernetes/server/bin/kube-apiserver.sh .
root@hdss7-21's password:
kube-apiserver.sh 100% 1078 449.4KB/s 00:00
[root@hdss7-22 bin]# ll
total 884640
-rwxr-xr-x 1 root root 43534816 Aug 5 2019 apiextensions-apiserver
drwxr-xr-x 2 root root 124 Jun 1 23:33 cert
-rwxr-xr-x 1 root root 100548640 Aug 5 2019 cloud-controller-manager
drwxr-xr-x 2 root root 24 Jun 1 23:36 conf
-rwxr-xr-x 1 root root 200648416 Aug 5 2019 hyperkube
-rwxr-xr-x 1 root root 40182208 Aug 5 2019 kubeadm
-rwxr-xr-x 1 root root 164501920 Aug 5 2019 kube-apiserver
-rwxr-xr-x 1 root root 1078 Jun 1 23:37 kube-apiserver.sh
-rwxr-xr-x 1 root root 116397088 Aug 5 2019 kube-controller-manager
-rwxr-xr-x 1 root root 42985504 Aug 5 2019 kubectl
-rwxr-xr-x 1 root root 119616640 Aug 5 2019 kubelet
-rwxr-xr-x 1 root root 36987488 Aug 5 2019 kube-proxy
-rwxr-xr-x 1 root root 38786144 Aug 5 2019 kube-scheduler
-rwxr-xr-x 1 root root 1648224 Aug 5 2019 mounter
[root@hdss7-22 bin]# scp hdss7-21:/opt/kubernetes/server/bin/kube-apiserver.ini .
root@hdss7-21's password:
scp: /opt/kubernetes/server/bin/kube-apiserver.ini: No such file or directory
[root@hdss7-22 bin]# scp hdss7-21:/opt/kubernetes/server/bin/kube-apiserver.ini .^C
[root@hdss7-22 bin]# scp hdss7-21:/etc/supervisord.d/kube-apiserver.ini /etc/supervisord.d/kube-apiserver.ini
root@hdss7-21's password:
kube-apiserver.ini 100% 1940 452.2KB/s 00:00
[root@hdss7-22 bin]# vi /etc/supervisord.d/kube-apiserver.ini
[program:kube-apiserver-7-22]
command=/opt/kubernetes/server/bin/kube-apiserver.sh ; the program (relative uses PATH, can take args)
numprocs=1 ; number of processes copies to start (def 1)
directory=/opt/kubernetes/server/bin ; 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=root ; setuid to this UNIX account to run the program
redirect_stderr=true ; redirect proc stderr to stdout (default false)
stdout_logfile=/data/logs/kubernetes/kube-apiserver/apiserver.stdout.log ; stderr 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)
[root@hdss7-22 bin]# supervisorctl update
error: <class 'xmlrpclib.Fault'>, <Fault 92: "CANT_REREAD: The directory named as part of the path /data/logs/kubernetes/kube-apiserver/apiserver.stdout.log does not exist in section 'program:kube-apiserver-7-22' (file: '/etc/supervisord.d/kube-apiserver.ini')">: file: /usr/lib64/python2.7/xmlrpclib.py line: 794
[root@hdss7-22 bin]# mkdir -p /data/logs/kubernetes/kube-apiserver
[root@hdss7-22 bin]# supervisorctl update
kube-apiserver-7-22: added process group
[root@hdss7-22 bin]# supervisorctl status
etcd-server-7-22 RUNNING pid 9387, uptime 2 days, 1:11:24
kube-apiserver-7-22 RUNNING pid 29281, uptime 0:00:50
2、测试是否apiservice是否启动成功了
回到21上也看下是不是也已经为runing了
[root@hdss7-21 bin]# supervisorctl status
etcd-server-7-21 RUNNING pid 83220, uptime 2 days, 22:33:32
kube-apiserver-7-21 RUNNING pid 91806, uptime 0:22:45
对21和22上都要查看下监听的两个端口
[root@hdss7-22 ~]# netstat -luntp |grep kube-api
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 29282/./kube-apiser
tcp6 0 0 :::6443 :::* LISTEN 29282/./kube-apiser
[root@hdss7-21 ~]# netstat -atunp |grep kube-api
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 91807/./kube-apiser
tcp 0 0 10.4.7.21:36048 10.4.7.21:2379 ESTABLISHED 91807/./kube-apiser
tcp 0 0 10.4.7.21:36220 10.4.7.21:2379 ESTABLISHED 91807/./kube-apiser
tcp 0 0 10.4.7.21:51616 10.4.7.12:2379 ESTABLISHED 91807/./kube-apiser
tcp 0 0 10.4.7.21:46266 10.4.7.22:2379 ESTABLISHED 91807/./kube-apiser
tcp 0 0 10.4.7.21:35778 10.4.7.21:2379 ESTABLISHED 91807/./kube-apiser
tcp 0 0 10.4.7.21:35984 10.4.7.21:2379 ESTABLISHED 91807/./kube-apiser
tcp 0 0 10.4.7.21:36116 10.4.7.21:2379 ESTABLISHED 91807/./kube-apiser
tcp 0 0 10.4.7.21:36198 10.4.7.21:2379 ESTABLISHED 91807/./kube-apiser
tcp 0 0 10.4.7.21:36018 10.4.7.21:2379 ESTABLISHED 91807/./kube-apiser 下面还有很多这里省略不写
三、安装部署主控节点L4反向服务
安装nginx的加入模块时候一直报错
然后我就直接安装了
yum -y install nginx nginx-all-modules.noarch
接下来就是需要在11和12上进行操作了
1、首先我们在11上进行操作,,这里需要用到的是kube-Proxy
HDSS7-11上进行操作,,首先安装nginx
[root@hdss7-11 ~]# yum -y install nginx nginx-all-modules.noarch
2、去给nginx配置主配置文件
解释一下 我们把21和22上的6443端口反代到我们本机的7443端口
/etc/nginx/nginx.conf ##放在下面
stream {
upstream kube-apiserver {
server 10.4.7.21:6443 max_fails=3 fail_timeout=30s;
server 10.4.7.22:6443 max_fails=3 fail_timeout=30s;
}
server {
listen 7443;
proxy_connect_timeout 2s;
proxy_timeout 900s;
proxy_pass kube-apiserver;
}
}
3、启动nginx
[root@hdss7-11 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@hdss7-11 ~]# systemctl start nginx
[root@hdss7-11 ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@hdss7-11 ~]#
4、安装keepalived
[root@hdss7-11 ~]# yum -y install keepalived
5、做一个keepalived的脚本,注意下面的那些解释的内容不需要贴进去
/etc/keepalived/check_port.sh
#!/bin/bash
#keepalived 监控端口脚本
#使用方法:
#在keepalived的配置文件中
#vrrp_script check_port {#创建一个vrrp_script脚本,检查配置
# script "/etc/keepalived/check_port.sh 6379" #配置监听的端口
# interval 2 #检查脚本的频率,单位(秒)
#}
CHK_PORT=$1
if [ -n "$CHK_PORT" ];then
PORT_PROCESS=`ss -lnt|grep $CHK_PORT|wc -l`
if [ $PORT_PROCESS -eq 0 ];then
echo "Port $CHK_PORT Is Not Used,End."
exit 1
fi
else
echo "Check Port Cant Be Empty!"
fi
[root@hdss7-11 ~]# chmod +x /etc/keepalived/check_port.sh
6、修改配置文件
/etc/keepalived/keepalived.conf
! Configuration File keepalived
global_defs {
router_id 10.4.7.11
}
vrrp_script chk_nginx {
script "/etc/keepalived/check_port.sh 7443"
interval 2
weight -20
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 251
priority 100
advert_int 1
mcast_src_ip 10.4.7.11
nopreempt
authentication {
auth_type PASS
auth_pass 11111111
}
track_script {
chk_nginx
}
virtual_ipaddress {
10.4.7.10
}
}
7、下面是12上做的它做从
/etc/keepalived/keepalived.conf -----注意这个文件有很多不同之处
! Configuration File keepalived
global_defs {
router_id 10.4.7.12
}
vrrp_script chk_nginx {
script "/etc/keepalived/check_port.sh 7443"
interval 2
weight -20
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 251
mcast_src_ip 10.4.7.12
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 11111111
}
track_script {
chk_nginx
}
virtual_ipaddress {
10.4.7.10
}
}
8、启动keepalived 并查看日志
[root@hdss7-11 ~]# systemctl start keepalived
[root@hdss7-11 ~]# systemctl enable keepalived
查看日志 tail -fn 200 /var/log/messages ##发现是执行脚本出错了 查看原来是ss -lnt |grep 7443少了一个选项n
Jun 2 22:35:19 hdss7-11 Keepalived_vrrp[94421]: /etc/keepalived/check_port.sh 7443 exited with status 1
Jun 2 22:35:21 hdss7-11 Keepalived_vrrp[94421]: /etc/keepalived/check_port.sh 7443 exited with status 1
Jun 2 22:35:23 hdss7-11 Keepalived_vrrp[94421]: /etc/keepalived/check_port.sh 7443 exited with status 1
Jun 2 22:35:25 hdss7-11 Keepalived_vrrp[94421]: /etc/keepalived/check_port.sh 7443 exited with status 1
更多推荐
已为社区贡献14条内容
所有评论(0)