一肄渗、環(huán)境
角色 | 主機(jī)名 | ip | 系統(tǒng) |
---|---|---|---|
Haproxy | haproxy | 192.168.100.100 | CentOS 7 |
Slave | slave01 | 192.168.100.101 | CentOS 7 |
Slave | slave02 | 192.168.100.102 | CentOS 7 |
二、準(zhǔn)備
安裝好兩臺(tái)MySQL
, 對(duì)外監(jiān)聽(tīng)在3306端口,并在iptables上對(duì)haproxy
放行3306
端口。并在MySQL
上創(chuàng)建賬號(hào):
MySQL> grant all on *.* to 'haproxy'@'192.168.100.100' identified by '123456';
MySQL> flush privileges;
三蛀骇、配置haproxy
-
安裝haproxy
$ yum install -y haproxy
-
修改haproxy配置文件
/etc/haproxy/haproxy.cfg
, 內(nèi)容如下global log 127.0.0.1 local2 chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 4000 user haproxy group haproxy daemon stats socket /var/lib/haproxy/stats defaults mode tcp log global option dontlognull timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout check 10s maxconn 3000 listen MySQL bind 0.0.0.0:3306 mode tcp option tcplog timeout connect 300ms server slave01 192.168.100.101:3306 check port 3306 inter 200 rise 3 fall 2 server slave02 192.168.100.102:3306 check port 3306 inter 200 rise 3 fall 2
-
日志配置
-
更改rsyslog配置文件
/etc/rsyslog.conf
$ModLoad imudp $UDPServerAddress 127.0.0.1 $UDPServerRun 514 ... local2.* /data/haproxy/haproxy.log ...
-
更改
/etc/sysconfig/rsyslog
SYSLOGD_OPTIONS="-r"
-
重啟rsyslog
$ systemctl restart rsyslog
-
啟動(dòng)Haproxy
$ systemctl start haproxy
結(jié)果
-