B7
Haproxy 四层负载均衡拓扑:
app---->mysql_master(write)
|
haproxy(read)
|
mysql_slave*N
一 Haproxy 部分
1 haproxy 代码
[*]listenbbs_slave 10.0.100.82:3306
[*] mode tcp #配置TCP模式
[*] maxconn 2000
[*] balance roundrobin
[*] #option httpchk OPTIONS * HTTP/1.1\r\nHost:\ www
[*] serverslave01 10.0.100.75:3306 check port 9120 inter 5000 rise 3 fall 3 weight 3
[*] serverslave02 10.0.100.76:3306 check port 9120 inter 5000 rise 3 fall 3 weight 3
[*] srvtimeout 20000
二 Mysql 部分
2.1 mysql replication 监控脚本
[*]cat /usr/local/bin/mysqlrep_status.sh
[*]#!/bin/bash
[*]#
[*]# /usr/local/bin/mysqlrep_status.sh
[*]#
[*]# This script checks if a mysql server is healthy running on localhost. It will
[*]# return:
[*]#
[*]# "HTTP/1.x 200 OK\r" (if mysql is running smoothly)
[*]#
[*]# – OR –
[*]#
[*]# "HTTP/1.x 503 Internal Server Error\r" (else)
[*]#
[*]
[*]mysql=/usr/local/bin/mysql
[*]mysql_host="localhost"
[*]mysql_port="3306"
[*]mysql_username="root"
[*]mysql_password="dongnan"
[*]#
[*]$mysql -u${mysql_username} -p${mysql_password} -e "show full processlist;" >/tmp/processlist.txt
[*]$mysql -u${mysql_username} -p${mysql_password} -e "show slave status\G;" >/tmp/rep.txt
[*]iostat=`awk '/Slave_IO_Running/ {print $2}' /tmp/rep.txt`
[*]sqlstat=`awk '/Slave_SQL_Running/ {print $2}' /tmp/rep.txt`
[*]
[*]if [ "$iostat" = "Yes" ] && [ "$sqlstat" = "Yes" ];then
[*] /bin/echo -e "HTTP/1.1 200 OK\r\n"
[*]else
[*] /bin/echo -e "HTTP/1.1 503 Service Unavailable\r\n"
[*]fi
2.2 配置 xinetd
//定义服务,服务名一定要在 /etc/services列出
[*]tail -n1 /etc/services
mysql_rep_check 9120/tcp
//定义 super daemon
[*]cat >> /etc/xinetd.d/mysql_rep_check
页:
[1]