1.1.redis的安装
主机:192.168.249.11 cd /root/ tar xf redis-3.2.2.tar.gz cd redis-3.2.2 make mkdir /data/redis/3.2.2 make PREFIX=/data/redis/3.2.2 ×××tall mkdir /data/redis/3.2.2/conf mkdir /data/redis/3.2.2/rdb
1,2.生成配置文件
grep -E "^[a-Z]" redis.conf >/data/redis/3.2.2/conf/redis.conf
1.3.修改配置文件
vim /data/redis/3.2.2/conf/redis.confbind 0.0.0.0 dbfilename dump.rdb dir /data/redis/3.2.2/rdb/requirepass 123456 #手动添加
1.4.启动redis
cd /data/redis/3.2.2/bin/./redis-server /data/redis/3.2.2/conf/redis.conf &
1.5.测试
./redis-cli -h 127.0.0.1 auth 123456set 1 1写入10个key 查看/data/redis/3.2.2/rdb 是否有rdb文件,一般五分钟后会生成rdb文件默认是没有的 因为我们采用rdb文件的key的测率是save 900 1 900s 有1个key变化save 300 10 300s 有10个key变化save 60 10000 60s 有10000个key变化
2.1.redis rdb文件恢复
主机:192.168.249.12说明:redis已经安装完毕 和 上面流程一样可以看出如下 key没有[root@192.168.249.12 bin]# ps -ef|grep redisroot 3336 2633 0 23:38 pts/0 00:00:00 ./redis-server 0.0.0.0:6379root 3345 2633 0 23:38 pts/0 00:00:00 grep --color=auto redis[root@zabbix-agent bin]# ./redis-cli -h 127.0.0.1 127.0.0.1:6379> auth 123456OK127.0.0.1:6379> keys *(empty list or set)127.0.0.1:6379> 开始恢复:把192.168.249.11 的/data/redis/3.2.2/rdb/dump.rdb 拷贝到192.168.249.12下面/data/redis/3.2.2/rdb/192.168.249.12 重启redis 可以看出redis的key都已经恢复[root@zabbix-agent bin]# ./redis-cli -h 127.0.0.1 127.0.0.1:6379> auth 123456 OK127.0.0.1:6379> keys * 1) "5" 2) "6" 3) "4" 4) "100" 5) "3" 6) "7" 7) "2" 8) "9" 9) "8"10) "10"11) "1"127.0.0.1:6379> quit [root@zabbix-agent bin]#
3.1 redis salve 模式
主机:192.168.249.13 部署同 192.168.249.10 编辑配置文件vim /data/redis/3.2.2/conf/redis.conf 添加如下 slaveof 192.168.249.11 6379 #master的ip 和端口masterauth 123456 ##master的密码启动即可
4.1 redis slave的提升为master
先设置redis slave 没有主
salveof no one
然后配置文件注释
#slaveof 192.168.249.11 6379
#masterauth 123456
2.其余的slave 如果想该master
修改配置文件 重启即可
slaveof 192.168.249.11 6379
masterauth 123456
5.redis哨兵模式
###
5.1 redis-6379
bind 0.0.0.0protected-mode yesport 6379tcp-backlog 511timeout 2tcp-keepalive 600daemonize nosupervised nopidfile /var/run/redis_6379.pidlogfile "/data/redis/3.2.2/log/6379.log"loglevel noticedatabases 16save 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump-6379rdb dir /data/redis/3.2.2/rdb/slave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100appendonly noappendfilename "appendonly.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size -2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yesrequirepass 123456#slaveof 192.168.249.11 6379#masterauth 123456
52. redis-6380.conf
bind 0.0.0.0protected-mode yesport 6380tcp-backlog 511timeout 2tcp-keepalive 600daemonize nosupervised nopidfile /var/run/redis_6380.pidlogfile "/data/redis/3.2.2/log/6380.log"loglevel noticedatabases 16save 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump-6380rdb dir /data/redis/3.2.2/rdb/slave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100appendonly noappendfilename "appendonly.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size -2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yesrequirepass 123456slaveof 192.168.249.12 6379masterauth 123456
5.3 redis-6381.conf
bind 0.0.0.0protected-mode yesport 6381tcp-backlog 511timeout 2tcp-keepalive 600daemonize nosupervised nopidfile /var/run/redis_6381.pidlogfile "/data/redis/3.2.2/log/6381.log"loglevel noticedatabases 16save 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump-6381rdb dir /data/redis/3.2.2/rdb/slave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100appendonly noappendfilename "appendonly.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size -2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yesrequirepass 123456slaveof 192.168.249.12 6379masterauth 123456
5.4 启动所有redis
/data/redis/3.2.2/bin/redis-server /data/redis/3.2.2/conf/redis-6379.conf &/data/redis/3.2.2/bin/redis-server /data/redis/3.2.2/conf/redis-6380.conf &/data/redis/3.2.2/bin/redis-server /data/redis/3.2.2/conf/redis-6381.conf &
5.5.redis-sentinel 26379配置文件
自己启动只有这些 启动后系统默认会添加一点
daemonize yesport 26379protected-mode nologfile "/data/redis/3.2.2/log/sentinel_26379.log"# Generated by CONFIG REWRITEdir "/data/redis/3.2.2/bin"sentinel myid 5f28ad1de807c463582fe3700be9abca89a99300sentinel monitor mymaster 192.168.249.12 6379 2sentinel auth-pass mymaster 123456
5.5.redis-sentinel 26380配置文件
daemonize yesport 26380protected-mode nologfile "/data/redis/3.2.2/log/sentinel_26380.log"# Generated by CONFIG REWRITEdir "/data/redis/3.2.2/bin"sentinel myid f14e3790c310759d21ee6328d71f69bab9587ebbsentinel monitor mymaster 192.168.249.12 6379 2sentinel auth-pass mymaster 123456
5.5.redis-sentinel 26381配置文件
daemonize yesport 26381protected-mode nologfile "/data/redis/3.2.2/log/sentinel_26381.log"dir "/data/redis/3.2.2/bin"sentinel myid 9f7b6de975105fa83ff4dc2a5f03407992880fd1sentinel monitor mymaster 192.168.249.12 6379 2# Generated by CONFIG REWRITEsentinel auth-pass mymaster 123456
5.6 查看哨兵模式信息
[root@zabbix-agent bin]# ./redis-cli -h 192.168.249.12 -p 26379192.168.249.12:26379> info # Serverredis_version:3.2.2redis_git_sha1:00000000redis_git_dirty:0redis_build_id:fc9e0ab8193a9c89redis_mode:sentinelos:Linux 3.10.0-327.el7.x86_64 x86_64arch_bits:64multiplexing_api:epollgcc_version:4.8.5process_id:6405run_id:031d3da188d76481ac6fa73b13f50c62b1403ae5tcp_port:26379uptime_in_seconds:1330uptime_in_days:0hz:14lru_clock:431489executable:/data/redis/3.2.2/bin/./redis-sentinelconfig_file:/data/redis/3.2.2/conf/sentinel-26379.conf# Clientsconnected_clients:3client_longest_output_list:0client_biggest_input_buf:0blocked_clients:0# CPUused_cpu_sys:0.57used_cpu_user:1.22used_cpu_sys_children:0.00used_cpu_user_children:0.00# Statstotal_connections_received:5total_commands_processed:3834×××tantaneous_ops_per_sec:2total_net_input_bytes:219128total_net_output_bytes:28649×××tantaneous_input_kbps:0.13×××tantaneous_output_kbps:0.02rejected_connections:0sync_full:0sync_partial_ok:0sync_partial_err:0expired_keys:0evicted_keys:0keyspace_hits:0keyspace_misses:0pubsub_channels:0pubsub_patterns:0latest_fork_usec:0migrate_cached_sockets:0# Sentinelsentinel_masters:1sentinel_tilt:0sentinel_running_scripts:0sentinel_scripts_queue_length:0sentinel_simulate_failure_flags:0master0:name=mymaster,status=ok,address=192.168.249.12:6379,slaves=2,sentinels=3192.168.249.12:26379>