keepalived设定#
安装keepalived
yum install -y keepalived
配置keepalived
keepalived主节点--lb01上配置
! Configuration File for keepalived
global_defs {
router_id lb01_192.168.1.41
enable_script_security
script_user root
}
vrrp_script chk_nginx {
script "/etc/keepalived/check_nginx_process.sh"
interval 2
weight -20
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 50
priority 90
advert_int 1
mcast_src_ip 192.168.1.41
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
chk_nginx
}
virtual_ipaddress {
192.168.1.40
}
}
keepalived从节点--lb02上配置
! Configuration File for keepalived
global_defs {
router_id lb02_192.168.1.42
enable_script_security
script_user root
}
vrrp_script chk_nginx {
script "/etc/keepalived/check_nginx_process.sh"
interval 2
weight -20
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 50
priority 100
advert_int 1
mcast_src_ip 192.168.1.42
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
chk_nginx
}
virtual_ipaddress {
192.168.1.40
}
}
创建监听nginx的脚本
cat <<'EOF' | sudo tee /etc/keepalived/check_nginx_process.sh
err=0
for k in $(seq 1 3)
do
check_code=$(pgrep nginx)
if [[ $check_code == "" ]]; then
err=$(expr $err + 1)
sleep 1
continue
else
err=0
break
fi
done
if [[ $err != "0" ]]; then
echo "systemctl stop keepalived"
/usr/bin/systemctl stop keepalived
exit 1
else
exit 0
fi
EOF
chmod +x /etc/keepalived/check_nginx_process.sh
启动服务
systemctl enable keepalived --now
nginx设定#
安装nginx
yum install -y keepalived
配置nginx
cat >> /etc/nginx/nginx.conf <<EOF
stream {
upstream kube-apiserver {
server 192.168.1.51:6443 max_fails=3 fail_timeout=30s;
server 192.168.1.52:6443 max_fails=3 fail_timeout=30s;
server 192.168.1.53:6443 max_fails=3 fail_timeout=30s;
}
server {
listen 8443;
proxy_connect_timeout 2s;
proxy_timeout 900s;
proxy_pass kube-apiserver;
}
}
EOF
启动服务
systemctl enable nginx --now
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App