centOS7.4+nginx 1.12.2负载均衡
1:参数信息
三台 centOS7.4 A,B,C
A作为主服务器,B C作为分流的服务器
都搭建 nginx 1.12.2
1:下载nginx rpm 包
]# wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm;
]# rpm -Uvh nginx-release-centos-7-0.el7.ngx.noarch.rpm
2:安装
]# yum install nginx
3:启动
]# systemctl start nginx
4:设置开机自启动
]# systemctl enable nginx
// 如果还是访问不了,就检查一下防火墙,看是否有开80端口
]# firewall-cmd --list-add
// 开放80端口 --permanent 表示永久开放
]# firewall-cmd --add-port=80/tcp --permanent
// 开放之后,要重新加载一下,才能生效
]# firewall-cmd --reload
// 可以访问了,就表 nginx 已经搭好了
接下来就是在主服务器A中配置 nginx 咯
在 nginx 的配置文件 default.conf 中,增加
upstream webservers{
ip_hash;
server 192.168.0.145:80 weight=1;
server 192.168.0.140:80 weight=500;
}
## webservers 这个是负载名称,自定义
然后再 vhost.conf 文件中
配置
server {
location / {
proxy_pass http://webservers; ## 负载名称跟上面的配置一样
proxy_set_header X-Real-IP $remote_addr;
}
}
具体配置如下:
default.conf
vhost.conf
参考网站:http://www.zhuhongliang.com/archives/240