Corosync Pacemaker Haproxy Cluster
Corosync Pacemaker Haproxy Cluster Document.
I have using RHEL6.4 64 Bit Machines
IP 192.168.0.100 Name Node1.example.com
IP 192.168.0.101 Name Node2.example.com
IP 192.168.0.200 (Virtual IP)
1. installing require Packages both Node ( Node1 & Node2 )
# yum install haproxy corosync pacemaker openssh-clients http* -y
# wget -c http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/x86_64/crmsh-2.1-1.6.x86_64.rpm
# wget -c http://pkgs.repoforge.org/pssh/pssh-2.0-1.el6.rf.noarch.rpm
# rpm -ivh pssh-2.0-1.el6.rf.noarch.rpm
# yum install crmsh-2.1-1.6.x86_64.rpm
2. Configure host file both Node ( Node1 & Node2 )
# vim /etc/hosts ( NODE1 Machine)
192.168.0.100 Node1.example.com Node1
192.168.0.101 Node2.example.com Node2
# vim /etc/hosts ( NODE2 Machine )
192.168.0.100 Node1.example.com Node1
192.168.0.101 Node2.example.com Node2
3. Configure httpd for testing both Node ( Node1 & Node2 )
# vim /etc/httpd/conf/httpd.conf ( NODE1 Machine )
Listen 192.168.4.100:8080
ServerName example.com
# cd /var/www/html/
# vim index.html
haproxy NODE1
# /etc/init.d/httpd restart
# vim /etc/httpd/conf/httpd.conf ( NODE2 Machine )
Listen 192.168.4.101:8080
ServerName example.com
# cd /var/www/html/
# vim index.html
haproxy NODE2
# /etc/init.d/httpd restart
4. Configure Haproxy both Node ( Node1 & Node2 Machine )
# cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg-ORG
# vim /etc/haproxy/haproxy.cfg
global
log 172.0.0.1 local2 debug
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4096
user haproxy
group haproxy
daemon
# turn on stats unix socket
stats socket /var/lib/haproxy/stats
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
mode http
log global
option httplog
option dontlognull
# option http-server-close
option forwardfor
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
listen Haproxy-APP 192.168.0.200:80 (Vertual IP)
balance roundrobin
option httpclose
# option forwardfor
option forwardfor header X-Real-IP
server APPSERVER1 192.168.0.100:8080 check (Machine IP NODE1)
server APPSERVER2 192.168.0.101:8080 check (Machine IP NODE2)
listen admin
bind *:5050
stats enable
stats realm Haproxy\ Statistics
stats uri /
stats auth admin:example@123
# scp /etc/haproxy/haproxy.cfg 192.168.0.101:/etc/haproxy/haproxy.cfg
# cp /etc/corosync/corosync.conf.example /etc/corosync/corosync.conf both Node ( Node1 & Node2 Machine )
# corosync-keygen
Corosync Cluster Engine Authentication key generator.
Gathering 1024 bits for key from /dev/random.
Press keys on your keyboard to generate entropy.
Press keys on your keyboard to generate entropy (bits = 128).
Press keys on your keyboard to generate entropy (bits = 192).
Press keys on your keyboard to generate entropy (bits = 256).
Press keys on your keyboard to generate entropy (bits = 320).
Press keys on your keyboard to generate entropy (bits = 384).
Press keys on your keyboard to generate entropy (bits = 456).
Press keys on your keyboard to generate entropy (bits = 520).
Press keys on your keyboard to generate entropy (bits = 584).
Press keys on your keyboard to generate entropy (bits = 648).
Press keys on your keyboard to generate entropy (bits = 712).
Press keys on your keyboard to generate entropy (bits = 776).
Press keys on your keyboard to generate entropy (bits = 840).
Press keys on your keyboard to generate entropy (bits = 904).
Press keys on your keyboard to generate entropy (bits = 968).
Writing corosync key to /etc/corosync/authkey.
# scp /etc/corosync/authkey root@192.168.0.101:/etc/corosync
# vim /etc/corosync/corosync.conf
compatibility: whitetank
totem {
version: 2
secauth: on
threads: 0
interface {
ringnumber: 0
bindnetaddr: 192.168.4.134 (Node1 IP)
mcastaddr: 239.255.1.1
mcastport: 5405
ttl: 1
}
}
logging {
fileline: off
to_stderr: no
to_logfile: yes
logfile: /var/log/cluster/corosync.log
to_syslog: yes
debug: off
timestamp: on
logger_subsys {
subsys: AMF
debug: off
}
}
# vi /etc/corosync/service.d/pcmk
service {
# Load the Pacemaker Cluster Resource Manager
name: pacemaker
ver: 1
}
# scp /etc/corosync/corosync.conf root@192.168.4.131:/etc/corosync/ (change IP in node2 )
# scp /etc/corosync/service.d/pcmk root@192.168.4.131:/etc/corosync/service.d/
# service corosync start
# service pacemaker start
# crm status
Last updated: Mon Jun 15 07:19:50 2015
Last change: Mon Jun 15 07:19:20 2015
Stack: classic openais (with plugin)
Current DC: node1.aap1 - partition WITHOUT quorum
Version: 1.1.11-97629de
2 Nodes configured, 2 expected votes
2 Resources configured
Online: [ node1.aap1 ]
OFFLINE: [ node2.app2 ]
# crm configure property stonith-enabled=false
# crm configure property no-quorum-policy=ignore
# crm configure primitive haproxy_fi IPaddr2 params ip=192.168.4.200 cidr_netmask=24 op monitor interval=30s
# cd /usr/lib/ocf/resource.d/heartbeat/
# wget http://github.com/russki/cluster-agents/raw/master/haproxy ( Download Both Node )
# chmod 744 haproxy
# cd
# crm configure primitive haproxyLB ocf:heartbeat:haproxy params conffile=/etc/haproxy/haproxy.cfg op monitor interval=30s
# crm configure show
node Node1.example.com
primitive haproxyLB haproxy \
params conffile="/etc/haproxy/haproxy.cfg" \
op monitor interval=30s
primitive haproxy_fi IPaddr2 \
params ip=192.168.4.200 cidr_netmask=24 \
op monitor interval=30s
property cib-bootstrap-options: \
dc-version=1.1.11-97629de \
cluster-infrastructure="classic openais (with plugin)" \
expected-quorum-votes=2 \
stonith-enabled=false \
no-quorum-policy=ignore
# crm configure edit ( Add Below line
group haproxy_group haproxy_fi
colocation haproxyWithIPs inf: haproxyLB haproxy_group
order haproxyAfterIPs Mandatory: haproxy_group haproxyLB
# crm configure show
node Node1.example.com
primitive haproxyLB haproxy \
params conffile="/etc/haproxy/haproxy.cfg" \
op monitor interval=30s
primitive haproxy_fi IPaddr2 \
params ip=192.168.4.200 cidr_netmask=24 \
op monitor interval=30s
group haproxy_group haproxy_fi
colocation haproxyWithIPs inf: haproxyLB haproxy_group
order haproxyAfterIPs Mandatory: haproxy_group haproxyLB
property cib-bootstrap-options: \
dc-version=1.1.11-97629de \
cluster-infrastructure="classic openais (with plugin)" \
expected-quorum-votes=2 \
stonith-enabled=false \
no-quorum-policy=ignore
Save and Quit
# /etc/init.d/haproxy restart
# /etc/init.d/httpd restart
NODE2
# /etc/init.d/corosync start
# /etc/init.d/pacemaker start
I have using RHEL6.4 64 Bit Machines
IP 192.168.0.100 Name Node1.example.com
IP 192.168.0.101 Name Node2.example.com
IP 192.168.0.200 (Virtual IP)
1. installing require Packages both Node ( Node1 & Node2 )
# yum install haproxy corosync pacemaker openssh-clients http* -y
# wget -c http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/x86_64/crmsh-2.1-1.6.x86_64.rpm
# wget -c http://pkgs.repoforge.org/pssh/pssh-2.0-1.el6.rf.noarch.rpm
# rpm -ivh pssh-2.0-1.el6.rf.noarch.rpm
# yum install crmsh-2.1-1.6.x86_64.rpm
2. Configure host file both Node ( Node1 & Node2 )
# vim /etc/hosts ( NODE1 Machine)
192.168.0.100 Node1.example.com Node1
192.168.0.101 Node2.example.com Node2
# vim /etc/hosts ( NODE2 Machine )
192.168.0.100 Node1.example.com Node1
192.168.0.101 Node2.example.com Node2
3. Configure httpd for testing both Node ( Node1 & Node2 )
# vim /etc/httpd/conf/httpd.conf ( NODE1 Machine )
Listen 192.168.4.100:8080
ServerName example.com
# cd /var/www/html/
# vim index.html
haproxy NODE1
# /etc/init.d/httpd restart
# vim /etc/httpd/conf/httpd.conf ( NODE2 Machine )
Listen 192.168.4.101:8080
ServerName example.com
# cd /var/www/html/
# vim index.html
haproxy NODE2
# /etc/init.d/httpd restart
4. Configure Haproxy both Node ( Node1 & Node2 Machine )
# cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg-ORG
# vim /etc/haproxy/haproxy.cfg
global
log 172.0.0.1 local2 debug
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4096
user haproxy
group haproxy
daemon
# turn on stats unix socket
stats socket /var/lib/haproxy/stats
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
mode http
log global
option httplog
option dontlognull
# option http-server-close
option forwardfor
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
listen Haproxy-APP 192.168.0.200:80 (Vertual IP)
balance roundrobin
option httpclose
# option forwardfor
option forwardfor header X-Real-IP
server APPSERVER1 192.168.0.100:8080 check (Machine IP NODE1)
server APPSERVER2 192.168.0.101:8080 check (Machine IP NODE2)
listen admin
bind *:5050
stats enable
stats realm Haproxy\ Statistics
stats uri /
stats auth admin:example@123
# scp /etc/haproxy/haproxy.cfg 192.168.0.101:/etc/haproxy/haproxy.cfg
# cp /etc/corosync/corosync.conf.example /etc/corosync/corosync.conf both Node ( Node1 & Node2 Machine )
# corosync-keygen
Corosync Cluster Engine Authentication key generator.
Gathering 1024 bits for key from /dev/random.
Press keys on your keyboard to generate entropy.
Press keys on your keyboard to generate entropy (bits = 128).
Press keys on your keyboard to generate entropy (bits = 192).
Press keys on your keyboard to generate entropy (bits = 256).
Press keys on your keyboard to generate entropy (bits = 320).
Press keys on your keyboard to generate entropy (bits = 384).
Press keys on your keyboard to generate entropy (bits = 456).
Press keys on your keyboard to generate entropy (bits = 520).
Press keys on your keyboard to generate entropy (bits = 584).
Press keys on your keyboard to generate entropy (bits = 648).
Press keys on your keyboard to generate entropy (bits = 712).
Press keys on your keyboard to generate entropy (bits = 776).
Press keys on your keyboard to generate entropy (bits = 840).
Press keys on your keyboard to generate entropy (bits = 904).
Press keys on your keyboard to generate entropy (bits = 968).
Writing corosync key to /etc/corosync/authkey.
# scp /etc/corosync/authkey root@192.168.0.101:/etc/corosync
# vim /etc/corosync/corosync.conf
compatibility: whitetank
totem {
version: 2
secauth: on
threads: 0
interface {
ringnumber: 0
bindnetaddr: 192.168.4.134 (Node1 IP)
mcastaddr: 239.255.1.1
mcastport: 5405
ttl: 1
}
}
logging {
fileline: off
to_stderr: no
to_logfile: yes
logfile: /var/log/cluster/corosync.log
to_syslog: yes
debug: off
timestamp: on
logger_subsys {
subsys: AMF
debug: off
}
}
# vi /etc/corosync/service.d/pcmk
service {
# Load the Pacemaker Cluster Resource Manager
name: pacemaker
ver: 1
}
# scp /etc/corosync/corosync.conf root@192.168.4.131:/etc/corosync/ (change IP in node2 )
# scp /etc/corosync/service.d/pcmk root@192.168.4.131:/etc/corosync/service.d/
# service corosync start
# service pacemaker start
# crm status
Last updated: Mon Jun 15 07:19:50 2015
Last change: Mon Jun 15 07:19:20 2015
Stack: classic openais (with plugin)
Current DC: node1.aap1 - partition WITHOUT quorum
Version: 1.1.11-97629de
2 Nodes configured, 2 expected votes
2 Resources configured
Online: [ node1.aap1 ]
OFFLINE: [ node2.app2 ]
# crm configure property stonith-enabled=false
# crm configure property no-quorum-policy=ignore
# crm configure primitive haproxy_fi IPaddr2 params ip=192.168.4.200 cidr_netmask=24 op monitor interval=30s
# cd /usr/lib/ocf/resource.d/heartbeat/
# wget http://github.com/russki/cluster-agents/raw/master/haproxy ( Download Both Node )
# chmod 744 haproxy
# cd
# crm configure primitive haproxyLB ocf:heartbeat:haproxy params conffile=/etc/haproxy/haproxy.cfg op monitor interval=30s
# crm configure show
node Node1.example.com
primitive haproxyLB haproxy \
params conffile="/etc/haproxy/haproxy.cfg" \
op monitor interval=30s
primitive haproxy_fi IPaddr2 \
params ip=192.168.4.200 cidr_netmask=24 \
op monitor interval=30s
property cib-bootstrap-options: \
dc-version=1.1.11-97629de \
cluster-infrastructure="classic openais (with plugin)" \
expected-quorum-votes=2 \
stonith-enabled=false \
no-quorum-policy=ignore
# crm configure edit ( Add Below line
group haproxy_group haproxy_fi
colocation haproxyWithIPs inf: haproxyLB haproxy_group
order haproxyAfterIPs Mandatory: haproxy_group haproxyLB
# crm configure show
node Node1.example.com
primitive haproxyLB haproxy \
params conffile="/etc/haproxy/haproxy.cfg" \
op monitor interval=30s
primitive haproxy_fi IPaddr2 \
params ip=192.168.4.200 cidr_netmask=24 \
op monitor interval=30s
group haproxy_group haproxy_fi
colocation haproxyWithIPs inf: haproxyLB haproxy_group
order haproxyAfterIPs Mandatory: haproxy_group haproxyLB
property cib-bootstrap-options: \
dc-version=1.1.11-97629de \
cluster-infrastructure="classic openais (with plugin)" \
expected-quorum-votes=2 \
stonith-enabled=false \
no-quorum-policy=ignore
Save and Quit
# /etc/init.d/haproxy restart
# /etc/init.d/httpd restart
NODE2
# /etc/init.d/corosync start
# /etc/init.d/pacemaker start
Comments
Post a Comment