Skip to content

Instantly share code, notes, and snippets.

@boardstretcher
Last active December 22, 2015 20:19
Show Gist options
  • Save boardstretcher/6525924 to your computer and use it in GitHub Desktop.
Save boardstretcher/6525924 to your computer and use it in GitHub Desktop.
install and set up latest haproxy for four nodes
# scientific linux 6.4
# lb node - no sql on this node
# sql nodes: db1, db2, db3, db4
yum -y update
yum -y install gcc
useradd haproxy
wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.24.tar.gz
tar zxvf haproxy-1.4.24.tar.gz
cd haproxy-1.4.24
make install
mkdir -v /etc/haproxy
tee /etc/haproxy/haproxy.cfg <<EOF
global
log 127.0.0.1 local0
maxconn 4096
user haproxy
group haproxy
daemon
defaults
log global
mode tcp
option tcplog
option dontlognull
retries 3
option redispatch
maxconn 2000
contimeout 3600000
clitimeout 3600000
srvtimeout 3600000
stats enable
stats scope .
frontend mysql_cluster
bind mysql_lb:3306
default_backend mysql_cluster
backend mysql_cluster
mode tcp
balance roundrobin
option mysql-check user haproxyUser
server db1 db1:3306 check
server db2 db2:3306 check
server db3 db3:3306 check
server db4 db4:3306 check
listen stats *:80
mode http
option httpclose
balance roundrobin
stats uri /
stats realm Haproxy\ Statistics
stats auth admin:admin
EOF
mysql -hdb1-uroot -p -e "GRANT ALL ON *.* to 'haproxyUser'@'%' IDENTIFIED BY '';"
mysql -hdb2-uroot -p -e "GRANT ALL ON *.* to 'haproxyUser'@'%' IDENTIFIED BY '';"
mysql -hdb3-uroot -p -e "GRANT ALL ON *.* to 'haproxyUser'@'%' IDENTIFIED BY '';"
mysql -hdb4-uroot -p -e "GRANT ALL ON *.* to 'haproxyUser'@'%' IDENTIFIED BY '';"
/usr/local/sbin/haproxy -f /etc/haproxy/haproxy.cfg -V
# be sure to modify iptables accordingly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment