环境准备:
角色 | ip地址 | 端口 | master | 192.168.135.139 | 6379 | slave | 192.168.135.139 | 6380 | slave | 192.168.135.139 | 6381 |
多实例配置
1.创建多实例目录
[root@net01 ~]# mkdir /server/redis/{6379,6380,6381} -p
2.配置多实例
[root@net01 ~]# vim /server/redis/6379/redis.conf
daemonize yes
bind 192.168.135.139 127.0.0.1
port 6379
pidfile /server/redis/6379/redis.pid
logfile /server/redis/6379/redis.log
protected-mode no
dir /server/redis/6379
dbfilename dump.rdb
save 900 1
save 300 10
save 60 10000
requirepass 123 #master密码
[root@net01 ~]# vim /server/redis/6380/redis.conf
daemonize yes
bind 192.168.135.139 127.0.0.1
port 6380
pidfile /server/redis/6380/redis.pid
logfile /server/redis/6380/redis.log
protected-mode no
dir /server/redis/6380
dbfilename dump.rdb
save 900 1
save 300 10
save 60 10000
masterauth 123 #必须跟master密码一致
[root@net01 ~]# vim /server/redis/6381/redis.conf
daemonize yes
bind 192.168.135.139 127.0.0.1
port 6381
pidfile /server/redis/6381/redis.pid
logfile /server/redis/6381/redis.log
protected-mode no
dir /server/redis/6381
dbfilename dump.rdb
save 900 1
save 300 10
save 60 10000
masterauth 123 #必须跟master密码一致
3.启动多实例
[root@net01 ~]# redis-server /server/redis/6379/redis.conf
[root@net01 ~]# redis-server /server/redis/6380/redis.conf
[root@net01 ~]# redis-server /server/redis/6381/redis.conf
4.检查启动
[root@net01 6379]# ps -ef | grep redis
root 3300 1 0 07:18 ? 00:00:02 redis-server 192.168.135.139:6379
root 3744 1 0 07:32 ? 00:00:01 redis-server 192.168.135.139:6380
root 3749 1 0 07:32 ? 00:00:01 redis-server 192.168.135.139:6381
root 4391 2781 0 08:14 pts/0 00:00:00 grep --color=auto redis
5.连接mster redis查看状态
[root@net01 ~]# redis-cli -p 6379
127.0.0.1:6379> auth 123
OK
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
127.0.0.1:6379>
6.分别进入6380/6381从redis连接主库并查看状态。
[root@net01 ~]# redis-cli -p 6380
127.0.0.1:6380> SLAVEOF 192.168.135.139 6379
OK
127.0.0.1:6380> info replication
# Replication
role:slave
master_host:192.168.135.139
master_port:6379
master_link_status:up
master_last_io_seconds_ago:4
master_sync_in_progress:0
slave_repl_offset:3851
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
[root@net01 ~]# redis-cli -p 6381
127.0.0.1:6381> SLAVEOF 192.168.135.139 6379
OK
127.0.0.1:6381> info replication
# Replication
role:slave
master_host:192.168.135.139
master_port:6379
master_link_status:up
master_last_io_seconds_ago:9
master_sync_in_progress:0
slave_repl_offset:3795
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
7.查看mater redis 状态
[root@net01 ~]# redis-cli -p 6379
127.0.0.1:6379> auth 123
OK
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.135.139,port=6380,state=online,offset=4089,lag=1
slave1:ip=192.168.135.139,port=6381,state=online,offset=4089,lag=1
master_repl_offset:4089
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:4088
127.0.0.1:6379>
|