Keepalived叢集軟體高階使用(工作原理和狀態通知)
1、介紹
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
示例: ! Configuration File for keepalived global_defs { notification_email { example@163.com } notification_email_from example@example.com smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id MYSQL_HA } vrrp_instance VI_1 { state BACKUP interface eth1 virtual_router_id 50 nopreempt #當主down時,備接管,主恢復,不自動接管 priority 100 advert_int 1 authentication { auth_type PASS ahth_pass 123 } virtual_ipaddress { 192.168.1.200 #虛擬IP地址 } } virtual_server 192.168.1.200 3306 { delay_loop 6 # lb_algo rr # lb_kind NAT persistence_timeout 50 protocol TCP real_server 192.168.1.201 3306 { #監控本機3306埠 weight 1 notify_down /etc/keepalived/kill_keepalived .sh #檢測3306埠為down狀態就執行此指令碼(只有keepalived關閉,VIP才漂移 ) TCP_CHECK { #健康狀態檢測方式,可針對業務需求調整(TTP_GET|SSL_GET|TCP_CHECK|SMTP_CHECK|MISC_CHECK) connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
示例: ! Configuration File for keepalived global_defs { notification_email { example@163.com } notification_email_from example@example.com smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id MYSQL_HA } vrrp_script check_nginx { script /etc/keepalived/check_nginx .sh #檢測指令碼 interval 2 #執行間隔時間 } vrrp_instance VI_1 { state BACKUP interface eth1 virtual_router_id 50 nopreempt #當主down時,備接管,主恢復,不自動接管 priority 100 advert_int 1 authentication { auth_type PASS ahth_pass 123 } virtual_ipaddress { 192.168.1.200 #虛擬IP地址 } track_script { #在例項中引用指令碼 check_nginx } } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
指令碼內容如下: # cat /etc/keepalived/check_nginx.sh Count1=` netstat -antp | grep - v grep | grep nginx | wc -l` if [ $Count1 - eq 0 ]; then /usr/local/nginx/sbin/nginx sleep 2 Count2=` netstat -antp | grep - v grep | grep nginx | wc -l` if [ $Count2 - eq 0 ]; then service keepalived stop else exit 0 fi else exit 0 fi |
1
2
3
4
5
6
7
8
9
10
11
12
|
HTTP_GET或SSL_GET { url { path /index .html #檢測url,可寫多個 digest 24326582a86bee478bac72d5af25089e #檢測效驗碼 #digest效驗碼獲取方法:genhash -s IP -p 80 -u http://IP/index.html status_code 200 #檢測返回http狀態碼 } connect_port 80 #連線埠 connect_timeout 3 #連線超時時間 nb_get_retry 3 #重試次數 delay_before_retry 2 #連線間隔時間 } |
1
2
3
4
5
6
|
TCP_CHECK { connect_port 80 #健康檢測埠,預設為real_server後跟埠 connect_timeout 5 nb_get_retry 3 delay_before_retry 3 } |
1
2
3
4
5
6
7
8
9
10
|
SMTP_CHECK { #健康檢測郵件伺服器smtp host { connect_ip connect_port } connect_timeout 5 retry 2 delay_before_retry 3 hello_name "mail.domain.com" } |
1
2
3
4
5
|
MISC_CHECK { misc_path /script .sh #指定外部程式或指令碼位置 misc_timeout 3 #執行指令碼超時時間 !misc_dynamic #不動態調整伺服器權重(weight),如果啟用將通過退出狀態碼動態調整real_server權重值 } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
主配置預設郵件通知配置模板如下: global_defs # Block id { notification_email # To: { admin@example1.com ... } # From: from address that will be in header notification_email_from admin@example.com smtp_server 127.0.0.1 # IP smtp_connect_timeout 30 # integer, seconds router_id my_hostname # string identifying the machine, # (doesn't have to be hostname). enable_traps # enable SNMP traps } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
示例: ! Configuration File for keepalived global_defs { notification_email { example@163.com } notification_email_from example@example.com smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id MYSQL_HA } vrrp_instance VI_1 { state BACKUP interface eth1 virtual_router_id 50 nopreempt #當主down時,備接管,主恢復,不自動接管 priority 100 advert_int 1 authentication { auth_type PASS ahth_pass 123 } virtual_ipaddress { 192.168.1.200 } notify_master /etc/keepalived/to_master .sh notify_backup /etc/keepalived/to_backup .sh notify_fault /etc/keepalived/to_fault .sh } virtual_server 192.168.1.200 3306 { delay_loop 6 persistence_timeout 50 protocol TCP real_server 192.168.1.201 3306 { weight 1 notify_up /etc/keepalived/mysql_up .sh notify_down /etc/keepalived/mysql_down .sh TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } } |
1
2
3
4
5
6
|
# cat to_master.sh #!/bin/bash Date=$( date +%F " " %T) IP=$( ifconfig eth0 | grep "inet addr" | cut -d ":" -f2 | awk '{print $1}' ) Mail= "baojingtongzhi@163.com" echo "$Date $IP change to master." |mail -s "Master-Backup Change Status" $Mail |
1
2
3
4
5
6
|
# cat to_backup.sh #!/bin/bash Date=$( date +%F " " %T) IP=$( ifconfig eth0 | grep "inet addr" | cut -d ":" -f2 | awk '{print $1}' ) Mail= "baojingtongzhi@163.com" echo "$Date $IP change to backup." |mail -s "Master-Backup Change Status" $Mail |
1
2
3
4
5
6
|
# cat to_fault.sh #!/bin/bash Date=$( date +%F " " %T) IP=$( ifconfig eth0 | grep "inet addr" | cut -d ":" -f2 | awk '{print $1}' ) Mail= "baojingtongzhi@163.com" echo "$Date $IP change to fault." |mail -s "Master-Backup Change Status" $Mail |
1
2
3
4
5
6
7
|
# cat mysql_down.sh #!/bin/bash Date=$( date +%F " " %T) IP=$( ifconfig eth0 | grep "inet addr" | cut -d ":" -f2 | awk '{print $1}' ) Mail= "baojingtongzhi@163.com" pkill keepalived echo "$Date $IP The mysql service failure,kill keepalived." |mail -s "Master-Backup MySQL Monitor" $Mail |
1
2
3
4
5
6
|
# cat mysql_up.sh #!/bin/bash Date=$( date +%F " " %T) IP=$( ifconfig eth0 | grep "inet addr" | cut -d ":" -f2 | awk '{print $1}' ) Mail= "baojingtongzhi@163.com" echo "$Date $IP The mysql service is recovery." |mail -s "Master-Backup MySQL Monitor" $Mail |
相關文章
- Keepalived 叢集軟體高階使用(工作原理和狀態通知)
- Keepalived高可用叢集工作原理示意圖
- 3.RabbitMQ高階叢集搭建(Haproxy負載均衡、Keepalived高可用)MQ負載
- PostgreSQL repmgr高可用叢集+keepalived高可用SQL
- RabbitMQ和Kafka的高可用叢集原理MQKafka
- LNMP 分散式叢集(六):keepalived 高可用方案LNMP分散式
- 基於 HAProxy + KeepAlived 搭建 RabbitMQ 高可用叢集MQ
- Keepalived+Nginx高可用叢集搭建筆記Nginx筆記
- MySQL叢集搭建(6)-雙主+keepalived高可用MySql
- Haproxy+Keepalived高可用負載均衡叢集負載
- 教你如何用Keepalived和HAproxy配置高可用 Kubernetes 叢集
- RabbitMQ高階指南:從配置、使用到高可用叢集搭MQ
- RabbitMQ高階指南:從配置、使用到高可用叢集搭建MQ
- 搭建高可用kubernetes叢集(keepalived+haproxy)
- Linux 高可用(HA)叢集之keepalived詳解Linux
- 使用Nginx+Keepalived組建高可用負載平衡Web server叢集Nginx負載WebServer
- Oracle叢集軟體管理-新增和刪除叢集節點Oracle
- MySQL主主複製+Keepalived打造高可用MySQL叢集MySql
- Hadoop周邊生態軟體和簡要工作原理(二)薦Hadoop
- Redis 叢集原理與使用Redis
- oracle RAC 診斷叢集狀態命令Oracle
- 高階圖形繪製軟體的原理猜想
- 高可用Mysql架構_Haproxy+keepalived+mycat叢集的配置MySql架構
- mysql主主複製+keepalived 打造高可用mysql叢集薦MySql
- redis通訊與高可用叢集原理Redis
- Android通知之狀態列通知Android
- Nginx + Keepalived 高可用叢集部署Nginx
- LVS+Keepalived高可用負載均衡叢集架構負載架構
- OracleRAC管理 之 叢集狀態&資訊檢視Oracle
- Nginx 高階篇(十一)叢集搭建實戰Nginx
- Elasticsearch高階之-叢集搭建,資料分片Elasticsearch
- redis叢集之主從複製叢集的原理和部署Redis
- 高可用服務之Keepalived郵件通知配置
- Elasticsearch 叢集和索引健康狀態及常見錯誤說明Elasticsearch索引
- 通過keepalived搭建MySQL雙主模式的高可用叢集系統MySql模式
- LVS+keepalived DR模式配置高可用負載均衡叢集模式負載
- 參加NEC卓越軟體的高可用叢集軟體EXPROCESSCLUSTER釋出會記錄
- 小知識:使用oracle使用者檢視RAC叢集資源狀態Oracle