From 6b1d89177525bd3c64a9ae8ea4c5f535eb0e0c1c Mon Sep 17 00:00:00 2001 From: zhanglikun Date: Tue, 12 Sep 2023 17:20:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 4 ++++ 0-config.sh | 19 +++++++++---------- 1-init.sh | 11 +++++++++-- 2-create_k8s.sh | 2 +- keepalived/keepalived1.conf | 8 ++++---- keepalived/keepalived2.conf | 8 ++++---- keepalived/keepalived3.conf | 8 ++++---- 7 files changed, 35 insertions(+), 25 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..ddd0a2f --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +MASTER1="10.0.0.112" +MASTER2="10.0.0.122" +MASTER3="10.0.0.132" +VIP="10.0.0.32" \ No newline at end of file diff --git a/0-config.sh b/0-config.sh index e096411..fe8eef6 100755 --- a/0-config.sh +++ b/0-config.sh @@ -1,13 +1,12 @@ #!/bin/bash +set -euo pipefail -master1="10.0.0.112" -master2="10.0.0.122" -master3="10.0.0.132" -vip="10.0.0.32" +source .env -sed -e "s/10.0.0.11/${master1}/g" \ - -e "s/10.0.0.12/${master2}/g" \ - -e "s/10.0.0.13/${master3}/g" \ - -e "s/10.0.0.3/${vip}/g" \ - -i keepalived/*.conf \ - -i 2-create_k8s.sh \ No newline at end of file +sed -e "s/__MASTER1__/${MASTER1}/g" \ + -e "s/__MASTER2__/${MASTER2}/g" \ + -e "s/__MASTER3__/${MASTER3}/g" \ + -e "s/__VIP__/${VIP}/g" \ + -i keepalived/*.conf + +sed -e "s/__API_SERVER__/${VIP}/g" -i 2-create_k8s.sh \ No newline at end of file diff --git a/1-init.sh b/1-init.sh index bcb22ee..bdd12fe 100755 --- a/1-init.sh +++ b/1-init.sh @@ -1,4 +1,11 @@ -sudo systemctl disable --now firewalld +#!/bin/bash + +if [ $(id -u) != "0" ]; then + echo "Error: You must be root to run this script" + exit 1 +fi + +systemctl disable --now firewalld setenforce 0 sed -i "s/^SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config @@ -15,7 +22,7 @@ EOF sudo sysctl --system # 关闭swap -sudo swapoff -a +swapoff -a sed -i 's/.*swap.*/#&/' /etc/fstab cd ./docker && bash ./install.sh && cd .. diff --git a/2-create_k8s.sh b/2-create_k8s.sh index 81fe583..fe17eb2 100755 --- a/2-create_k8s.sh +++ b/2-create_k8s.sh @@ -1,6 +1,6 @@ #!/bin/bash -apiserver="10.0.0.3" +apiserver="__API_SERVER__" sudo kubeadm init \ diff --git a/keepalived/keepalived1.conf b/keepalived/keepalived1.conf index 2f7658f..328001f 100644 --- a/keepalived/keepalived1.conf +++ b/keepalived/keepalived1.conf @@ -22,13 +22,13 @@ vrrp_instance VI_1 { # 实例名 track_script { check } - unicast_src_ip 10.0.0.11 + unicast_src_ip __MASTER1__ unicast_peer { - 10.0.0.12 - 10.0.0.13 + __MASTER2__ + __MASTER3__ } virtual_ipaddress { - 10.0.0.3 dev ens192 + __VIP__ dev ens192 } } diff --git a/keepalived/keepalived2.conf b/keepalived/keepalived2.conf index 2036720..3813e04 100644 --- a/keepalived/keepalived2.conf +++ b/keepalived/keepalived2.conf @@ -22,13 +22,13 @@ vrrp_instance VI_1 { # 实例名 track_script { check } - unicast_src_ip 10.0.0.12 + unicast_src_ip __MASTER2__ unicast_peer { - 10.0.0.11 - 10.0.0.13 + __MASTER1__ + __MASTER3__ } virtual_ipaddress { - 10.0.0.3 dev ens192 + __VIP__ dev ens192 } } diff --git a/keepalived/keepalived3.conf b/keepalived/keepalived3.conf index e2fb008..29d8264 100644 --- a/keepalived/keepalived3.conf +++ b/keepalived/keepalived3.conf @@ -22,13 +22,13 @@ vrrp_instance VI_1 { # 实例名 track_script { check } - unicast_src_ip 10.0.0.13 + unicast_src_ip __MASTER3__ unicast_peer { - 10.0.0.11 - 10.0.0.12 + __MASTER1__ + __MASTER2__ } virtual_ipaddress { - 10.0.0.3 dev ens192 + __VIP__ dev ens192 } }