keepalived+nginx+apache雙活搭建(雙網卡模式)
阿新 • • 發佈:2018-06-15
emc RKE RM etc lin admin 腳本 include status 之前寫過一篇文章《keepalived+nginx+apache主備及雙活搭建測試》,該測試環境只有一張網卡,雙活的ip都在該網卡上。
本文背景:自動化運維平臺的前置機部署在雲平臺,服務器有兩張網卡,分別對應帶外ip和業務ip;雲平臺的被管服務器訪問帶外虛ip,非雲平臺的物理服務器訪問業務的虛ip。
架構圖:
配置:
主機 | ip | 操作系統 | 軟件 | vip |
nginx01 | 172.27.9.91 172.27.18.127 | Centos7.3.1611 | nginx 端口82 keepalived | 172.27.9.200 |
nginx02 | 172.27.9.92 172.27.18.128 | Centos7.3.1611 | nginx 端口82 keepalived | 172.27.18.120 |
web01 | 172.27.9.125 | Centos7.3.1611 | apache 端口1180 | / |
web02 | 172.27.9.126 | Centos7.3.1611 | apache 端口1180 | / |
vmware版本:12.5.2 build-4638234
1.vmware新增網卡
打開‘虛擬網絡編輯器’:
‘VMnet0’和‘VMnet2’分別對應pc機物理網卡和無線網卡:
新增網卡及配置:
2.keepalived配置
nginx01上keepalived配置:
[root@nginx01 keepalived]# more /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { notification_email { [email protected] [email protected] [email protected] } notification_email_from [email protected] #smtp_server 192.168.200.1 #smtp_connect_timeout 30 router_id proxy1 } vrrp_script chk_nginx { script "/etc/keepalived/check_nginx.sh" interval 2 weight 20 fall 1 rise 10 } vrrp_instance VI_1 { state MASTER interface ens33 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 172.27.9.200 } track_script { chk_nginx } } vrrp_instance VI_2 { state BACKUP interface ens37 virtual_router_id 52 priority 90 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 172.27.18.120 } track_script { chk_nginx } }
nginx02上keepalived配置:
[root@nginx02 keepalived]# more /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { notification_email { [email protected] [email protected] [email protected] } notification_email_from [email protected] #smtp_server 192.168.200.1 #smtp_connect_timeout 30 router_id proxy2 } vrrp_script chk_nginx { script "/etc/keepalived/check_nginx.sh" interval 2 weight 20 fall 2 rise 1 } vrrp_instance VI_1 { state BACKUP interface ens33 virtual_router_id 51 priority 90 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 172.27.9.200 } track_script { chk_nginx } } vrrp_instance VI_2 { state MASTER interface ens37 virtual_router_id 52 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 172.27.18.120 } track_script { chk_nginx } }
check_nginx.sh腳本配置同之前文章
3.nginx配置
兩臺nginx服務器配置相同如下:
[root@nginx02 keepalived]# more /usr/local/nginx/conf/nginx.conf #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include 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 logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; upstream webser{ server 172.27.9.125:1180; server 172.27.9.126:1180; server 172.27.18.127:1180; server 172.27.18.128:1180; } server { listen 82; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://webser; #root html; #index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
4.啟動服務
啟動兩臺服務器nginx和keepalived服務:
[root@nginx01 ~]# nginx [root@nginx01 ~]# service keepalived start Redirecting to /bin/systemctl start keepalived.service
5.查看vip
6.頁面訪問
vip1:http://172.27.9.200:82/
vip2:http://172.27.18.120:82/
刷新web,發現vip1和vip2分別以輪詢方式訪問web服務器
7.高可用測試
同之前文章,不再贅述。
測試完成,雲平臺生產環境也可以按本次測試實施。
keepalived+nginx+apache雙活搭建(雙網卡模式)