CentOS 7
Ads

Redis : Replication Setting
2016/07/21
 
Configure Redis Replication. This configuration is general Master-Slave settings.
[1] Change Settings on Master Host.
[root@dlp ~]#
vi /etc/redis.conf
# line 64: change to own IP or 0.0.0.0

bind
0.0.0.0
# line 377: add follows if you need

# min-slaves-to-write : if number of slave Hosts are online, Master Host accepts write requests

# min-slaves-max-lag : decision time(sec) for online if Slave Hosts return answer within specified time

min-slaves-to-write 2
min-slaves-max-lag 10
[root@dlp ~]#
systemctl restart redis
[2] Cahnge Settings on Slave Hosts.
[root@node01 ~]#
vi /etc/redis.conf
# line 64: change to own IP or 0.0.0.0

bind
0.0.0.0
# line 206: add Master server's IP and port

slaveof 10.0.0.30 6379
# line 213: add connection password set on Master Host

masterauth password
# line 241: verify parameter (set Slave Hosts read-only)

slave-read-only yes
[root@node01 ~]#
systemctl restart redis
[3] If Firewalld is running on Master/Slave Hosts, allow Redis port.
[root@dlp ~]#
firewall-cmd --add-port=6379/tcp --permanent

success
[root@dlp ~]#
firewall-cmd --reload

success
[4] If SELinux is enabled on Slave Hosts, add rules for replication like follows.
[root@node01 ~]#
vi redis_repl.te
# create new

module redis_repl 1.0;

require {
        type redis_port_t;
        type redis_t;
        class tcp_socket name_connect;
}

#============= redis_t ==============
allow redis_t redis_port_t:tcp_socket name_connect;

[root@node01 ~]#
checkmodule -m -M -o redis_repl.mod redis_repl.te

checkmodule: loading policy configuration from redis_repl.te
checkmodule: policy configuration loaded
checkmodule: writing binary representation (version 17) to redis_repl.mod
[root@node01 ~]#
semodule_package --outfile redis_repl.pp --module redis_repl.mod

[root@node01 ~]#
semodule -i redis_repl.pp

[5] Verify statics on Slave Hosts, then it's OK if "master_link_status:up" is shown.
[root@node01 ~]#
redis-cli info Replication

# Replication
role:slave
master_host:10.0.0.30
master_port:6379
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:384
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

# try to get a Key normally

[root@node01 ~]#
redis-cli get key_on_master

"value_on_master"
 
Tweet