Redis主从复制安装部署:
环境部署:至少需要2台,满足一主一从。
主库:172.17.80.204
从库:172.17.80.60
主库redis的配置文件:
# cat /usr/local/redis/etc/redis.conf
bind 172.17.80.204 127.0.0.1
protected-mode yes
port 6379
daemonize yes
logfile "/usr/local/redis/redis.log"
dir /usr/local/redis
slave-serve-stale-data yes
slave-read-only no
#masterauth "redhat6.3" #主库不需要配置
requirepass "redhat6.3"
appendonly yes
appendfilename "appendonly.aof"
从库redis的配置文件:
# cat /usr/local/redis/etc/redis.conf
bind 172.17.80.60 127.0.0.1
protected-mode yes
port 6379
daemonize yes
logfile "/usr/local/redis/redis.log"
dir /usr/local/redis
slaveof 172.17.80.204 6379
slave-serve-stale-data yes
slave-read-only yes
masterauth "redhat6.3"
requirepass "redhat6.4" #此密码可以单独配置
appendonly yes
appendfilename "appendonly.aof"
启动主库和从库的redis服务:
# ./redis-server ../etc/redis.conf
# ps -ef | grep redis
root 27631 1 0 11:30 ? 00:00:00 ./redis-server 172.17.80.204:6379
root 27721 16676 0 11:30 pts/1 00:00:00 grep --color=auto redis
# ps -ef | grep redis
root 27631 1 0 11:30 ? 00:00:00 ./redis-server 172.17.80.204:6379
root 27752 16676 0 11:30 pts/1 00:00:00 grep --color=auto redis
登录redis主库,查看reids主从信息:
# redis-cli -a redhat6.3
测试redis主从是否同步:
主库输入key“test”并取值“hello”,从库获取key:
127.0.0.1:6379> set test 'hello'
OK
127.0.0.1:6379> get test
"hello"
# redis-cli -a redhat6.4
Warning: Using a password with '-a' option on the command line interface may not be safe.
127.0.0.1:6379> get test
"hello"
文档来源:51CTO技术博客https://blog.51cto.com/215687833/3302267
页:
[1]