博客详情

keepalived+nginx配置高可用负载均衡代理 (原创)

作者: 朝如青丝暮成雪
发布时间:2022-02-08 11:51:59  文章分类:随手笔记   阅读(845)  评论(0)

参考:

https://www.cnblogs.com/yanjieli/p/10682064.html
https://www.cnblogs.com/rexcheny/p/10778567.html


keepalived+nginx配置高可用负载均衡代理

1、安装keepalived 服务
yum install keepalived -y 
cd /etc/keepalived/
cp -rf keepalived.conf keepalived.conf.bak


2、配置server01主机

server01上 :

keepalived.conf 配置如下  (vi /etc/keepalived/keepalived.conf)
global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30

   router_id sev01

}

vrrp_instance VI_1 {
    state MASTER   #主节点
    interface ens192  #网卡名称
    virtual_router_id 51  
    priority 100  #优先级
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
      192.168.0.110/24  dev ens192 label ens192:0  #虚拟ip地址(VIP)
          
    }
   preempt delay 60
}
 

nginx.conf配置如下
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
 
   upstream backend_ccb_wlpt {
      server 192.168.0.126:2323 weight=1 ;
      server 192.168.0.127:2323 weight=1 ;
    }

    server {
       listen  90;
       server_name  localhost;
       location / {
        proxy_pass http://backend_ccb_wlpt;
        proxy_set_header Host $host:$proxy_port;
        proxy_set_header X-Forwarded-For $remote_addr;
      }
    }
}


3、配置server02主机

erver02上: 

keepalived.conf 配置如下  (vi /etc/keepalived/keepalived.conf)

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id sev02
  
}

vrrp_instance VI_1 {
    state BACKUP  #备份节点
    interface ens192   #网卡名称
    virtual_router_id 51  
    priority 90  #优先级
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }

    virtual_ipaddress {
       192.168.0.110/24  dev ens192 label ens192:0     #虚拟ip地址(VIP)
    }

   preempt delay 60
}

nginx.conf配置如下


http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
 
   upstream backend_ccb_wlpt {
      server 192.168.0.126:2323 weight=1 ;
      server 192.168.0.127:2323 weight=1 ;
    }

    server {
       listen  90;
       server_name  localhost;
       location / {
        proxy_pass http://backend_ccb_wlpt;
        proxy_set_header Host $host:$proxy_port;
        proxy_set_header X-Forwarded-For $remote_addr;
      }
    }

}


3、最后启动keepalived和nginx  (server01、server02上)

nginx -s reload 

sysyetmctl enable keepalived 
sysyetmctl start keepalived 

cat /var/log/messages 
ifconfig  #查看虚拟网卡(VIP网卡)


关键字:  keepalived  nginx
评论信息
暂无评论
发表评论

亲,您还没有登陆,暂不能评论哦! 去 登陆 | 注册

博主信息
   
数据加载中,请稍候...
文章分类
   
数据加载中,请稍候...
阅读排行
 
数据加载中,请稍候...
评论排行
 
数据加载中,请稍候...

Copyright © 叮叮声的奶酪 版权所有
备案号:鄂ICP备17018671号-1

鄂公网安备 42011102000739号