日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

nginx+keepalived 高可用

發布時間:2025/5/22 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nginx+keepalived 高可用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

nginx 安裝


rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install nginx

#設置開機啟動
systemctl enable nginx.service

#啟動服務
systemctl start nginx.service


keepalived 安裝
#安裝keepavlived
yum -y install keepalived

#設置開機啟動
systemctl enable nginx.service

#啟動服務
service keepalived start


keepavlived mater設置

global_defs {
notification_email {br/>localhost@163.com
}
notification_email_from Keepalived@localhost
smtp_server 163@smtp.com
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_nginx {
script "/etc/keepalived/chk_nginx.sh"
interval 3
weight 2
}

vrrp_instance VI_1 {
state MASTER
interface eth0
lvs_sync_daemon_interface eth0
virtual_router_id 151
priority 100
advert_int 5
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
#VIP
virtual_ipaddress {
172.16.101.193
}
track_script {
chk_nginx
}
}


keepavlived backup 設置
cat keepalived.conf

global_defs {
notification_email {br/>localhost@163.com
}
notification_email_from Keepalived@localhost
smtp_server 163@smtp.com
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_nginx {
script "/etc/keepalived/chk_nginx.sh"
interval 3 #這個必須要大于腳本里sleep 2 要不腳本不生效。
weight 2
}

vrrp_instance VI_1 {
state BACKUP
interface eth0
lvs_sync_daemon_interface eth0
virtual_router_id 151
priority 90
advert_int 5
authentication {
auth_type PASS
auth_pass 1111
}
#VIP
virtual_ipaddress {
172.16.101.193
}
track_script {
chk_nginx
}
}


腳本:
cat /etc/keepalived/chk_nginx.sh

#!/bin/sh
A=ps -C nginx --no-header |wc -l
if [ $A -eq 0 ];then
systemctl start nginx.service
sleep 2
if [ ps -C nginx --no-header |wc -l -eq 0 ];then
systemctl stop keepalived
fi
fi

轉載于:https://blog.51cto.com/guoshaoliang789/2163779

總結

以上是生活随笔為你收集整理的nginx+keepalived 高可用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。