1. Installing Redis
Home Address: http://redis.io/
: http://download.redis.io/Download the latest source package
wget HTTP://DOWNLOAD.REDIS.IO/RELEASES/REDIS-2.6.16.TAR.GZTAR-ZXVF redis-stable.tar.gz-c/usr/local/cd/usr/local/ Redis-stable/make Malloc=libcmake Install
2. Operation
Load configuration files and run in the background
Redis-server/usr/local/redis-stable/redis.conf &
#redis-cli (command line tools)
3. Testing
# Redis-benchmark--help Get help information including stress test command sample
Practical Test Examples
[[Email protected]~]# redis-benchmark-t set-c 20-n 1000000-r 100000000====== set ====== 1000000 requests completed in 8.92 seconds Parallel clients 3 bytes payload Keep alive:1100.00% <= 0 milliseconds112095.06 requests per second
4. Master-slave configuration and measurement Try:
Main |
10.10.10.34 |
Gc-redis1 |
6379 |
From |
10.10.10.35 |
Gc-redis2 |
6379 |
From |
10.10.10.36 |
Gc-redis3 |
6379 |
#主服务器 (10.34) The following configuration, the other default can be:
[Email protected] redis-stable]# vim/usr/local/redis-stable/redis.conf masterauth "Redispass" Requirepass "Redispass "
#从服务器上 (10.35,10.36) Do the following configuration, other default:
[Email protected] redis-stable]# vim/usr/local/redis-stable/redis.conf slaveof 10.10.10.34 6379masterauth "Redispass "Requirepass" Redispass "
#启动主, from Redis services:
Redis-server/usr/local/redis-stable/redis.conf &
#主服务器显示信息:
[13997] 09:57:21.045 * Slave ask for synchronization[13997] Geneva 09:57:21.045 * Starting BGSAVE for sync[13997] 0 3 Nov 09:57:21.046 * Background saving started by PID 14002[14002] Geneva 09:57:21.058 * DB saved on disk[14002] Geneva 09 : 57:21.059 * rdb:0 MB of memory used by copy-on-write[13997] Geneva 09:57:21.070 * Background saving terminated with SUCC ess[13997] 09:57:21.070 * Synchronization with Slave succeeded
#从服务器显示信息:
[3496] 09:56:41.953 * Connecting to MASTER ... [3496] 09:56:41.953 * MASTER <-> SLAVE sync started [3496] Geneva 09:56:41.954 * Non blocking Connect for SY NC fired the event. [3496] 09:56:41.954 * Master replied to PING, replication can continue ... [3496] 09:56:42.055 * Master <-> SLAVE sync:receiving bytes from master [3496] Geneva 09:56:42.055 * MAS TER <-> SLAVE sync:loading DB in memory [3496] Geneva 09:56:42.055 * MASTER <-> SLAVE sync:finished with Su ccess [3499] Geneva 09:56:42.056 * SYNC append only file rewrite performed [3499] Geneva 09:56:42.057 * AOF rewrite:0 M B of memory used by Copy-on-write [3496] Geneva 09:56:42.057 * Background append only file rewriting started by PID 3499 [3496] 09:56:42.154 * Background AOF rewrite terminated with success [3496] Geneva 09:56:42.154 * Parent diff suc Cessfully flushed to the rewritten AOF (0 bytes) [3496] Geneva 09:56:42.154 * Background AOF rewrite finishedSuccessfully
#主服务器查看主从信息
[Email protected] ~]# redis-cli-h 127.0.0.1-a jrgcredispass info replication# replicationrole:masterconnected_slaves : 2slave0:ip=10.10.10.35,port=6379,state=online,offset=168812144,lag=1slave1:ip=10.10.10.36,port=6379,state= Online,offset=168812144,lag=0master_repl_offset:168812281repl_backlog_active:1repl_backlog_size:1048576repl_ backlog_first_byte_offset:167763706repl_backlog_histlen:1048576
#从服务器查看主从信息
[Email protected] ~]# redis-cli-h 127.0.0.1-a jrgcredispass info replication# replicationrole:slavemaster_host : 10.10.10.34master_port:6379master_link_status:upmaster_last_io_seconds_ago:0master_sync_in_progress:0slave_ Repl_offset:168809239slave_priority:100slave_read_only:1connected_slaves:0master_repl_offset:0repl_backlog_ active:0repl_backlog_size:1048576repl_backlog_first_byte_offset:0repl_backlog_histlen:0
#写同步测试
#主服务器
[Email protected] ~]# redis-cli-h 127.0.0.1-a redispass redis 127.0.0.1:6379> set a 123OKredis 127.0.0.1:6379> ge T a "123"
#从服务器
Redis installation, master-slave configuration and Sentinel configuration automatic failover