nginx+keepalived实现主备模式高可用


一、拓扑

二、keepalived配置
2.1 主配置
! Configuration File for keepalivedglobal_defs {
notification_email {acassen@firewall.loc
br/>acassen@firewall.loc
br/>sysadmin@firewall.loc
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id NGINX_V1
}vrrp_script chk_nginx {
script “/usr/local/keepalived/check_nginx.sh”
interval 2
weight 2
}vrrp_instance VI_1 {
state MASTER
interface ens37
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass wenlf@780419
}
track_script {
chk_nginx
}
virtual_ipaddress {
172.16.10.65 dev ens33
}
notify_master “/usr/local/keepalived/clean_arp.sh 172.16.10.65”
}
2.2 备配置
! Configuration File for keepalivedglobal_defs {
notification_email {acassen@firewall.loc
br/>acassen@firewall.loc
br/>sysadmin@firewall.loc
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id NGINX_V1
}vrrp_script chk_nginx {
script “/usr/local/keepalived/check_nginx.sh”
interval 2
weight 2
}vrrp_instance VI_1 {
state BACKUP
interface ens37
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass wenlf@780419
}
track_script {
chk_nginx
}
virtual_ipaddress {
172.16.10.65 dev ens33
}
notify_master “/usr/local/keepalived/clean_arp.sh 172.16.10.65”
2.3 监控脚本—————————————-clean_arp.sh————————————
#!/bin/sh
VIP=$1
GATEWAY=172.16.10.254
/sbin/arping -I ens33 -c 5 -s $VIP $GATEWAY &>/dev/null—————————————–check_nginx.sh——————————–
#!/bin/sh
if [ $(ps -C nginx –no-header | wc -l) -eq 0 ]; then
/etc/rc.d/init.d/nginx start
fi
sleep 2
if [ $(ps -C nginx –no-header | wc -l) -eq 0 ]; then
/etc/rc.d/init.d/keepalived stop
fi
三、nginx配置
3.1 nginx.conf
user www www;
worker_processes 1;#error_log logs/error.log;
#error_log logs/error.log notice;
error_log logs/error.log info;pid logs/nginx.pid;worker_rlimit_nofile 65535;events {
worker_connections 1024;
use epoll;}http {}
3.2 虚拟机
server
{
listen 80;
server_name 172.16.10.65;
#index index.html index.htm index.php;
location / {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_pass http://LoadBalance;
#proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
loc开发云主机域名ation /NginxStatus {
stub_status on;
access_log on;
auth_basic “NginxStatus”;
#auth_basic_user_file pwd;
}
}
3.3 负载均衡配置
upstream LoadBalance{
server 192.168.10.70:80 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.10.71:80 weight=1 max_fails=2 fail_timeout=30s;
ip_hash;}
四、验证

相关推荐: 想查看linux系统内存大小,怎么做

本篇文章和大家了解一下想查看linux系统内存大小,怎么做。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。首先打开系统终端命令行(免费学习视频教程分享:linux视频教程)输入free -h命令,在结果中找到total即可查看到系统总的内存情…

免责声明:本站发布的图片视频文字,以转载和分享为主,文章观点不代表本站立场,本站不承担相关法律责任;如果涉及侵权请联系邮箱:360163164@qq.com举报,并提供相关证据,经查实将立刻删除涉嫌侵权内容。

(0)
打赏 微信扫一扫 微信扫一扫
上一篇 04/02 15:34
下一篇 04/02 15:34