标签:
1、安装redis
首页地址:http://redis.io/
下载地址:http://download.redis.io/ 下载最新的源码包
wget http://download.redis.io/releases/redis-2.6.16.tar.gz tar -zxvf redis-stable.tar.gz -C /usr/local/ cd /usr/local/redis-stable/ make MALLOC=libc make install
2、运行
加载配置文件并后台运行
redis-server /usr/local/redis-stable/redis.conf &
#redis-cli (命令行工具)
3、测试
# redis-benchmark --help 获取帮助信息,其中包含压力测试命令样例
实际测试举例
[root@localhost~]# redis-benchmark -t set -c 20 -n 1000000 -r 100000000 ====== SET ====== 1000000 requests completed in 8.92 seconds 20 parallel clients 3 bytes payload keep alive: 1 100.00% <= 0 milliseconds 112095.06 requests per second
4、主从配置及测试:
主 | 10.10.10.34 | gc-redis1 | 6379 |
从 | 10.10.10.35 | gc-redis2 | 6379 |
从 | 10.10.10.36 | gc-redis3 | 6379 |
#主服务器(10.34)上做如下配置,其他默认即可:
[root@gc-redis1 redis-stable]# vim /usr/local/redis-stable/redis.conf masterauth "redispass" requirepass "redispass"
#从服务器上(10.35,10.36)做如下配置,其他默认即可:
[root@gc-redis2 redis-stable]# vim /usr/local/redis-stable/redis.conf slaveof 10.10.10.34 6379 masterauth "redispass" requirepass "redispass"
#启动主、从redis服务:
redis-server /usr/local/redis-stable/redis.conf &
#主服务器显示信息:
[13997] 03 Nov 09:57:21.045 * Slave ask for synchronization [13997] 03 Nov 09:57:21.045 * Starting BGSAVE for SYNC [13997] 03 Nov 09:57:21.046 * Background saving started by pid 14002 [14002] 03 Nov 09:57:21.058 * DB saved on disk [14002] 03 Nov 09:57:21.059 * RDB: 0 MB of memory used by copy-on-write [13997] 03 Nov 09:57:21.070 * Background saving terminated with success [13997] 03 Nov 09:57:21.070 * Synchronization with slave succeeded
#从服务器显示信息:
[3496] 03 Nov 09:56:41.953 * Connecting to MASTER... [3496] 03 Nov 09:56:41.953 * MASTER <-> SLAVE sync started [3496] 03 Nov 09:56:41.954 * Non blocking connect for SYNC fired the event. [3496] 03 Nov 09:56:41.954 * Master replied to PING, replication can continue... [3496] 03 Nov 09:56:42.055 * MASTER <-> SLAVE sync: receiving 18 bytes from master [3496] 03 Nov 09:56:42.055 * MASTER <-> SLAVE sync: Loading DB in memory [3496] 03 Nov 09:56:42.055 * MASTER <-> SLAVE sync: Finished with success [3499] 03 Nov 09:56:42.056 * SYNC append only file rewrite performed [3499] 03 Nov 09:56:42.057 * AOF rewrite: 0 MB of memory used by copy-on-write [3496] 03 Nov 09:56:42.057 * Background append only file rewriting started by pid 3499 [3496] 03 Nov 09:56:42.154 * Background AOF rewrite terminated with success [3496] 03 Nov 09:56:42.154 * Parent diff successfully flushed to the rewritten AOF (0 bytes) [3496] 03 Nov 09:56:42.154 * Background AOF rewrite finished successfully
#主服务器查看主从信息
[root@gc-redis3 ~]# redis-cli -h 127.0.0.1 -a jrgcredispass info replication # Replication role:master connected_slaves:2 slave0:ip=10.10.10.35,port=6379,state=online,offset=168812144,lag=1 slave1:ip=10.10.10.36,port=6379,state=online,offset=168812144,lag=0 master_repl_offset:168812281 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:167763706 repl_backlog_histlen:1048576
#从服务器查看主从信息
[root@gc-redis1 ~]# redis-cli -h 127.0.0.1 -a jrgcredispass info replication # Replication role:slave master_host:10.10.10.34 master_port:6379 master_link_status:up master_last_io_seconds_ago:0 master_sync_in_progress:0 slave_repl_offset:168809239 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
#写同步测试
[root@gc-redis1 ~]# redis-cli -h 127.0.0.1 -a redispass redis 127.0.0.1:6379> set a 123 OK redis 127.0.0.1:6379> get a "123"
#从服务器
Redis 安装,主从配置及Sentinel配置自动Failover
标签:
原文地址:http://www.cnblogs.com/saneri/p/5275261.html