Redis 主從模式
阿新 • • 發佈:2017-11-20
commit checksum http max live name usr depth ise
系統: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 主從模式