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.conf bind 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 123456 set 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 redis root 3336 2633 0 23:38 pts/0 00:00:00 ./redis-server 0.0.0.0:6379 root 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 123456 OK 127.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 OK 127.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.0 protected-mode yes port 6379 tcp-backlog 511 timeout 2 tcp-keepalive 600 daemonize no supervised no pidfile /var/run/redis_6379.pid logfile "/data/redis/3.2.2/log/6379.log" loglevel notice databases 16 save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump-6379rdb dir /data/redis/3.2.2/rdb/ 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 no 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 requirepass 123456 #slaveof 192.168.249.11 6379 #masterauth 123456
52. redis-6380.conf
bind 0.0.0.0 protected-mode yes port 6380 tcp-backlog 511 timeout 2 tcp-keepalive 600 daemonize no supervised no pidfile /var/run/redis_6380.pid logfile "/data/redis/3.2.2/log/6380.log" loglevel notice databases 16 save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump-6380rdb dir /data/redis/3.2.2/rdb/ 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 no 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 requirepass 123456 slaveof 192.168.249.12 6379 masterauth 123456
5.3 redis-6381.conf
bind 0.0.0.0 protected-mode yes port 6381 tcp-backlog 511 timeout 2 tcp-keepalive 600 daemonize no supervised no pidfile /var/run/redis_6381.pid logfile "/data/redis/3.2.2/log/6381.log" loglevel notice databases 16 save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump-6381rdb dir /data/redis/3.2.2/rdb/ 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 no 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 requirepass 123456 slaveof 192.168.249.12 6379 masterauth 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 yes port 26379 protected-mode no logfile "/data/redis/3.2.2/log/sentinel_26379.log" # Generated by CONFIG REWRITE dir "/data/redis/3.2.2/bin" sentinel myid 5f28ad1de807c463582fe3700be9abca89a99300 sentinel monitor mymaster 192.168.249.12 6379 2 sentinel auth-pass mymaster 123456
5.5.redis-sentinel 26380配置文件
daemonize yes port 26380 protected-mode no logfile "/data/redis/3.2.2/log/sentinel_26380.log" # Generated by CONFIG REWRITE dir "/data/redis/3.2.2/bin" sentinel myid f14e3790c310759d21ee6328d71f69bab9587ebb sentinel monitor mymaster 192.168.249.12 6379 2 sentinel auth-pass mymaster 123456
5.5.redis-sentinel 26381配置文件
daemonize yes port 26381 protected-mode no logfile "/data/redis/3.2.2/log/sentinel_26381.log" dir "/data/redis/3.2.2/bin" sentinel myid 9f7b6de975105fa83ff4dc2a5f03407992880fd1 sentinel monitor mymaster 192.168.249.12 6379 2 # Generated by CONFIG REWRITE sentinel auth-pass mymaster 123456
5.6 查看哨兵模式信息
[root@zabbix-agent bin]# ./redis-cli -h 192.168.249.12 -p 26379 192.168.249.12:26379> info # Server redis_version:3.2.2 redis_git_sha1:00000000 redis_git_dirty:0 redis_build_id:fc9e0ab8193a9c89 redis_mode:sentinel os:Linux 3.10.0-327.el7.x86_64 x86_64 arch_bits:64 multiplexing_api:epoll gcc_version:4.8.5 process_id:6405 run_id:031d3da188d76481ac6fa73b13f50c62b1403ae5 tcp_port:26379 uptime_in_seconds:1330 uptime_in_days:0 hz:14 lru_clock:431489 executable:/data/redis/3.2.2/bin/./redis-sentinel config_file:/data/redis/3.2.2/conf/sentinel-26379.conf # Clients connected_clients:3 client_longest_output_list:0 client_biggest_input_buf:0 blocked_clients:0 # CPU used_cpu_sys:0.57 used_cpu_user:1.22 used_cpu_sys_children:0.00 used_cpu_user_children:0.00 # Stats total_connections_received:5 total_commands_processed:3834 ×××tantaneous_ops_per_sec:2 total_net_input_bytes:219128 total_net_output_bytes:28649 ×××tantaneous_input_kbps:0.13 ×××tantaneous_output_kbps:0.02 rejected_connections:0 sync_full:0 sync_partial_ok:0 sync_partial_err:0 expired_keys:0 evicted_keys:0 keyspace_hits:0 keyspace_misses:0 pubsub_channels:0 pubsub_patterns:0 latest_fork_usec:0 migrate_cached_sockets:0 # Sentinel sentinel_masters:1 sentinel_tilt:0 sentinel_running_scripts:0 sentinel_scripts_queue_length:0 sentinel_simulate_failure_flags:0 master0:name=mymaster,status=ok,address=192.168.249.12:6379,slaves=2,sentinels=3 192.168.249.12:26379>
转载于:https://blog.51cto.com/wsxxsl/2409653