Redis configuration
Redis Introduction
Redis is an open source use written in ANSI C, based on the Key-Value database memory.
It supports relatively more stored value type, comprising a string (string), List (list), SET (set), zset (sorted set - ordered set) and hash (hash type).
Redis supports master-slave synchronization, data can be synchronized from the server from the primary server to any number, due to the full realization of the publish / subscribe mechanism, so that from time database synchronization tree anywhere, you can subscribe to a channel and receiving a master server full message release record.
Redis configuration on the CentOS7
Install redis
- In CentOS7 yum redis can be installed directly (direct input need to confirm y can)
[root@localhost ~]# yum install epel-release
[root@localhost ~]# yum install redis
Configuration Environment
[root@localhost ~]# vi /etc/redis.conf
- The [stop-writes-on-bgsave-error] is yes to no.
- [Will] daemonize of no change yes
- Esc: wq (save and exit)
- Restart environment
#reboot
Start redis
[root@localhost ~]# redis-server /etc/redis.conf
Use redis
Redis coupled to (connected to local default)
[root@localhost ~]# redis-cli
127.0.0.1:6379>
Ping
127.0.0.1:6379> ping
PONG
Setting key
127.0.0.1:6379> set testkey "hello"
OK
Query key
127.0.0.1:6379> get testkey
"hello"
Delete key
127.0.0.1:6379> del testkey
(integer) 1
The master-slave mode configuration Redis
Master
[root@localhost ~]# vi /etc/redis.conf
- Find bind 127.0.0.1, 127.0.0.1 will change your ip address (192.168.0.118)
- Find port 6379, does not change
- Esc: wq (Exit)
- Restart [reboot]
[root@localhost ~]# redis-server /etc/redis.conf
[root@localhost ~]# redis-cli -h 192.168.0.118 -p 6379
192.168.0.118:6379>
Slave
[root@localhost ~]# vi /etc/redis.conf
- Find bind 127.0.0.1, 127.0.0.1 will change your ip address (192.168.0.113)
- Find port 6379, will be replaced by 6379 6380
- # Slaveof find [], written in a separate line below [slaveof Master IP Maste Port]
slaveof 192.168.0.118 6379
- The [slave-read-only] changed to yes
- Esc: wq (Exit)
- Restart [reboot]
[root@localhost ~]# redis-server /etc/redis.conf
[root@localhost ~]# redis-cli -h 192.168.0.113 -p 6380
192.168.0.113:6380>
Redis separate read and write tests
Master
[root@localhost ~]# redis-cli -h 192.168.0.118 -p 6379
192.168.0.118:6379> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=192.168.0.113,port=6380,state=online,offset=4049,lag=1
master_repl_offset:4049
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:4048
192.168.0.118:6379> set test zjs
OK
192.168.0.118:6379>
Slave
192.168.0.113:6380> info replication
# Replication
role:slave
master_host:192.168.0.118
master_port:6379
master_link_status:up
master_last_io_seconds_ago:4
master_sync_in_progress:0
slave_repl_offset:4263
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
192.168.0.113:6380> get test
"zjs"
192.168.0.113:6380>