Getting started with redis
Redis introduction:
Redis is a key-value memory storage system, which is similar to memcache but supports data persistence. Redis supports many data types, including string, hash table, linked list, set, sorted set, and related operations based on these data types. Redis is developed in C language and optimized for memory allocation. Redis also supports a wide range of client languages, common computer languages such as C, C #, C ++, Object-C, PHP, Python, Java, Perl, Lua, and Erlang have available clients to access the Redis server. Currently, redis is widely used in large and small companies.
Redis installation:
Redis installation is relatively simple. You can directly download the source code for compilation and installation. At that time, you must install gcc in advance. Take the redhat series system as an example:
# yum install -y gcc# tar -czvf redis.tar.gz# cd redis# make && make test && make install
Make test is to test the basic functions of redis and ensure that redis can run normally on your machine.
Start redis:
# redis-server /etc/redis/redis.conf
The specific meaning of the configuration file
A specific configuration file is as follows:
Daemonize yes
Pidfile "/var/run/redis. pid"
Port 6381
Tcp-Back log 511
Timeout 0
Tcp-keepalive 0
Loglevel notice
Logfile "/var/log/redis. log"
Databases 16
Save 900 1
Save 300 10
Save 60 10000
Stop-writes-on-bgsave-error yes
Rdbcompression yes
Rdbchecksum yes
Dbfilename "dump. rdb"
Dir "/var/lib/redis /"
Masterauth "go-redis"
Slave-serve-stale-data yes
Slave-read-only yes
Repl-diskless-sync no
Repl-diskless-sync-delay 5
Repl-disable-tcp-nodelay no
Repl-backlog-size 1 mb
Slave-priority 100
Requirepass "go-redis"
Appendonly no
Appendfilename "appendonly. aof"
Appendfsync everysec
No-appendfsync-on-rewrite no
Auto-aof-rewrite-percentage 100
Auto-aof-rewrite-min-size 64 mb
Aof-load-truncated yes
Lua-time-limit 5000
Slowlog-log-slower-than 10000
Slowlog-max-len 128
Latency-monitor-threshold 0
Policy-keyspace-events ""
Hash-max-ziplist-entries 512
Hash-max-ziplist-value 64
List-max-ziplist-entries 512
List-max-ziplist-value 64
Set-max-intset-entries 512
Zset-max-ziplist-entries 128
Zset-max-ziplist-value 64
Hll-sparse-max-bytes 3000
Activerehashing yes
Client-output-buffer-limit normal 0 0 0
Client-output-buffer-limit slave 256 mb 64 mb 60
Client-output-buffer-limit pubsub 32 mb 8 mb 60
Hz 10
Aof-rewrite-incremental-fsync yes
Set the master-slave relationship of redis:
# redis-cli -a testpass -p 6381 > slaveof 10.1.1.2 6381OK
Or execute:
# redis-cli -a testpass -p 6381 slaveof 10.1.1.2 6381
View the active/standby pairing relationship:
# redis-cli -p 6381 info replication# Replicationrole:slavemaster_host:1.1.1.2master_port:6381master_link_status:downmaster_last_io_seconds_ago:-1master_sync_in_progress:0slave_repl_offset:0master_link_down_since_seconds:1507368352slave_priority:100slave_read_only:1connected_slaves:0master_replid:da725ce3153f5e4bf544924293259aaa31b728f2master_replid2:0000000000000000000000000000000000000000master_repl_offset:0second_repl_offset:-1repl_backlog_active:0repl_backlog_size:1048576repl_backlog_first_byte_offset:0repl_backlog_histlen:0
Cancel the master-slave relationship:
[root@rh6350G redis]# redis-cli -p 6381 slaveof NO ONEOK[root@rh6350G redis]# redis-cli -p 6381 info replication# Replicationrole:masterconnected_slaves:0master_replid:c4090d642878080ab4d59bbe847e94aab294d6b8master_replid2:da725ce3153f5e4bf544924293259aaa31b728f2master_repl_offset:0second_repl_offset:1repl_backlog_active:0repl_backlog_size:1048576repl_backlog_first_byte_offset:0repl_backlog_histlen:0
Configure sentinel:
Sentinel is a component used to monitor redis. sentinel itself is a cluster. Generally, three or five nodes are configured to ensure high availability, similar to the zookeeper cluster. A typical sentinel configuration file is as follows:
port 26380daemonize yeslogfile "/var/log/sentinel_log.log"dir "/tmp"sentinel monitor master0 10.1.1.1 6381 2sentinel down-after-milliseconds master0 15000sentinel auth-pass master0 go-redissentinel config-epoch master0 156sentinel leader-epoch master0 156sentinel known-slave master0 10.1.1.1 6381sentinel known-sentinel master0 10.1.1.1 26380 5970281bfa14f40f3ba8b75a2f87d570aac99bc8sentinel known-sentinel master0 10.1.1.3 26380 59ee62deddd88597e591c288a65b20d865df12d6sentinel monitor master2 10.1.1.3 6381 2sentinel down-after-milliseconds master2 15000sentinel auth-pass master2 go-redissentinel config-epoch master2 158sentinel leader-epoch master2 158sentinel known-slave master2 10.1.1.1 6381sentinel known-slave master2 10.1.1.4 6381sentinel known-sentinel master2 10.1.1.1 26380 5970281bfa14f40f3ba8b75a2f87d570aac99bc8sentinel known-sentinel master2 10.1.1.3 26380 59ee62deddd88597e591c288a65b20d865df12d6sentinel monitor master1 10.1.1.1 6382 2sentinel down-after-milliseconds master1 15000sentinel auth-pass master1 go-redissentinel config-epoch master1 153sentinel leader-epoch master1 153sentinel known-slave master1 10.1.1.2 6382sentinel known-sentinel master1 10.1.1.1 26380 5970281bfa14f40f3ba8b75a2f87d570aac99bc8sentinel known-sentinel master1 10.1.1.3 26380 59ee62deddd88597e591c288a65b20d865df12d6sentinel monitor master3 10.1.1.3 6382 2sentinel down-after-milliseconds master3 15000sentinel auth-pass master3 go-redissentinel config-epoch master3 139sentinel leader-epoch master3 135sentinel known-slave master3 10.1.1.4 6382sentinel known-sentinel master3 10.1.1.1 26380 5970281bfa14f40f3ba8b75a2f87d570aac99bc8sentinel known-sentinel master3 10.1.1.3 26380 59ee62deddd88597e591c288a65b20d865df12d6sentinel current-epoch 158
In this example, sentinel is deployed on 10.1.1.1, 10.1.1.2, and 10.1.1.3 to monitor the redis servers 10.1.1.1 and 10.1.1.2.
Start sentinel:
# redis-sentinel /etc/redis/sentinel.conf