性能测试全栈笔记:47.redis-多实例部署/主从配置
性能测试全栈笔记:47.redis-多实例部署/主从关系
上一章学习了redis基础理论及单实例部署,本章开始学习redis多实例部署以及redis主从关系,也是实际工作过程中常见的类型。
redis多实例部署:
原理:由于redis服务端是单线程实现的,因此只能占用CPU的单核,为了充分利用CPU资源,可以在一台服务器上同时启动多个redis-server实例
redis多实例配置方法:
- 每个实例创建一个conf文件
- 修改每个conf文件中的端口号
- 启动不同实例时指定不同的配置
开始操作:
1.在conf目录下,拷贝一份配置文件:[root@redis1 conf]# cp 6379.conf 6380.conf

2.修改拷贝后的配置:vi 6380.conf
- port:修改为6380,
port 6380
- dbfilename:修改为dump_6380.rdb,
dbfilename dump_6380.rdb
修改port:port 6380

修改dbfilename:dbfilename dump_6380.rdb

3.启动redis-server,端口为6380,[root@redis1 src]# redis-server ../conf/6380.conf

4.验证redis客户端:[root@redis1 src]# redis-cli -p 6380 -a qwe123

5.验证服务启动状态:[root@redis1 src]# ps -ef |grep redis
两个端口的redis服务都已启动。

下面是redis主从配置:
操作:在从redis的conf文件中,配置上slaveof 127.0.0.1 6379,重启从redis,其中127.0.0.1为主redis的IP地址,根据实际情况修改
在protected-mode no
下一行添加:slaveof 192.168.25.156 6379
masterauth qwe123

如果验证配置成功了:(主从能互相获取数据)
主redis中:
127.0.0.1:6379> set name lixue
OK
127.0.0.1:6379> get name
"lixue"

从redis中:
127.0.0.1:6379> get name
"lixue"

至此,redis主从配置完成。
更新不易,感谢支持。
附赠: