Haproxy+Keepalived+MySQL Cluster实现负载均衡

由于在生产环境使用了mysqlcluster,需要实现高可用负载均衡,选用keepalived+haproxy来实现。

[b]1.Mysql Cluster安装[/b]

参考 CentOS 6.3 安装 mysql-cluster-gpl-7.4.7
http://maosheng.iteye.com/blog/2249106

[b]2.haproxy安装(haproxy-1.3.15.10)[/b]

参考CentOS 6.3 安装 HAProxy
http://maosheng.iteye.com/blog/2256676

[b]haproxy配置文件:[/b]

# vi /etc/haproxy/haproxy.conf

global
maxconn 4096
pidfile /var/run/haproxy.pid
daemon
nbproc 1
defaults
log global
mode http
retries 3
option redispatch
option httplog
option httpclose
option abortonclose
maxconn 4096
timeout connect 50000
timeout client 50000
timeout server 50000

listen mysql_proxy
bind 172.16.10.75:3366
mode tcp
option tcpka
option httpchk
balance roundrobin
server mysqldb1 172.16.10.70:3306 weight 1
server mysqldb1 172.16.10.71:3306 weight 1
listen stats
bind 172.16.10.75:8888
mode http
option httpclose
option httplog
stats refresh 5s
balance roundrobin
stats uri /
stats realm Haproxy\ Statistics
stats auth admin:admin

[b]3.keepalived安装[/b]

参考CentOS 6.3 安装 Keepalived
http://maosheng.iteye.com/blog/2238747

参考Keepalived+Nginx 实现双机热备
http://maosheng.iteye.com/blog/2242594

[b]keepalived配置文件:[/b]

[b]Master:[/b]

# vi /etc/keepalived/keepalived.conf

! Configuration File for keepalived


global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id HAProxy_DEVEL_1
}

vrrp_script chk_http_port {
script "/etc/keepalived/check_haproxy.sh"
interval 2
weight 2
}

vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 101
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}

track_script {
chk_http_port
}

virtual_ipaddress {
172.16.10.75
}
}

[b]Backup:[/b]

# vi /etc/keepalived/keepalived.conf

! Configuration File for keepalived


global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id HAProxy_DEVEL_2
}

vrrp_script chk_http_port {
script "/etc/keepalived/check_haproxy.sh"
interval 2
weight 2
}

vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}

track_script {
chk_http_port
}

virtual_ipaddress {
172.16.10.75
}
}

[b]配置侦测haproxy状态脚本:[/b]

# vi /etc/keepalived/check_haproxy.sh

#!/bin/bash
A=`ps -C haproxy --no-header |wc -l`
if [ $A -eq 0 ];then
/usr/local/haproxy-1.3.15.10/sbin/haproxy -f /etc/haproxy/haproxy.conf
sleep 3

if [ `ps -C haproxy --no-header |wc -l` -eq 0 ];then
/etc/init.d/keepalived stop
fi
fi


[b]4.haproxy检查[/b]

http://172.16.10.75:8888/


[img]http://dl2.iteye.com/upload/attachment/0113/1907/fea3556e-9ba3-3cc6-8057-27d37b70faf0.png[/img]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值