利用redis-sentinel+keepalived實現redis高可用
目標、需求:
方案概述:
方案原理:
連線圖
主機標識 | Redis1 | Redis2 | Redis3 |
IP地址 | 192.168.1.241 | 192.168.1.242 | 192.168.1.243 |
預設配置 |
redis-server master keepalived master |
redis-server slave keepalived backup |
redis-server slave keepalived backup |
VIP |
配置步驟:
-
安裝:安裝redis-server、redis-sentinel、keepalived
-
配置:配置Redis1、Redis2、Redis3,主要是編輯各個服務的配置檔案
-
啟動:先啟動redis-server、再啟動redis-sentinel、最後自動keepalived
-
驗證:模擬一臺主機宕機,主機網路中斷,redis-server、redis-sentinel、keepalived三個服務任何一個發生故障的情況。
# http://download.redis.io/redis-stable.tar.gz wget -c http://download.redis.io/releases/redis-3.0.7.tar.gz tar zxf redis-3.0.7.tar.gz cd redis-3.0.7 make cd \cp redis-3.0.7/src/redis-benchmark /usr/local/sbin/ \cp redis-3.0.7/src/redis-check-aof /usr/local/sbin/ \cp redis-3.0.7/src/redis-check-dump /usr/local/sbin/ \cp redis-3.0.7/src/redis-cli /usr/local/sbin/ \cp redis-3.0.7/src/redis-sentinel /usr/local/sbin/ \cp redis-3.0.7/src/redis-server /usr/local/sbin/ mkdir /etc/redis mkdir -p /data/redis-6379/
# http://www.keepalived.org/documentation.html wget -c http://www.keepalived.org/software/keepalived-1.2.19.tar.gz tar zxf keepalived-1.2.19.tar.gz cd keepalived-1.2.19 ./configure --prefix=/usr/local/keepalived make make install cp /usr/local/keepalived/sbin/keepalived /usr/sbin/ cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/ cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/ mkdir /etc/keepalived
cat >/etc/redis/sentinel.conf<<eof port 26379 dir /tmp sentinel monitor mymaster 192.168.1.241 6379 2 sentinel down-after-milliseconds mymaster 30000 sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 180000 eof
cat > /etc/redis/redis-6379.conf <<eof # maxmemory 268435456 maxmemory 256mb daemonize yes pidfile /data/redis-6379/redis-6379.pid port 6379 bind 0.0.0.0 tcp-backlog 511 timeout 0 tcp-keepalive 0 loglevel notice logfile /data/redis-6379/redis.log databases 16 save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dumpredis-6379.rdb dir /data/redis-6379 slave-serve-stale-data yes slave-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 # repl-ping-slave-period 10 # repl-timeout 60 repl-disable-tcp-nodelay no # repl-backlog-size 1mb # repl-backlog-ttl 3600 slave-priority 100 # min-slaves-to-write 3 # min-slaves-max-lag 10 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-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 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10 aof-rewrite-incremental-fsync yes eof
cat > /etc/redis/redis-6379.conf <<eof slaveof 192.168.1.241 6379 # maxmemory 268435456 maxmemory 256mb daemonize yes pidfile /data/redis-6379/redis-6379.pid port 6379 bind 0.0.0.0 tcp-backlog 511 timeout 0 tcp-keepalive 0 loglevel notice logfile /data/redis-6379/redis.log databases 16 save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dumpredis-6379.rdb dir /data/redis-6379 slave-serve-stale-data yes slave-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 # repl-ping-slave-period 10 # repl-timeout 60 repl-disable-tcp-nodelay no # repl-backlog-size 1mb # repl-backlog-ttl 3600 slave-priority 100 # min-slaves-to-write 3 # min-slaves-max-lag 10 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-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 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10 aof-rewrite-incremental-fsync yes eof
! Configuration File for keepalived global_defs { notification_email { [email protected] } notification_email_from [email protected] smtp_server 127.0.0.1 smtp_connect_timeout 10 router_id keepalivedha_1 } vrrp_script chk_http_port { script "redis-cli info | grep role:master >/dev/null 2>&1" interval 1 timeout 2 fall 2 rise 1 } vrrp_sync_group VG_1 { group { VI_1 } } vrrp_instance VI_1 { state BACKUP interface eth1 #use_vmac keepalived #vmac_xmit_base mcast_src_ip 192.168.1.241 smtp_alert virtual_router_id 20 priority 100 advert_int 1 authentication { auth_type PASS auth_pass password } virtual_ipaddress { 192.168.1.245 } track_script { chk_http_port } }
! Configuration File for keepalived global_defs { notification_email { [email protected] } notification_email_from [email protected] smtp_server 127.0.0.1 smtp_connect_timeout 10 router_id keepalivedha_2 } vrrp_script chk_http_port { script "redis-cli info | grep role:master >/dev/null 2>&1" interval 1 timeout 2 fall 2 rise 1 } vrrp_sync_group VG_1 { group { VI_1 } } vrrp_instance VI_1 { state BACKUP interface eth2 #use_vmac keepalived #vmac_xmit_base mcast_src_ip 192.168.1.242 smtp_alert virtual_router_id 20 priority 99 advert_int 1 authentication { auth_type PASS auth_pass password } virtual_ipaddress { 192.168.1.245 } track_script { chk_http_port } nopreempt }
! Configuration File for keepalived global_defs { notification_email { [email protected] } notification_email_from [email protected] smtp_server 127.0.0.1 smtp_connect_timeout 10 router_id keepalivedha_3 } vrrp_script chk_http_port { script "redis-cli info | grep role:master >/dev/null 2>&1" interval 1 timeout 2 fall 2 rise 1 } vrrp_sync_group VG_1 { group { VI_1 } } vrrp_instance VI_1 { state BACKUP interface eth1 #use_vmac keepalived #vmac_xmit_base mcast_src_ip 192.168.1.243 smtp_alert virtual_router_id 20 priority 98 advert_int 1 authentication { auth_type PASS auth_pass password } virtual_ipaddress { 192.168.1.245 } track_script { chk_http_port } nopreempt }
redis-server /etc/redis/redis-6379.conf tail /data/redis-6379/redis.log
redis-sentinel /etc/redis/redis-sentinel.conf tail /data/redis-6379/redis-sentinel.log
service keepalived start tail /var/log/messages
測試
故障切換的步驟
參考
相關推薦
利用redis-sentinel+keepalived實現redis高可用
目標、需求: 為上層應用提供高可靠、低延遲、低(無限接近0)資料損失的Redis快取服務 方案概述: 採用同一網路內的三臺主機(可以是物理主機、虛擬機器或docker容器),要求三臺主機之間都能相互訪問,每一臺主機上都安裝redis-server、redis-sen
redis-sentinel主從復制高可用
一分鐘 for 重寫 aof重寫 dataset 方法 解決方案 返回結果 方式 一,Redis-Sentinel介紹 Redis-Sentinel是redis官方推薦的高可用性解決方案,當用redis作master-slave的高可用時,如果master本身
LVS結合Redis Sentinel哨兵模式的高可用設計
Redis哨兵模式配置與原理不在這裡敘述,網上已經有很多文章可供參考。 下面給出哨兵模式Java客戶端的一段程式碼。 JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); jedi
Nginx+Keepalived實現站點高可用
不存在 個人 全局配置 狀態 操作 介紹 轉發 所在 端口 公司內部 OA 系統要做線上高可用,避免單點故障,所以計劃使用2臺虛擬機通過 Keepalived 工具來實現 nginx 的高可用(High Avaiability),達到一臺nginx入口服務器宕機,另一臺備機
keepalived實現服務高可用
keepalived高可用環境說明 系統: centos 7.4 軟件: keepalived: 1.3.5 nginx: 1.12.2 tcpdump工具 主機:192.168.9.222 192.168.9.223 vip地址: 192.168.9.151 kee
MySQL主主復制+LVS+Keepalived實現MySQL高可用性
reports with server 好的 進入 ring BE failed remote MySQL復制能夠保證數據的冗余的同時可以做讀寫分離來分擔系統壓力,如果是主主復制還可以很好的避免主節點的單點故障。但是MySQL主主復制存在一些問題無法滿足我們的實際需要:未提
inotify+rsync+mysql主主復制+keepalived實現zabbix高可用
lease 包含 ati weight ebp nag fig 數據信息 replicat 思路:主備機通過inotify+rsync實現文件同步,通過mysql主主復制實現數據同步,同一時刻只有一臺服務器能對外提供zabbix服務,web端登陸虛ip訪問,被監控主機通過配
Nginx+Keepalived實現Nginx高可用
itl one 瀏覽器 p地址 存在 interval img title 訪問 在架構設計中,可以利用NGINX的反向代理和負載均衡實現後端應用的高可用性,同時我們還需要考慮Nginx的單點故障。真正做到架構高可用性。主要考慮以下幾點: 1、Nginx服務因為意外
Memcached 主主復制+ Keepalived 實現 Memcached 高可用架構集群
作用 代理 應用 進行 rep 高可用性 val gen backup Memcached +keepalived 高可用集群 Memcached 主主復制這種架構,在程序連接時不知道應該連接哪個主服務器,所以需要在前端增加 VIP 地址,實現高可用架構。這裏用 Keep
keepalived實現nginx高可用,一主一備
ddr cti 文件重命名 實現 usr time deb 安裝 fall keepalived實現nginx高可用(HA) 安裝直接yum安裝就可以,版本可能比官網落後,但是夠用了, yum -y install keepalived 編輯配置文件,默認路徑 /et
linux中keepalived實現nginx高可用配置
linux中keepalived實現nginx高可用配置 安裝keepalived 執行如下命令即可 tar -zxvf keepalived-2.0.8.tar.gz -C /usr/src cd /usr/src/keepalived-2.0.8 sudo apt-get install
配置Keepalived實現MySQL高可用
配置環境 已關閉防火牆、selinux; 伺服器的IP地址及角色如下表: IP地址 伺服器/角色 安裝服務 192.168.91.131 master
利用RHCS套件實現nginx高可用叢集
RHCS 簡介 RHCS即 RedHat Cluster Suite ,中文意思即紅帽叢集套件。 紅帽叢集套件(RedHat Cluter Suite, RHCS)是一套綜合的軟體元件,可以通過在部署時採用不同的配置,以滿足你的對高可用性,負載均衡,可擴充套件性,檔案共享和節約成本的
Nginx + Keepalived 實現服務高可用
這一篇,主要介紹下 Nginx + KeepAlived 如何配置 HA(高可用性”(High Availability)通常來描述一個系統經過專門的設計,從而減少停工時間,而保持其服務的高度可用性)。 在專案部署過程中,代理伺服器 Nginx 要做到線上高可用,避免出現單點故障,
MySQL 主主複製 + LVS + Keepalived 實現 MySQL 高可用性
MySQL複製能夠保證資料的冗餘的同時可以做讀寫分離來分擔系統壓力,如果是主主複製還可以很好的避免主節點的單點故障。但是MySQL主主複製存在一些問題無法滿足我們的實際需要:未提供統一訪問入口來實現負載均衡,如果其中master宕掉的話需要手動切換到另外一個mast
跨叢集服務——如何利用Kubernetes 1.3實現跨區高可用
編者按:這篇文章是關於Kubernetes 1.3新功能的一系列深入文章的一部分。本文是第七篇。使用者使用Kubernetes 對生產環境上的部署進行彈性伸縮,同時我們聽到一個明確的聲音:希望跨區域、跨資料中心、跨叢集和跨雲服務商來部署服務。跨叢集服務能夠分佈在不同的地理位置,使得混合和多雲成為可能,相對於單
MHA+keepalived實現Mysql高可用及讀寫分離
1.準備工作 1.準備機器(5臺) keepalived+mha(2臺): 10.11.13.11 keepalived master及mha管理機公用 10.11.13.12 keepalived slave 10.11.13.241 keepalived vip 10.11.13.2
keepalived實現mycat高可用問題排查;道路坎坷,布滿荊棘,定讓你大吃一驚!
查詢信息 情況 sbin 使用 str 說明 pen at命令 搶占 前言 開心一刻 醫院裏,一母親帶著小女孩打針。小女孩:“媽媽我不想打針,疼!”媽媽:“寶貝兒聽話,這裏這麽多護士阿姨,咱們找個打針不疼的。”
利用QJM和zookeeper實現HDFS高可用
為防止單點故障,在hadoop2.X中通常由兩個NameNode組成,一個處於active狀態(皇帝),另一個處於standby狀態(太子)。Active NameNode負責和客戶端的交流,而Standby NameNode則不對外提供服務,僅同步active nameno
keepalived實現nginx高可用
alived default req mib 5.1 nop router his rep keepalived實現nginx高可用 1、環境說明 IP 服務 作用 192.168.1.101 nginx + keepalived master 192.1