测试集群部署

This commit is contained in:
zhanglikun 2023-09-13 10:45:29 +08:00
parent 865b9af4d6
commit c2ae899716
5 changed files with 52 additions and 31 deletions

View File

@ -4,9 +4,7 @@ MASTER2="10.0.0.12"
MASTER3="10.0.0.13" MASTER3="10.0.0.13"
# master 节点的网卡设备名 # master 节点的网卡设备名
MASTER1_NIC="eth0" NETWORK_NIC="eth0"
MASTER2_NIC="eth0"
MASTER3_NIC="eth0"
# api server 填vip或者负载均衡的地址 # api server 填vip或者负载均衡的地址
API_SERVER="10.0.0.10" API_SERVER="10.0.0.10"

View File

@ -8,8 +8,28 @@ if [ $(id -u) != "0" ]; then
exit 1 exit 1
fi fi
# 生成keepalived配置文件
git
sed -e "s/__MASTER1__/${MASTER1}/g" \
-e "s/__MASTER2__/${MASTER2}/g" \
-e "s/__MASTER3__/${MASTER3}/g" \
-e "s/__VIP__/${VIP}/g" \
-e "s/__NETWORK_NIC__/${NETWORK_NIC}/g" \
-i keepalived/*.conf
# 分发仓库文件
scp -r * root@${MASTER1}:/tmp/
scp -r * root@${MASTER2}:/tmp/
scp -r * root@${MASTER3}:/tmp/
# 分发配置
ssh root@${MASTER1} "cd /tmp/keepalived/ && cp keepalived1.conf /etc/keepalived/keepalived.conf && bash install.sh"
ssh root@${MASTER2} "cd /tmp/keepalived/ && cp keepalived2.conf /etc/keepalived/keepalived.conf && bash install.sh"
ssh root@${MASTER3} "cd /tmp/keepalived/ && cp keepalived3.conf /etc/keepalived/keepalived.conf && bash install.sh"
exit 1
cd scripts cd scripts
./init.sh ./init.sh
sed -e "s/^apiserver=.*/apiserver=${VIP}/g" -i create_cluster.sh ./create_cluster.sh ${API_SERVER}
./create_cluster.sh
./nginx_ingress.sh ./nginx_ingress.sh

View File

@ -10,10 +10,11 @@ vrrp_script check {
} }
vrrp_instance VI_1 { # 实例名 vrrp_instance VI_1 { # 实例名
state MASTER # 3个实例1个配置MASTER另外2个配置BACKUP state BACKUP # 3个实例1个配置MASTER另外2个配置BACKUP, 非抢占式配置BACKUP
interface ens192 interface __NETWORK_NIC__
virtual_router_id 251 # ID主备需一致 virtual_router_id 251 # ID主备需一致
priority 100 # 默认权重3个节点保持不一致并且MASTER最大priority之间的差值要小于weight priority 100 # 默认权重3个节点保持不一致并且MASTER最大priority之间的差值要小于weight
nopreempt # 非抢占式
authentication { authentication {
auth_type PASS # 主备验证信息,需一致 auth_type PASS # 主备验证信息,需一致
@ -28,7 +29,7 @@ vrrp_instance VI_1 { # 实例名
__MASTER3__ __MASTER3__
} }
virtual_ipaddress { virtual_ipaddress {
__VIP__ dev ens192 __VIP__ dev __NETWORK_NIC__
} }
} }

View File

@ -1,22 +1,23 @@
global_defs { global_defs {
script_user root # 脚本执行者 script_user root
enable_script_security # 标记脚本安全 enable_script_security
} }
vrrp_script check { vrrp_script check {
script "killall -0 kube-apiserver" # 脚本路径 script "killall -0 kube-apiserver"
interval 2 # 脚本执行间隔单位s interval 2
weight -20 # -254-254之间检测失败权重减少 weight -20
} }
vrrp_instance VI_1 { # 实例名 vrrp_instance VI_1 {
state MASTER # 3个实例1个配置MASTER另外2个配置BACKUP state BACKUP
interface ens192 interface __NETWORK_NIC__
virtual_router_id 251 # ID主备需一致 virtual_router_id 251
priority 99 priority 99
nopreempt
authentication { authentication {
auth_type PASS # 主备验证信息,需一致 auth_type PASS
auth_pass 123456 auth_pass 123456
} }
track_script { track_script {
@ -28,7 +29,7 @@ vrrp_instance VI_1 { # 实例名
__MASTER3__ __MASTER3__
} }
virtual_ipaddress { virtual_ipaddress {
__VIP__ dev ens192 __VIP__ dev __NETWORK_NIC__
} }
} }

View File

@ -1,22 +1,23 @@
global_defs { global_defs {
script_user root # 脚本执行者 script_user root
enable_script_security # 标记脚本安全 enable_script_security
} }
vrrp_script check { vrrp_script check {
script "killall -0 kube-apiserver" # 脚本路径 script "killall -0 kube-apiserver"
interval 2 # 脚本执行间隔单位s interval 2
weight -20 # -254-254之间检测失败权重减少 weight -20
} }
vrrp_instance VI_1 { # 实例名 vrrp_instance VI_1 {
state MASTER # 3个实例1个配置MASTER另外2个配置BACKUP state BACKUP
interface ens192 interface __NETWORK_NIC__
virtual_router_id 251 # ID主备需一致 virtual_router_id 251
priority 98 priority 98
nopreempt
authentication { authentication {
auth_type PASS # 主备验证信息,需一致 auth_type PASS
auth_pass 123456 auth_pass 123456
} }
track_script { track_script {
@ -28,7 +29,7 @@ vrrp_instance VI_1 { # 实例名
__MASTER2__ __MASTER2__
} }
virtual_ipaddress { virtual_ipaddress {
__VIP__ dev ens192 __VIP__ dev __NETWORK_NIC__
} }
} }