【NGINX】-8 nginx负载均衡实例-Redis


1、总部署图

我们需要四台虚拟机,代理服务器上安装nginx,服务器上安装redis,最后通过客户端访问以实现负载均衡
在这里插入图片描述

2、具体步骤

2.1 代理服务器编译安装nginx

安装完成
在这里插入图片描述

2.2 后端服务器需要安装redis

在这里我们选择yum安装

#安装两台redis服务器
[root@centos8 ~]# yum -y install redis 
[root@centos8 ~]# sed -i '/^bind /c bind 0.0.0.0' /etc/redis.conf
[root@centos8 ~]# systemctl enable --now redis
[root@centos8 ~]# ss -tnl | grep 6379
LISTEN     0      128         *:6379                     *:*  

在这里插入图片描述

2.3 修改nginx的配置文件

[root@localhost tcp]# vim /apps/nginx/conf/nginx.conf
在这里插入图片描述

[root@localhost tcp]# vim tcp.conf 
stream{
upstream redis_server{
server 192.168.107.193:6379;
server 192.168.107.192:6379;


}
server {
listen 192.168.107.190:6379;
proxy_pass redis_server;


}
}

刷新配置文件

[root@localhost tcp]# nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[root@localhost tcp]# nginx -s reload

2.4 测试访问

具体测试操作

在两台redis服务器上的操作

[root@localhost ~]# redis-cli
127.0.0.1:6379> set name def
OK
127.0.0.1:6379> get name
"def"
127.0.0.1:6379> 

[root@localhost ~]# redis-cli
127.0.0.1:6379> set name abc
OK
127.0.0.1:6379> get name
"abc"
127.0.0.1:6379> 


测试结果:

[root@localhost ~]# redis-cli -h 192.168.107.190
192.168.107.190:6379> get name
"abc"
192.168.107.190:6379> get name
"abc"
192.168.107.190:6379> get name
"abc"
192.168.107.190:6379> quit

[root@localhost ~]# redis-cli -h 192.168.107.190
192.168.107.190:6379> get name
"def"
192.168.107.190:6379> 

#负载均衡验证成功
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值