Redis Database
I. Installing and configuring Redis
1. Installing Redis
[Email protected] ~]# wget http://download.redis.io/releases/redis-3.2.8.tar.gz
[Email protected] ~]# TAR-ZXVF redis-3.2.8.tar.gz-c/usr/local/src/
[Email protected] ~]# ln-sv/usr/local/src/redis-3.2.8//usr/local/redis
[Email protected] ~]# cd/usr/local/redis/
[[email protected] redis]# ls
00-releasenotes contributing Deps Makefile readme.md redis.conf runtest-cluster sentinel.conf tests
BUGS COPYING INSTALL MANIFESTO redis runtest runtest-sentinel src utils
[[email protected] redis]# make
[[email protected] redis]# make install
[email protected] redis]# CP redis.conf/etc
[Email protected] redis]# vim/etc/redis.conf
Bind 0.0.0.0 #设置redis监听的地址
Daemonize Yes #设置redis以守护进程的方式启动
Dir/redisdb #设置redis缓存数据的目录
LogFile "/redisdb/redis.log"
AppendOnly Yes #开启AOF持久化日志
[Email protected] redis]# Mkdir/redisdb
2. Start Redis
[Email protected] redis]# redis-server/etc/redis.conf
[[Email protected] redis]# PS aux|grep Redis
Root 29198 0.0 0.3 129500 3596? SSL 20:11 0:00 redis-server 0.0.0.0:6379
Root 29202 0.0 0.2 103312 2108 pts/0 s+ 20:12 0:00 grep redis
[Email protected] redis]# Netstat-anptul|grep Redis
TCP 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 29198/redis-server
2. Stop Redis
[Email protected] redis]# REDIS-CLI shutdown
Second, master-slave replication:
Main: 192.168.1.78-----------------> From: 192.168.1.53
There is nothing to say about the configuration of the master, as above. From the configuration below, from the configuration is also very simple, just need to open slaveof in its configuration file, such as:
Slaveof 192.168.1.78 6379
Masterauth Flux100plat
[Email protected] ~]# grep-v "^#"/etc/redis.conf |grep-v "^$"
Bind 0.0.0.0
Protected-mode Yes
Port 6379
Tcp-backlog 511
Timeout 0
Tcp-keepalive 300
Daemonize Yes
Supervised no
Pidfile/var/run/redis_6379.pid
LogLevel Notice
LogFile ""
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/redisdb
Slaveof 192.168.1.78 6379
Masterauth Flux100plat
Slave-serve-stale-data Yes
Slave-read-only Yes
Repl-diskless-sync No
Repl-diskless-sync-delay 5
Repl-disable-tcp-nodelay No
Slave-priority 100
AppendOnly Yes
Appendfilename "Appendonly.aof"
Appendfsync everysec
No-appendfsync-on-rewrite No
Auto-aof-rewrite-percentage 100
Auto-aof-rewrite-min-size 64MB
aof-load-truncated Yes
Lua-time-limit 5000
Slowlog-log-slower-than 10000
Slowlog-max-len 128
Latency-monitor-threshold 0
Notify-keyspace-events ""
Hash-max-ziplist-entries 512
Hash-max-ziplist-value 64
List-max-ziplist-size-2
List-compress-depth 0
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 256MB 64MB 60
Client-output-buffer-limit pubsub 32MB 8MB 60
Hz 10
Aof-rewrite-incremental-fsync Yes
Then restart:
[Email protected] redis]# REDIS-CLI shutdown
[Email protected] redis]# redis-server/etc/redis.conf
To view the configuration:
[Email protected] ~]# REDIS-CLI
127.0.0.1:6379> INFO Replication
# Replication
Role:slave
master_host:192.168.1.78
master_port:6379
Master_link_status:up
Master_last_io_seconds_ago:6
master_sync_in_progress:0
slave_repl_offset:57
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
127.0.0.1:6379> Scan 0
1) "128"
2) 1) "1386229"
2) "1529562"
3) "1377317"
4) "1886250"
5) "1381493"
6) "1889670"
7) "1365620"
8) "1377610"
9) "1377173"
10) "1515178"
---------------------can see that the data is synchronized.
In the Lord View:
[Email protected] ~]# REDIS-CLI
127.0.0.1:6379> Auth Flux100plat
Ok
127.0.0.1:6379> Info Replication
# Replication
Role:master
Connected_slaves:1
Slave0:ip=192.168.1.53,port=6379,state=online,offset=1289,lag=1
master_repl_offset:1289
Repl_backlog_active:1
repl_backlog_size:1048576
Repl_backlog_first_byte_offset:2
repl_backlog_histlen:1288
Execute the following command from the library:
slaveof 192.168.1.78 3789 Masterauth Flux100plat
You can also perform synchronous operations
Slaveof no one interrupts replication
This article is from the "Linunx" blog, please be sure to keep this source http://lijianmin2008.blog.51cto.com/621678/1925098
Redis database Master-slave replication