评论

收藏

[NoSQL] Redis主从复制安装部署:

数据库 数据库 发布于:2021-08-07 10:14 | 阅读数:490 | 评论:0

环境部署:
至少需要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服务:
[root@master bin]# ./redis-server ../etc/redis.conf
[root@master bin]# 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
[root@master bin]# 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
DSC0000.jpg


登录redis主库,查看reids主从信息:
[root@master ~]# redis-cli -a redhat6.3
DSC0001.jpg


测试redis主从是否同步:
主库输入key“test”并取值“hello”,从库获取key:
127.0.0.1:6379> set test 'hello'
OK
127.0.0.1:6379> get test
"hello"
DSC0002.jpg

[root@node01 ~]# 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"
DSC0003.jpg



关注下面的标签,发现更多相似文章