Skip to content

ashraf-s9s/mysqlchk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 

Repository files navigation

mysqlchk

Based on ClusterControl's mysqlchk script but built for MySQL Replication. It detects the MySQL replication role on the database node as per below:

  • if master (read_only = OFF),

  • return 'MySQL master is running.'

  • if slave (Slave_IO_Running = Yes AND Slave_SQL_Running = Yes AND (Seconds_Behind_Master = 0 OR Seconds_Behind_Master < SLAVE_LAG_LIMIT))

  • return 'MySQL slave is running. (slave lag: 0)'

  • else

  • return 'MySQL is *down*'

How to use

  1. Deploy or add existing MySQL Replication setup into ClusterControl

  2. Install HAProxy on the your selected node. ClusterControl will install the default mysqlchk that need to be replaced with this one on each of the database node. By default, it's located under /usr/local/sbin/mysqlchk

  3. Grab the file from this repo and replace it.

  4. Update require information (SLAVE_LAG_LIMIT is in seconds):

SLAVE_LAG_LIMIT=5
MYSQL_HOST="localhost"
MYSQL_PORT="3306"
MYSQL_USERNAME='root'
MYSQL_PASSWORD='password'
  1. You are good to go. Now ensure in HAProxy you have 2 listeners (3307 for write, 3308 for read) and use option tcp-check & tcp-check expect to distinguish master/slave similar to example below:
listen  haproxy_192.168.55.110_3307_write
        bind *:3307
        mode tcp
        timeout client  10800s
        timeout server  10800s
        balance leastconn
        option tcp-check
        tcp-check expect string MySQL\ master
        option allbackups
        default-server port 9200 inter 2s downinter 5s rise 3 fall 2 slowstart 60s maxconn 64 maxqueue 128 weight 100
        server 192.168.55.111 192.168.55.111:3306 check
        server 192.168.55.112 192.168.55.112:3306 check
        server 192.168.55.113 192.168.55.113:3306 check

listen  haproxy_192.168.55.110_3308_read
        bind *:3308
        mode tcp
        timeout client  10800s
        timeout server  10800s
        balance leastconn
        option tcp-check
        tcp-check expect string is\ running.
        option allbackups
        default-server port 9200 inter 2s downinter 5s rise 3 fall 2 slowstart 60s maxconn 64 maxqueue 128 weight 100
        server 192.168.55.111 192.168.55.111:3306 check
        server 192.168.55.112 192.168.55.112:3306 check
        server 192.168.55.113 192.168.55.113:3306 check

About

HAproxy health check script for MySQL Replication

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages