Nginx 負載均衡測試

2021-09-26 21:37:52 字數 2859 閱讀 1188

1.需要準備3臺伺服器,並安裝好nginx

10.0.0.3 nginx 負載均衡伺服器

10.0.0.8 後端業務伺服器1

10.0.0.9 後端業務伺服器2

2.檢視nginx原引數

[root@localhost ~]# /data/nginx/sbin/nginx -v

nginx version: nginx/1.16.1

built by gcc 4.8.5 20150623 (red hat 4.8.5-36) (gcc)

built with openssl 1.0.2k-fips 26 jan 2017

tls sni support enabled

configure arguments: --prefix=/data/nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module

3.安裝echo測試模組

[root@localhost ~]# tar xzf v0.61.tar.gz -c nginx-1.16.1 #解壓echo測試模組

[root@localhost nginx-1.16.1]# ./configure --prefix=/data/nginx --add-module=echo-nginx-module-0.61 #預編譯echo測試模組

[root@localhost nginx-1.16.1]# make #編譯(不需要編譯安裝)

[root@localhost nginx-1.16.1]# mv /data/nginx/sbin/nginx /data/nginx/sbin/nginx.old #重新命名原執行檔案

[root@localhost nginx-1.16.1]# cp objs/nginx /data/nginx/sbin/nginx #拷貝新nginx執行檔案至nginx目錄

[root@localhost nginx-1.16.1]# make upgrade

4.安裝echo測試模組完成

[root@localhost nginx-1.16.1]# /data/nginx/sbin/nginx -v

nginx version: nginx/1.16.1

built by gcc 4.8.5 20150623 (red hat 4.8.5-36) (gcc)

configure arguments: --prefix=/data/nginx --add-module=echo-nginx-module-0.61

5.啟動3臺伺服器的nginx並測試是否能正常ping通。

[root@localhost ~]# systemctl stop firewalld.service && /data/nginx/sbin/nginx   #關閉防火牆並啟動nginx

[root@localhost ~]# ping 10.0.0.8

ping 10.0.0.8 (10.0.0.8) 56(84) bytes of data.

64 bytes from 10.0.0.8: icmp_seq=1 ttl=64 time=0.748 ms

64 bytes from 10.0.0.8: icmp_seq=2 ttl=64 time=0.257 ms

64 bytes from 10.0.0.8: icmp_seq=3 ttl=64 time=0.246 ms #可正常連線

[root@localhost ~]# ping 10.0.0.9

ping 10.0.0.9 (10.0.0.9) 56(84) bytes of data.

64 bytes from 10.0.0.9: icmp_seq=1 ttl=64 time=0.924 ms

64 bytes from 10.0.0.9: icmp_seq=2 ttl=64 time=0.243 ms

64 bytes from 10.0.0.9: icmp_seq=3 ttl=64 time=0.267 ms #可正常連線

6.配置nginx.conf檔案

1️⃣10.0.0.3 nginx 負載均衡伺服器

upstream www

server

2️⃣10.0.0.8 後端業務伺服器1

server
3️⃣10.0.0.9 後端業務伺服器2

server
並重啟3臺伺服器的nginx服務

[root@localhost conf]# /data/nginx/sbin/nginx -s reload
7.測試10.0.0.3是否正常進行負責均衡

[root@localhost conf]# curl www.test.com

gdl1

[root@localhost conf]# curl www.test.com

gdl2

[root@localhost conf]# curl www.test.com

gdl1

[root@localhost conf]# curl www.test.com

gdl2

[root@localhost conf]# curl www.test.com

gdl1

[root@localhost conf]# curl www.test.com

gdl2

訪問10.0.0.3可以正常**至後端伺服器,並進行輪詢訪問後端伺服器。

nginx 負載均衡 Nginx負載均衡策略

nginx提供的負載均衡策略有2種 內建策略和擴充套件策略。內建策略為輪詢 預設 加權輪詢,ip hash,第三方。upstream mysvr1 輪詢 每個請求按照時間順序逐一的分配到每乙個後台伺服器上。如果某台伺服器宕機了,將會自動的剔除宕機的服務。nginx預設就是輪詢其權重都預設為1,伺服器...

nginx負載均衡安裝及測試

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 h...

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...