四、nginx负载均衡:
nginx:192.168.80.146
web1:192.168.80.143
web2:192.168.80.144(web2同web1即可)
- # egrep -v "^$|#" /etc/nginx/nginx.conf
- worker_processes 1;
- events {
- worker_connections 1024;
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- upstream peace { //名字为peace
- server 192.168.80.143 weight=1; //定义节点信息,weight指定权重
- server 192.168.80.144 weight=2;
- }
- sendfile on;
- keepalive_timeout 65;
- server {
- listen 80;
- server_name localhost;
- location / {
- proxy_pass http://peace; //引用peace的负载均衡
- }
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
- }
- }
- # service nginx restart
下面访问下nginx可以看到有轮询
但是这里有个问题就是没有状态检查,有错误时还照样轮询,所以这里使用第三方来做健康监测


