Nginx+KeepAlive方案


機器規划和架構圖

 

 

 

 

部署nginx負載均衡

 

 

配置nginx負載
  安裝nginx服務
[root@linux-node4 ~]# yum -y install nginx
配置反向代理
[root@lb-master ~]# vim /etc/nginx/nginx.conf 

stream {

​        log_format main '$remote_addr $upstream_addr - [$time_local] $status $upstream_bytes_sent'; 

​        access_log /var/log/nginx/django-access.log main; 

​        upstream django-apiserver { 

​                        server 192.168.56.62:80; 

​                        server 192.168.56.63:80; 

​                } 

​        server { 

​                    listen 88; 

​                    proxy_pass django-apiserver; 

​        } 

}
完整配置如下
看一下即可,都是nginx默認配置
http {

​        include         /etc/nginx/mime.types; 

​        default_type     application/octet-stream; 

​        log_format     main     '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"'; 

access_log     /var/log/nginx/access.log main; 

sendfile         on; 

\#tcp_nopush         on; 

keepalive_timeout     65; 

\#gzip     on; 

include     /etc/nginx/conf.d/*.conf; 


}
測試反向代理可用性

 

 

 

 

 

[root@lb-master ~]# vim /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 127.0.0.1 

​    smtp_connect_timeout 30 

​    router_id NGINX_MASTER 

}

\# 健康監測nginx 

vrrp_script check_nginx { 

​        script "/etc/keepalived/check_nginx.sh" # 設置檢查nginx是否存活的腳本位置

}

\# keepalive熱備組配置 

vrrp_instance VI_1 { 

​        state MASTER # 配置當前keepalive為master角色 

​        interface eth0 # 網卡名字,必須和實際網卡名稱一致,默認是ens33 

​        virtual_router_id 51 # VRRP 路由 ID實例,每個實例是唯一的 

​        priority 100 # 優先級,備服務器設置 90 

​        advert_int 1 # 指定VRRP 心跳包通告間隔時間,默認1秒 

​        authentication { 

​                auth_type PASS 

​                auth_pass 1111 # 設置keepalive的master和slave之間簡單的秘鑰認證 

​    }

​    virtual_ipaddress { 

​        192.168.56.60/24 # 設置keepalive虛擬IP地址 

​    }

​    track_script { 

​                check_nginx 

​    } 

}

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM