《實戰錄|Redis的主從服務器搭建》要點:
本文介紹了實戰錄|Redis的主從服務器搭建,希望對您有用。如果有疑問,可以聯系我們。
《實戰錄》導語
云端衛士《實戰錄》欄目定期會向粉絲朋友們分享一些在開發運維中的經驗和技巧,希望對于關注我們的朋友有所裨益.本期分享人為云端衛士平安平臺工程師田全磊,將帶來Redis的主從服務器搭建.
Redis是一個簡單快捷的key-value存儲系統.它提供了豐富的數據存儲結構,包含 lists, sets, ordered sets 以及 hashes ,當然還有和Memcached一樣的 strings結構.同時Redis提供還對這些數據結構的豐富操作.
Redis尖兵模式介紹
Redis 的 Sentinel 功效用于管理多個 Redis 服務器,它主要提供了監控,提醒和自動故障遷移的功效.
1.監控(Monitoring): Sentinel 會賡續地檢查你的主服務器和從服務器是否運作正常.
2.提醒(Notification): 當被監控的某個 Redis 服務器呈現問題時, Sentinel 可以通過 API 向管理員或者其他應用程序發送通知.
3.自動故障遷移(Automatic failover): 當一個主服務器不克不及正常工作時, Sentinel 會開始一次自動故障遷移操作, 它會將失效主服務器的其中一個從服務器升級為新的主服務器, 并讓失效主服務器的其他從服務器改為復制新的主服務器; 當客戶端試圖連接失效的主服務器時, 集群也會向客戶端返回新主服務器的地址, 使得集群可以使用新主服務器代替失效服務器.
安裝
下載redis-2.8.19.tar.gz
解壓tar zxf redis-2.8.19.tar.gz
安裝cd redis-2.8.19
make && make install
每臺機械上都同樣安裝redis
Redis主從情況搭建
一主:192.168.24.147
兩從:192.168.24.148,192.168.24.149
(1)主192.168.24.147設置裝備擺設
目次:conf/redis_6379.conf
啟動敕令 src/redis-server conf/redis_6379.conf
daemonize yes
pidfile /export/Data/redis_pid/redis_6379.pid
port 6379
# tcp-backlog 511
timeout 300
tcp-keepalive 0
loglevel notice
logfile /export/Logs/redis/redis_6379.log
databases 16
stop-writes-on-bgsave-error yes
rdbcompression yes
dbfilename 6379.rdb
dir /export/Data/redis_data/6379
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
repl-backlog-size 128mb
maxmemory 2g
appendonly no
appendfilename 6379.aof
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 1024
# notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
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 512mb 256mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
rename-co妹妹and keys jkeys
(2)從192.168.24.148設置裝備擺設
目次:conf/redis_6379.conf
啟動敕令 src/redis-server conf/redis_6379.conf
daemonize yes
slaveof 192.168.24.147 6379
pidfile /export/Data/redis_pid/redis_6379.pid
port 6379
# tcp-backlog 511
timeout 300
tcp-keepalive 0
loglevel notice
logfile /export/Logs/redis/redis_6379.log
databases 16
stop-writes-on-bgsave-error yes
rdbcompression yes
dbfilename 6379.rdb
dir /export/Data/redis_data/6379
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
repl-backlog-size 128mb
maxmemory 2g
appendonly no
appendfilename 6379.aof
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 1024
# notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
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 512mb 256mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
rename-co妹妹and keys jkeys
(3)從192.168.24.149設置裝備擺設
目次:conf/redis_6379.conf
啟動敕令 src/redis-server conf/redis_6379.conf
daemonize yes
slaveof 192.168.24.147 6379
pidfile /export/Data/redis_pid/redis_6379.pid
port 6379
# tcp-backlog 511
timeout 300
tcp-keepalive 0
loglevel notice
logfile /export/Logs/redis/redis_6379.log
databases 16
stop-writes-on-bgsave-error yes
rdbcompression yes
dbfilename 6379.rdb
dir /export/Data/redis_data/6379
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
repl-backlog-size 128mb
maxmemory 2g
appendonly no
appendfilename 6379.aof
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 1024
# notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
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 512mb 256mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
rename-co妹妹and keys jkeys
歡迎參與《實戰錄|Redis的主從服務器搭建》討論,分享您的想法,維易PHP學院為您提供專業教程。
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/9614.html