Nginx 反向代理+高可用
生活随笔
收集整理的這篇文章主要介紹了
Nginx 反向代理+高可用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
反向代理主機IP:10.0.0.20
WEB01主機IP : 10.0.0.22
WEB02主機IP : 10.0.0.23
WEB02主機IP : 10.0.0.23
反向代理主機配置:10.0.0.20
[root@node1 html]# vim /etc/nginx/conf.d/web.conf server {listen 80;server_name www.wanglan.com;location / {proxy_pass http://10.0.0.30; #keepalived虛擬IP proxy_set_header HOST $HOST;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Real-IP $remote_addr;proxy_set_header Request-Url $request_uri;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}}web01主機配置 Keepalived.conf
[root@node1 ~]# vim /etc/keepalived/keepalived.conf ! Configuration File for keepalivedglobal_defs {notification_email {acassen@firewall.locfailover@firewall.locsysadmin@firewall.loc}notification_email_from Alexandre.Cassen@firewall.locsmtp_server 192.168.200.1smtp_connect_timeout 30router_id WEB #集群名稱,相同集群名稱必須相同 }vrrp_instance VI_1 {state MASTER #主從設置,這里設置為主interface eth0virtual_router_id 51priority 150 #定義訪問優先級,數值越大優先級越高advert_int 1authentication {auth_type PASSauth_pass 1111}virtual_ipaddress {10.0.0.30 #置虛擬IP,這就是反向代理服務器所代理的IP} }?
web0主機配置keepalived.conf 文件
[root@node4 ~]# vim /etc/keepalived/keepalived.conf ! Configuration File for keepalivedglobal_defs {notification_email {acassen@firewall.locfailover@firewall.locsysadmin@firewall.loc}notification_email_from Alexandre.Cassen@firewall.locsmtp_server 192.168.200.1smtp_connect_timeout 30router_id WEB #集群名稱,必須和web01設置相同 }vrrp_instance VI_1 {state BACKUP #主從設置,這里設置為從interface eth0virtual_router_id 51priority 100 #定義訪問優先級,從要比主的數值小advert_int 1authentication {auth_type PASSauth_pass 1111}virtual_ipaddress {10.0.0.30 #設置虛擬IP,必須相同} }重啟服務查看web01的網卡上是否有 10.0.0.30 IP
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:e6:36:7b brd ff:ff:ff:ff:ff:ffinet 10.0.0.22/24 brd 10.0.0.255 scope global eth0valid_lft forever preferred_lft foreverinet 10.0.0.30/32 scope global eth0而此時web02的網卡上是沒有10.0.0.30 IP
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:15:ba:84 brd ff:ff:ff:ff:ff:ffinet 10.0.0.23/24 brd 10.0.0.255 scope global eth0valid_lft forever preferred_lft forever可以關閉web01的keepalived 服務,查看IP是否轉移到了web02上
web01上已經沒有了10.0.0.30
[root@node1 ~]# systemctl stop keepalived2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:e6:36:7b brd ff:ff:ff:ff:ff:ffinet 10.0.0.22/24 brd 10.0.0.255 scope global eth0valid_lft forever preferred_lft forever查看web02
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:15:ba:84 brd ff:ff:ff:ff:ff:ffinet 10.0.0.23/24 brd 10.0.0.255 scope global eth0valid_lft forever preferred_lft foreverinet 10.0.0.30/32 scope global eth0valid_lft forever preferred_lft forever此時10.0.0.30 已經轉移到了 web02上
?
轉載于:https://www.cnblogs.com/wanglan/p/7494345.html
總結
以上是生活随笔為你收集整理的Nginx 反向代理+高可用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 二叉树02
- 下一篇: Nginx 的线程池与性能剖析【转载】