在根目录创建一个文件夹
mkdir myredis
将原来运行的redis配置文件复制到此处一份
cp /etc/redis.conf /myredis/redis.conf
创建子配置运行文件
vi redis6379.config
redis6379.config详细
include /myredis/redis.conf
pidfile /var/run/redis_6379.pid
port 6379
dbfilename dump6379.rdb
以相同方式创建redis6380.conf redis6381.conf
运行三台redis(一主二从)
redis-server redis6379.conf
redis-server redis6380.conf
redis-server redis6381.conf
进入redis
[root@bogon myredis]# redis-cli -p 6379
127.0.0.1:6379> info replication //查看信息
# Replication
role:master
进入6380/6381设置主服务器
127.0.0.1:6380> SLAVEOF 127.0.0.1 6379
127.0.0.1:6381> SLAVEOF 127.0.0.1 6379
查看从服务器info
127.0.0.1:6380> info replication
# Replication
role:slave
master_host:127.0.0.1
master_port:6379
master_link_status:up
master_last_io_seconds_ago:7
master_sync_in_progress:0
slave_read_repl_offset:1315
slave_repl_offset:1315
slave_priority:100
slave_read_only:1
查看主服务器info
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=127.0.0.1,port=6380,state=online,offset=1357,lag=1
slave1:ip=127.0.0.1,port=6381,state=online,offset=1357,lag=1
master_failover_state:no-failover
master_replid:5781dda1b1fca93a4ff7919d6365bb05d3287ed3
通过在服务器上查看管道符查看redis的运行状态
[root@bogon myredis]# ps -ef | grep redis
root 12823 1 0 21:37 ? 00:00:01 redis-server 0.0.0.0:6380
root 13011 1 0 21:37 ? 00:00:01 redis-server 0.0.0.0:6381
root 18566 86854 0 21:39 pts/2 00:00:00 redis-cli -p 6380
root 20417 19285 0 21:40 pts/4 00:00:00 redis-cli -p 6381
root 89526 91189 0 21:58 pts/0 00:00:00 grep --color=auto redis
root 112060 1 0 20:34 ? 00:00:04 redis-server 0.0.0.0:6379
[root@bogon myredis]#