偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Nginx主主負載均衡架構(gòu)

原創(chuàng)
網(wǎng)絡(luò) 網(wǎng)絡(luò)優(yōu)化 網(wǎng)絡(luò)運維
在和一些朋友交流Nginx+Keepalived技術(shù)時,我雖然已成功多次實施Nginx+Keepaived項目方案,但這些都是用的單主Nginx在工作,從Nginx長期只是處于備份狀態(tài),所以我們想將二臺Nginx負載均衡器都處于工作狀態(tài),其實用Nginx+Keepalived也很容易實現(xiàn)。

【51CTO.com 獨家特稿】在和一些朋友交流Nginx+Keepalived技術(shù)時,我雖然已成功多次實施Nginx+Keepaived項目方案,但這些都是用的單主Nginx在工作,從Nginx長期只是處于備份狀態(tài),所以我們想將二臺Nginx負載均衡器都處于工作狀態(tài),其實用Nginx+Keepalived也很容易實現(xiàn)。

此方法適用場景:適合中小型網(wǎng)站應(yīng)用場景。

一般為了維護方便,企業(yè)網(wǎng)站的服務(wù)器都在自己的內(nèi)部機房里,只開放了Keepalived的VIP地址的兩個端口80、443,通過Juniper SSG550防火墻映射出去,外網(wǎng)DNS對應(yīng)映射后的公網(wǎng)IP。此架構(gòu)的防火墻及網(wǎng)絡(luò)安全說明如下:

此系統(tǒng)架構(gòu)僅映射內(nèi)網(wǎng)VIP的80及443端口于外網(wǎng)的Juniper SSG550防火墻下,其他端口均關(guān)閉,內(nèi)網(wǎng)所有機器均關(guān)閉iptables防火墻;外網(wǎng)DNS指向即通過Juniper SSG550映射出來的外網(wǎng)地址。

Nginx負載均衡作服務(wù)器遇到的故障一般有:服務(wù)器網(wǎng)線松動等網(wǎng)絡(luò)故障;服務(wù)器硬件故障發(fā)生損壞現(xiàn)象而crash;

Nginx服務(wù)進程死掉(這種情況理論上會遇到,但事實上生產(chǎn)環(huán)境下的Linux服務(wù)器沒有出現(xiàn)過這種情況,足以證明了Nginx作為負載均衡器/反向代理服務(wù)器的穩(wěn)定性,我們可以通過技術(shù)手段來解決這一問題)。

測試實驗環(huán)境:

主Nginx之一:192.168.1.5

主Nginx之二:192.168.1.6

Web服務(wù)器一:192.168.1.17

Web服務(wù)器二:192.168.1.18

VIP地址一:192.168.1.8

VIP 地址二:192.168.1.9

一、 Nginx和Keepalived的安裝比較簡單,我這里就不重復(fù)了,大家可以參考我的專題系列的文章,如下地址http://network.51cto.com/art/201007/209823.htm,我這里附上Nginx.conf配置文件,如下所示:

  1. user www www;  
  2.     worker_processes 8;  
  3.     pid /usr/local/nginx/logs/nginx.pid;  
  4.     worker_rlimit_nofile 51200;  
  5.     events  
  6.     {  
  7.     use epoll;  
  8.     worker_connections 51200;  
  9.     }  
  10.     http{  
  11.     include       mime.types;  
  12.     default_type application/octet-stream;  
  13.     server_names_hash_bucket_size 128;  
  14.     client_header_buffer_size 32k;  
  15.     large_client_header_buffers 4 32k;  
  16.     client_max_body_size 8m;  
  17.     sendfile on;  
  18.     tcp_nopush     on;  
  19.     keepalive_timeout 60;  
  20.     tcp_nodelay on;  
  21.     fastcgi_connect_timeout 300;  
  22.     fastcgi_send_timeout 300;  
  23.     fastcgi_read_timeout 300;  
  24.     fastcgi_buffer_size 64k;  
  25.     fastcgi_buffers 4 64k;  
  26.     fastcgi_busy_buffers_size 128k;  
  27.     fastcgi_temp_file_write_size 128k;  
  28.     gzip on;  
  29.     gzip_min_length 1k;  
  30.     gzip_buffers     4 16k;  
  31.     gzip_http_version 1.0;  
  32.     gzip_comp_level 2;  
  33.     gzip_types       text/plain application/x-javascript text/css application/xml;  
  34.     gzip_vary on;  
  35.    
  36.     upstream backend  
  37.     {  
  38.     ip_hash;  
  39. server 192.168.1.17:80;  
  40.     server 192.168.1.18:80;  
  41.     }  
  42.     server {  
  43.     listen 80;  
  44.     server_name www.1paituan.com;  
  45.     location / {  
  46.     root /var/www/html ;  
  47.     index index.php index.htm index.html;  
  48.     proxy_redirect off;  
  49.     proxy_set_header Host $host;  
  50.     proxy_set_header X-Real-IP $remote_addr;  
  51.     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
  52.     proxy_pass http://backend;  
  53.     }  
  54.       
  55.     location /nginx {  
  56.     access_log off;  
  57.     auth_basic "NginxStatus";  
  58.     #auth_basic_user_file /usr/local/nginx/htpasswd;  
  59.     }  
  60.       
  61.     log_format access '$remote_addr - $remote_user [$time_local] "$request" '  
  62.     '$status $body_bytes_sent "$http_referer" '  
  63.     '"$http_user_agent" $http_x_forwarded_for';  
  64.     access_log /data/logs/access.log access;  
  65.     }  
  66. }  
  67.  

