|
Centos222 |
Centos224 |
|
[centos222]# REDIS-CLI
127.0.0.1:6379>set KK 123
127.0.0.1:6379>get KK
"123"
127.0.0.1:6379>get mm
(nil)
127.0.0.1:6379>exit |
[centos224]# REDIS-CLI
127.0.0.1:6379>set KK 123
127.0.0.1:6379>get mm
"22222"
127.0.0.1:6379>get KK
(nil)
127.0.0.1:6379>exit |
|
next requires remote Access, config file set LAN IP, turn off protected mode
Vi/etc/redis/6379.conf |
|
Bind 127.0.0.1 192.168.1.222
Protected-mode No |
Bind 127.0.0.1 192.168.1.224
Protected-mode No |
|
Restart the Redis service and add the add-on port to access each other's Redis server. |
|
[centos222]# iptables-i input-p TCP--dport 6379-j ACCEPT
[centos222]# redis-cli-h 192.168.1.224-p 6379
192.168.1.224:6379> get mm
"22222" |
[centos222]# iptables-i input-p TCP--dport 6379-j ACCEPT
[centos224]# redis-cli-h 192.168.1.222-p 6379
192.168.1.222:6379> Get KK
"123" |
|
access no password, not secure, now set the system password parameter requirepass
(Take centos222 as an example, both servers need to be set up) |
|
127.0.0.1:6379> config get Requirepass #查看参数信息
1) "Requirepass"
2) ""
127.0.0.1:6379> config set requirepass 123456 #设置参数 (password) value
Ok
127.0.0.1:6379> config get Requirepass #设置密码后无法操作
(Error) Noauth Authentication required.
127.0.0.1:6379> Auth 123456 #使用密码访问
Ok
127.0.0.1:6379> Get KK
"123"
127.0.0.1:6379> exit
[centos222]# redis-cli-h 192.168.1.224-p 6379-a 123456 #远程访问
192.168.1.224:6379> get mm
"22222"
192.168.1.224:6379>
|
|
However, when the Redis service restarts, the Requirepass password is invalidated and the null value is changed back
to permanently take effect, add this parameter to the configuration file:vi/etc/redis/6379.conf |
|
Requirepass 123456 |
|
start Configuring Master-slave replication. Very simple. The configuration parameter slaveof is used primarily .
Vi/etc/redis/6379.conf |
|
Centos222 (Master) |
Centos224 (slave) |
|
Bind 127.0.0.1 192.168.1.222
Protected-mode No
Port 6379
Requirepass 654321
|
Bind 127.0.0.1 192.168.1.224
Protected-mode No
Port 6379
Requirepass 654321
Slaveof 192.168.1.222 6379
Masterauth 654321
Slave-read-only Yes |
|
configuration complete, restart the service. Found in the master set key, the slave can be read (slave read only). Master-Slave configuration is complete. |
|
[Root@centos222 ~]# Redis-cli
127.0.0.1:6379> Auth 654321
Ok
127.0.0.1:6379> Set QQ 6666666
Ok
127.0.0.1:6379> get QQ
"6666666"
127.0.0.1:6379> |
[root@centos224 ~]# Redis-cli
127.0.0.1:6379> Auth 654321
Ok
127.0.0.1:6379> get QQ
"6666666"
127.0.0.1:6379>
127.0.0.1:6379> Set pp 444
(Error) READONLY you can ' t write against a read only slave. |
|
Info Replication View replication configuration information |
|
127.0.0.1:6379> Info Replication
# Replication
Role:master
Connected_slaves:1
Slave0:ip=192.168.1.224,port=6379,state=online,offset=392,lag=0
master_repl_offset:392
Repl_backlog_active:1
repl_backlog_size:1048576
Repl_backlog_first_byte_offset:2
repl_backlog_histlen:391 |
127.0.0.1:6379> Info Replication
# Replication
Role:slave
master_host:192.168.1.222
master_port:6379
Master_link_status:up
Master_last_io_seconds_ago:3
master_sync_in_progress:0
slave_repl_offset:420
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 |
|
|
|