a伺服器ip :192.168.157.128 (主)
b伺服器ip :192.168.157.136
c伺服器ip :192.168.157.137
vim /etc/hosts
192.168.157.128 hadoop1
192.168.157.136 hadoop2
192.168.157.137 hadoop3
a伺服器nginx.conf設定
開啟nginx.conf,檔案位置在nginx安裝目錄的conf目錄下。
在http段加入以下**
upstream a.com
server
}儲存重啟 nginx -s reload
分別配置b、c伺服器nginx.conf設定
開啟nginx.confi,在http段加入以下**
server
分別重啟b、c伺服器 nginx -s reload
區分介面:
192.168.157.128 vim /usr/local/nginx/html/index.html 內容為hadoop1
192.168.157.136 vim /usr/local/nginx/html/index.html 內容為hadoop2
192.168.157.137 vim /usr/local/nginx/html/index.html 內容為hadoop3
nginx -s reload
訪問http://hadoop1:80 重新整理介面 可以看到介面內容為hadoop2或者hadoop3
結論:開啟瀏覽器訪問http://hadoop1:80 結果,重新整理會發現所有的請求均分別被主伺服器(192.168.157.128)分配到b伺服器(192.168.157.136)與c伺服器(192.168.157.137)上,實現了負載均衡效果。
假如其中一台伺服器死機會怎樣?
當某台伺服器宕機了,是否會影響訪問呢?
我們先來看看例項,根據以上例子,假設c伺服器192.168.157.137這台機子宕機了(由於無法模擬宕機,所以我就把c伺服器關機)然後再來訪問看看。
訪問結果:hadoop2
我們發現,雖然c伺服器(192.168.157.137)宕機了,但不影響**訪問。這樣,就不會擔心在負載均衡模式下因為某台機子宕機而拖累整個站點了。
NGINX安裝及負載均衡
一 安裝 1 安裝nginx,必須保證系統安裝了gcc,gcc c 編譯工具,安裝命令 yum y install gcc,yum y install gcc c 2 安裝pcre庫 tar zxvf pcre 8.34.tar.gz 進入目錄pcre 8.34 分別執行.configure,mak...
nginx負載均衡配置及測試
the remote server ip is the nginx server ip is 2 啟動兩個tomcat,進行訪問測試 宿主機中的 http localhost 8080 test.jsp ubuntu14.04中的 http localhost 8080 test.jsp 3 在ng...
nginx安裝及負載均衡配置
nginx engine x 是乙個高效能的 http 和 反向 伺服器,也是乙個 imap pop3 smtp 伺服器。nginx 是由 igor sysoev 為俄羅斯訪問量第二的 rambler.ru 站點開發的,第乙個公開版本0.1.0發布於2004年10月4日。其將源 以類bsd許可證的形...