日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

nginx的负载均衡

發布時間:2025/7/25 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nginx的负载均衡 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

根據osi分四層負載均衡和七層負載均衡

四層:主要是在傳輸層,傳輸層能支持到tcp協議的控制,所以對客戶端的請求只需要進行tcp/ip的包轉發,就可以實現負載均衡

七層:主要是在應用層,可以實現http協議的改寫,頭信息的改寫,安全應用規則的控制以及轉發等的規則,nginx就是七層負載均衡的SLB

?

?

?

nginx負載均衡實現的原理:使用的是proxy_pass

把所有端的請求,代理轉發到對應后端的服務器上,轉發到一組小服務池,upstream server

配置語法:

必須是在http以內,server層以外

例子:

在/opt/app下面有三個文件夾 code1 code2 code3

在每個文件夾中都放了不同展示效果的頁面

比如其中一個頁面index.html

<html> <head><meta charset="utf-8"><title>server1</title> </head> <body style="background-color:yellow;"><h1>server 1</h1> </body> </html>

在 /etc/nginx/conf.d/下建了三個conf? ?server1.conf? server2.conf? ?server3.conf

比如其中一個conf中server1.conf

server{listen 8001;server_name localhost;access_log /var/log/nginx/log/server1.access.log main;location /{root /opt/app/code1;index index.html index.htm;}

server2.conf

server{listen 8002;server_name localhost;access_log /var/log/nginx/log/server2.access.log main;location /{root /opt/app/code2;index index.html index.htm;}

開始配置負載均衡

新建一個虛擬server 叫:upsream_test.conf

upstream imooc{server 116.62.103.228:8001; server 116.62.103.228:8002; server 116.62.103.228:8003; } server{listen 80;server_name localhost jeson.peak;access_log /var/log/nginx/test_proxy.access.log main;location /{proxy_pass http://imooc;include proxy_params;} }

nginx -s reload -c /etc/nginx/nginx.conf

訪問 jeson.peak就可以了 ,默認是輪詢的狀態

假設有一個服務掛掉

iptables -I INPUT -p tcp --dport 8002 -j DROP

用這個規則關掉8002之后

就不會顯示對應的8002端口對應的頁面了

?

清理規則 iptables -F

配置負載均衡調度中的狀態

nginx的輪詢策略與加權輪詢

ip_hash是把相同請求轉到同一臺服務器

url_hash 是基于url負載均衡的方式

?

轉載于:https://www.cnblogs.com/gaosf/p/10232131.html

總結

以上是生活随笔為你收集整理的nginx的负载均衡的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。