西数超哥博客
运维经验教程分享

[原创]linux系统下进行redis进行主从配置、测试以及常用参数优化

21运维原创,转载请注明出处。

前期准备两台服务器
redis1:192.168.1.9 (主)
redis2:192.168.1.10(从)
1,安装redis
首先安装epel源
yum install epel-release -y
安装redis
yum install redis jemalloc-devel -y

2,配置从服务器
2.1主服务器修改配置文件,把bind的IP改成自己的服务器局域网IP或公网IP
2.2从服务器做如下操作,修改配置文件添加如下一行:
slaveof 192.168.1.9 6379
如果主redis设置了密码,从服务器要添加:
masterauth password(master的redis密码)

3,测试主从
分别启动主从上的redis

[root@web1 ~]# tail -f /var/log/redis/redis.log
[1681] 17 May 15:15:38 * Server started, Redis version 2.4.10
[1681] 17 May 15:15:38 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[1681] 17 May 15:15:38 * DB loaded from disk: 0 seconds
[1681] 17 May 15:15:38 * The server is now ready to accept connections on port 6379
[1681] 17 May 15:15:38 * Connecting to MASTER...
[1681] 17 May 15:15:38 * MASTER  SLAVE sync started
[1681] 17 May 15:15:38 * Non blocking connect for SYNC fired the event.
[1681] 17 May 15:15:38 * MASTER  SLAVE sync: receiving 18 bytes from master
[1681] 17 May 15:15:38 * MASTER  SLAVE sync: Loading DB in memory
[1681] 17 May 15:15:38 * MASTER  SLAVE sync: Finished with success

我们从主服务器上set一个值,然后到从服务器上看下是否可以get到。如果可以get到就说明主从配置成功了。

4,主从参数优化
slave-only-read  yes 让从只读

repl-ping-slave-eriod 30 设置从服务器向master发起ping的频率。做健康监测
repl-timeout 60 设置slave ping 不通master多少秒超时
slave-priority 1  设置优先级,数值越小优先级越高。在从服务器较多情况下,如果master挂了,那么从服务器会按照优先级进行接管,优先级高的切换。
min-slaves-max-lag 10 

min-slaves-to-write 3  master发现从服务器数量延迟较高的数量,默认0.如果高于设置的值,master会停止读写。

转载请注明:西数超哥博客www.ysidc.top» [原创]linux系统下进行redis进行主从配置、测试以及常用参数优化

https://www.ysidc.top 西数超哥博客,数据库,西数超哥,虚拟主机,域名注册,域名,云服务器,云主机,云建站,ysidc.top

赞(0)
声明:本站发布的内容(图片、视频和文字)以原创、转载和分享网络内容为主,若涉及侵权请及时告知,将会在第一时间删除。本站原创内容未经允许不得转载:西数超哥博客 » [原创]linux系统下进行redis进行主从配置、测试以及常用参数优化