编程知识 cdmana.com

Keepalived health check and dual master MySQL health check script

One 、http Check

HTTP_GET: Working in the second 5 layer , To specify the URL perform http request , Use the result to md5 Encrypt and communicate with the specified md5 Compare values to see if they match , If not, remove it from the server pool ; You can also specify http Return code to judge whether the detection is successful .HTTP_GET You can specify multiple URL Used to detect , This server is easy to use when there are multiple virtual hosts .

1

2

3

4

5

6

7

8

9

10

11

12

13

14

real_server 10.21.10.30 80 {

weight 1

HTTP_GET {

url {

path /keeptest/index`.html`

digest 3b9bc8d36a113971683321ad4fa02daf

}

connect_timeout 10

nb_get_retry 3

delay_before_retry 3

}

}

1

2

# Use command to get URL Of hash

/usr/bin/genhash  -s 10.21.10.30 -p 80 -u /keeptest/index`.html`

Two 、tcp Port check

SSL_GET: With the above HTTP_GET be similar , The difference is just to use SSL Connect

3、 ... and 、tcp Port check

TCP_CHECK: Working in the second 4 layer ,keepalived Initiate a tcp Connection request , If the back end server does not respond or times out , Then the backend will be removed from the server pool .

1

2

3

4

5

6

7

8

9

real_server 172.16.0.66 3306 {

weight 1

TCP_CHECK {

connect_timeout 3

retry 3

delay_before_retry 3

connect_port 3306

}

}

Four 、 Script check

MISC_CHECK: Use scripts to detect , If the script has parameters , You need to put the script and parameters in double quotation marks . The return value of the script should be :             0)   Test successful             1)   Detection failed , Remove... From the server pool             2-255) Test successful ; If there are settings misc_dynamic, The weight is automatically adjusted to   Exit code -2, If the exit code is 200, The weight is automatically adjusted to 198=200-2.

5、 ... and 、 Mail check

SMTP_CHECK: Used to detect the e-mail service smtp Of . I've never used it. I'll search for it myself

keepalive Double main MySQL health examination

1

2

3

4

5

6

7

8

9

10

11

12

13

real_server 172.16.0.66 3306 {

weight 1

TCP_CHECK {

connect_timeout 3

retry 3

delay_before_retry 3

connect_port 3306

}

MISC_CHECK {

misc_path "/etc/keepalived/mysql_check.sh 172.16.0.66"

misc_timeout 3

}

}

mysql_check.sh The contents are as follows

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

#!/bin/bash

if [ $`# -ne 1 ];then`

echo "Error: please use $0 172.16.0.66"

exit 1

else

CHECK_IP=$1

Slave_status=$(mysql -u guoyabin -p`'*' -h $CHECK_IP -e "show slave statusG" | grep -wE 'Slave_SQL_Running|Slave_IO_Running' | awk -F`": " '{print $2}' | wc -l)

Seconds_Behind_Master=$(mysql -u guoyabin -p`'*' -h $CHECK_IP -e "show slave statusG" | grep -w Seconds_Behind_Master | awk -F": "` `'{print $2}')`

if [ ${Slave_status} -`eq 2 ] && [ ${Seconds_Behind_Master} -lt 300 ];`then

exit 0

else

# Call pin asynchronously to send notification . The first time the script used for i in {1..20} Time , Find out keepalive Nail notification is sent every time you check , So only once .

{

message=`"$CHECK_IP Slave_status=$Slave_status Seconds_Behind_Master = $Seconds_Behind_Master"`

curl --connect-timeout 2 "https://oapi.dingtalk.com/robot/send?access_token=**********************************************" ``

-H "Content-Type: application/json" ``

-d '{`"msgtype":` `"text",`

"text"`: {`

"content"`: "'"${message}"'"`

}

}'

} &

exit 1

fi

fi

版权声明
本文为[A Jie]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201225151208605r.html

Scroll to Top