#p#

二、 配置Keepalived文件。

我這里簡單說下原理,其實也就是通過Keepalived生成二個實例,二臺Nginx互為備份,即***臺是第二臺機器的備機,而第二臺機器也是***臺的備機,而生成的二個VIP地址分別對應(yīng)我們網(wǎng)站http://www.1paituan.com,這樣大家在公網(wǎng)上可以通過DNS輪詢來訪問得到我們的網(wǎng)站,任何一臺Nginx機器如果發(fā)生硬件損壞,Keepalived會自動將它的VIP地址切換到另一臺機器,不影響客戶端的訪問,這個跟我們以前的LVS+Keepalived多實例的原理是一樣的,相信大家也能明白。

主Nginx機器之一的Keepalived.conf配置文件如下:

  1.  
  2. ! Configuration File for keepalived  
  3. global_defs {  
  4.    notification_email {  
  5.    yuhongchun027@163.com  
  6.         }  
  7.    notification_email_from keepalived@chtopnet.com  
  8.    smtp_server 127.0.0.1  
  9.    smtp_connect_timeout 30  
  10.    router_id LVS_DEVEL  
  11. }  
  12.  
  13. vrrp_instance VI_1 {  
  14.     state MASTER  
  15.     interface eth0  
  16.     virtual_router_id 51  
  17.     priority 100  
  18.     advert_int 1  
  19.     authentication {  
  20.         auth_type PASS  
  21.         auth_pass 1paituan.com  
  22.     }  
  23.     virtual_ipaddress {  
  24.         192.168.1.8  
  25.     }  
  26. }  
  27.  
  28.  
  29. vrrp_instance VI_2 {  
  30.     state BACKUP  
  31.     interface eth0  
  32.     virtual_router_id 52  
  33.     priority 99  
  34.     advert_int 1  
  35.     authentication {  
  36.         auth_type PASS  
  37.         auth_pass 1paituan.com  
  38.     }  
  39.     virtual_ipaddress {  
  40.         192.168.1.9  
  41.     }  
  42. }  
  43.  

主Nginx之二的keepalivd.conf配置文件如下:

  1. ! Configuration File for keepalived  
  2. global_defs {  
  3.    notification_email {  
  4.    yuhongchun027@163.com  
  5.         }  
  6.    notification_email_from keepalived@chtopnet.com  
  7.    smtp_server 127.0.0.1  
  8.    smtp_connect_timeout 30  
  9.    router_id LVS_DEVEL  
  10. }  
  11.  
  12. vrrp_instance VI_1 {  
  13.     state BACKUP   
  14.     interface eth0  
  15.     virtual_router_id 51  
  16.     priority 99  
  17.     advert_int 1  
  18.     authentication {  
  19.         auth_type PASS  
  20.         auth_pass 1paituan  
  21.     }  
  22.     virtual_ipaddress {  
  23.         192.168.1.8                     
  24.     }  
  25. }  
  26.  
  27.  
  28. vrrp_instance VI_2 {  
  29.     state MASTER   
  30.     interface eth0  
  31.     virtual_router_id 52  
  32.     priority 100  
  33.     advert_int 1  
  34.     authentication {  
  35.         auth_type PASS  
  36.         auth_pass 1paituan  
  37.     }  
  38.     virtual_ipaddress {  
  39.         192.168.1.9                     
  40.     }  
  41. }  
  42.  

#p#

三、大家都知道Keepalived是實現(xiàn)不了程序級別的高可用的,所以我們要寫SHELL腳本,來實現(xiàn)Nginx的高可用,腳本/root/nginxpid.sh內(nèi)容如下:

  1. #!/bin/bash  
  2. while  :  
  3. do  
  4.  nginxpid=`ps -C nginx --no-header | wc -l`  
  5.  if [ $nginxpid -eq 0 ];then  
  6.   /usr/local/nginx/sbin/nginx  
  7.   sleep 5
  8. nginxpid=`ps -C nginx --no-header | wc -l`
  9.    if [ $nginxpid -eq 0 ];then  
  10.    /etc/init.d/keepalived stop  
  11.    fi  
  12.  fi  
  13.  sleep 5  
  14. done  
  15.  

