Before start
Download and install redis from official site
redis excutable commands are under bin
folder, configs are under etc
folder, logs are under var
folder
Redis master Configuration 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 daemonize yes pidfile "/var/run/redis_6379.pid" logfile "/var/log/6379.log" databases 16 dbfilename dump.rdb dir "/var/dump/" port 6379 bind ip1 ip2 ip3 requirepass password
Start Master 1 redis-server /redis/etc/{master.config}
Verify Master 1 redis-cli -h 127.0.0.1 -p 6379 -a password info replication
You should see something like this, if you have slave you will see number of connected_slaves
:
1 2 3 4 5 6 7 8 9 10 11 [root@lx-uk-ssm129 redis]# bin/redis-cli -p 6379 -a password info replication # Replication role:master connected_slaves:2 slave0:ip=127.0.0.1,port=8880,state=online,offset=110104326,lag=1 slave1:ip=127.0.0.1,port=8879,state=online,offset=110104386,lag=1 master_repl_offset:110104386 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:109055811 repl_backlog_histlen:1048576
Redis slave Configuration Repeat master configuration, change your port, bind ip…etc, the only difference are two lines :
1 2 3 4 5 slaveof 127.0.0.1 6379 masterauth password
Start Slave 1 redis-server /redis/etc/{slave.config}
Verify Slave 1 redis-cli -h 127.0.0.1 -p 6379 -a password info replication
You will see something like this :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 [root@example redis]# bin/redis-cli -h 127.0.0.1 -p 8879 -a password info replication # Replication role:slave master_host:127.0.0.1 master_port:6379 master_link_status:up master_last_io_seconds_ago:1 master_sync_in_progress:0 slave_repl_offset:108498274 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
Sentinel Create sentinel.conf 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 port 26379 dir /tmp sentinel monitor master 127.0 .0 .1 6379 1 sentinel down-after-milliseconds master 3000 sentinel parallel-syncs master 1 sentinel failover-timeout master 18000
Start sentinel 1 redis-server sentinel.conf --sentinel
Verify sentinel 1 redis-cli -h 127.0.0.1 -p 26379 info sentinel
Useful commands 1 2 3 4 5 ps –ef | grep redis kill PID
Normally you don’t need quote for string,
If string contains special character, use quote ""
or ''
Difference between ""
or ''
is double quote parse escape character but single quote doesn’t