《Centos系统——nginx负载均衡》

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访问

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值