Redis 主从模式
Posted Weblog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Redis 主从模式相关的知识,希望对你有一定的参考价值。
系统:Centos6.6x64
安装目录:/usr/local/
主:192.168.100.103
从:192.168.100.104
1,下载安装: 安装依赖: # yum install gcc tcl ruby -y # wget http://download.redis.io/releases/redis-3.2.4.tar.gz # tar xf redis-3.2.4.tar.gz # mv redis-3.2.4 /opt/redis # cd /opt/redis # make # make test 2,内核修改配置 echo "vm.overcommit_memory=1" >> /etc/sysctl.conf /sbin/sysctl -p 3,iptables端口开发 selinux关闭设置: # cat /etc/sysconfig/iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT 4,创建 数据 日志目录 mkdir -p redis/{log,data}
5,redis 主从配置
主服务:192.168.100.103 # cat redis.conf bind 192.168.100.103 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 /opt/redis/log/redis.log 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 /opt/redis/data requirepass passwd 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
从服务:192.168.100.104 # cat redis.conf bind 192.168.100.104 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 /opt/redis/log/redis.log 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 /opt/redis/data slaveof 192.168.100.103 6379 masterauth passwd 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
6,启动测试:
# /opt/redis# nohup src/redis-server redis.conf & # ps-ef|grep redis # /usr/local/redis/bin/redis-cli ping
7,测试:
主服务103上执行创建: # /usr/local/redis/bin/redis-cli -h 192.168.100.103 -a passwd set test 123456 从服务104上执行查看: # /usr/local/redis/bin/redis-cli -h 192.168.100.104 get test
性能测试 # /usr/local/redis/bin/redis-benchmark 关闭服务 # /usr/local/redis/bin/redis-cli -p 6379 shutdown 强制刷新数据到磁盘【Redis默认是异步写入磁盘的】 # /usr/local/redis/bin/redis-cli -p 6379 save
以上是关于Redis 主从模式的主要内容,如果未能解决你的问题,请参考以下文章