目录
nginx负载均衡
nginx包:
链接: https://pan.baidu.com/s/1B1jr9nhDgl2scdEhBeBVCg 提取码: 41m2 复制这段内容后打开百度网盘手机App,操作更方便哦
1. 准备3台虚拟机,关闭iptables、配置yum源、设置selinux为关闭
192.168.179.130
192.168.179.131
192.168.179.132
[root@localhost ~]# systemctl stop firewalld -----关闭防火墙
[root@localhost ~]# setenforce 0 -----关闭selinux
[root@localhost ~]# yum repolist -----yum源
已加载插件:fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Determining fastest mirrors
* base: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.huaweicloud.com
源标识 源名称 状态
!base/7/x86_64 CentOS-7 - Base 10,070
!extras/7/x86_64 CentOS-7 - Extras 413
!updates/7/x86_64 CentOS-7 - Updates 1,134
repolist: 11,617
2. 源码编译安装nginx
上传nginx包
链接: https://pan.baidu.com/s/1LTB7P3y3jNHDSA6pvvulFA 提取码: pabc 复制这段内容后打开百度网盘手机App,操作更方便哦
[root@localhost ~]# yum -y install gcc gcc-c++ pcre-devel zlib-devel -----安装依赖
[root@localhost ~]# tar xzf nginx-1.12.2.tar.gz
[root@localhost ~]# cd nginx-1.12.2
[root@localhost nginx-1.12.2]# ./configure && make && make install
3. 配置nginx负载均衡,一台作负载均衡器,另外两台做rs
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf -----修改配置文件
4. 配置nginx负载均衡调度算法为加权轮询
5. 加权轮询的比例为1:3
6. 给后端两台rs编写不同的测试访问页面
192.168.179.131
[root@localhost log]# cat /usr/local/nginx/html/index.html
web1
192.168.179.132
[root@localhost log]# cat /usr/local/nginx/html/index.html
web2
7. 启动nginx
[root@localhost ~]# /usr/local/nginx/sbin/nginx -----启动nginx
8. 测试nginx访问