我們分別在二臺主Nginx上執(zhí)行,命令如下所示:

  1. nohup sh /root/nginxpid.sh &   

此腳本我是直接從生產(chǎn)服務(wù)器上下載的,大家不要懷疑它會引起死循環(huán)和有效性的問題,我稍為解釋一下,這是一個無限循環(huán)的腳本,放在主Nginx機器上(因為目前主要是由它提供服務(wù)),每隔5秒執(zhí)行一次,用ps -C 命令來收集nginx的PID值到底是否為0,如果是0的話(即Nginx進程死掉了),嘗試啟動nginx進程;如果繼續(xù)為0,即nginx啟動失改, 則關(guān)閉本機的Keeplaived進程,VIP地址則會由備機接管,當然了,整個網(wǎng)站就會由備機的Nginx來提供服務(wù)了,這樣保證Nginx進程的高可 用。

#p#

四、正常啟動二臺主Nginx的Nginx和Keealived程序后,二臺機器的正常IP顯示應(yīng)該如下所示:

這臺是IP為192.168.1.5的機器的ip addr命令顯示結(jié)果:

  1. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue   
  2. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00  
  3. inet 127.0.0.1/8 scope host lo  
  4. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000  
  5. link/ether 00:0c:29:99:fb:32 brd ff:ff:ff:ff:ff:ff  
  6. inet 192.168.1.5/24 brd 192.168.1.255 scope global eth0  
  7.   inet 192.168.1.8/32 scope global eth0  

這臺是IP為192.168.1.6的機器的ip addr命令顯示結(jié)果:

  1. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue   
  2. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00  
  3. inet 127.0.0.1/8 scope host lo  
  4. inet6 ::1/128 scope host   
  5. valid_lft forever preferred_lft forever  
  6. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000  
  7. link/ether 00:0c:29:7d:58:5e brd ff:ff:ff:ff:ff:ff  
  8. inet 192.168.1.6/24 brd 192.168.1.255 scope global eth0  
  9. inet 192.168.1.9/32 scope global eth0  
  10. inet6 fe80::20c:29ff:fe7d:585e/64 scope link   
  11. valid_lft forever preferred_lft forever  
  12. 3: sit0: <NOARP> mtu 1480 qdisc noop   
  13.   link/sit 0.0.0.0 brd 0.0.0.0 

五、測試過程如下:

一、我們要分別在二臺主Nginx上用killall殺掉Nginx進程,然后在客戶端分別訪問192.168.1.8和192.168.1.9這二個IP(模擬DNS輪詢)看能否正常訪問Web服務(wù)器。

二、嘗試重啟192.168.1.5的主Nginx負載均衡器,測試過程如上;

三、嘗試重啟192.168.1.6的主Nginx負載均衡器,測試過程如下;

四、嘗試分別關(guān)閉192.168.1.5和192.168.1.6的機器,測試過程如上,看影響網(wǎng)站的正常訪問不?

六、目前投入生產(chǎn)要解決的問題:

一、Cacti和Nagios等監(jiān)控服務(wù)要重新部署,因為現(xiàn)在客戶機是分別訪問二臺負載均衡器;

二、日志收集要重新部署,現(xiàn)在訪問日志是分布在二臺負載均衡器上;

三、要考慮google收錄的問題;

四、證書的問題,二臺機器都需要;

五、其它問題暫時沒有想到,待補充。

【51CTO.com獨家特稿,非經(jīng)授權(quán)謝絕轉(zhuǎn)載!合作媒體轉(zhuǎn)載請注明原文出處及出處!】

責任編輯:佟健 來源: 51CTO.com
相關(guān)推薦

2015-04-13 09:44:14

Nginxkeepalived負載均衡

2010-05-04 13:23:55

Tomcat負載均衡

2010-05-04 15:41:44

交換負載均衡

2012-07-31 09:25:42

nginx負載均衡反向代理

2013-04-22 11:29:14

Nginx

2023-02-20 08:27:17

2011-12-02 22:51:46

Nginx負載均衡

2010-05-06 10:01:26

nginx負載均衡

2013-10-15 13:24:00

負載均衡架構(gòu)

2010-05-07 12:23:23

nginx負載均衡

2011-01-07 11:14:17

Nginx負載均衡負載均衡

2014-07-28 11:37:49

NginxTomcat

2024-11-11 09:51:46

Nginx部署負載

2019-09-18 10:39:08

負載均衡反向代理TCP

2017-11-09 10:42:11

Nginx負載均衡策略

2010-03-25 18:52:15

Nginx負載均衡

2010-05-07 12:27:53

nginx負載均衡

2017-12-18 12:04:02

Nginx代理均衡

2019-11-04 15:35:53

Nginx反向代理負載均衡

2012-11-06 16:51:29

nginx負載均衡
點贊
收藏

51CTO技術(shù)棧公眾號