Corosync is an open source cluster engine used to implement high availability within applications. Commonly referred to as a messaging layer, Corosync provides a cluster membership and closed communication model for creating replicated state machines, on top of which cluster resource managers like Pacemaker can run. Corosync can be seen as the underlying system that connects the cluster nodes together, while Pacemaker monitors the cluster and takes action in the event of a failure.
This tutorial will demonstrate how to use Corosync and Pacemaker to create a high availability (HA) infrastructure on DigitalOcean with CentOS 7 servers and Floating IPs. To facilitate the process of setting up and managing the cluster nodes, we are going to use PCS, a command line interface that interacts with both Corosync and Pacemaker.A. Pre Activity
This tutorial will demonstrate how to use Corosync and Pacemaker to create a high availability (HA) infrastructure on DigitalOcean with CentOS 7 servers and Floating IPs. To facilitate the process of setting up and managing the cluster nodes, we are going to use PCS, a command line interface that interacts with both Corosync and Pacemaker.A. Pre Activity
1. Editing Network
Server01
# vi /etc/sysconfig/network-script/eth0
IPADDR = 10.10.10.10
PREFIX = 24
GATEWAY = 10.10.10.1
STATIC
Server02
# vi /etc/sysconfig/network-script/eth0
IPADDR = 10.10.10.20
PREFIX = 24
GATEWAY = 10.10.10.1
STATIC
2. Verify network
Server01 and Server02
# ip ad
# ping -c1 10.10.10.10
# ping -c1 10.10.10.20
vi /etc/hosts
10.10.10.10 teguht-ha01
10.10.10.20 teguht-ha02
sample output
[root@teguht-ha01 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain .localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.10.10.10 teguht-ha01
10.10.10.20 teguht-ha02
[root@teguht-ha01 ~]#
from Server01
[root@teguht-ha01 ~]# ping -c1 teguht-ha01
PING teguht-ha01 (10.10.10.10) 56(84) bytes of data.
64 bytes from teguht-ha01 (10.10.10.10): icmp_seq=1 ttl=64 time=0.043 ms
--- teguht-ha01 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.043/0.043/0.043/0.000 ms
[root@teguht-ha01 ~]#
[root@teguht-ha01 ~]# ping -c1 teguht-ha02
PING teguht-ha02 (10.10.10.20) 56(84) bytes of data.
64 bytes from teguht-ha02 (10.10.10.20): icmp_seq=1 ttl=64 time=0.491 ms
--- teguht-ha02 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.491/0.491/0.491/0.000 ms
[root@teguht-ha01 ~]#
from Server02
[root@teguht-ha02 ~]# ping -c1 teguht-ha01
PING teguht-ha01 (10.10.10.10) 56(84) bytes of data.
64 bytes from teguht-ha01 (10.10.10.10): icmp_seq=1 ttl=64 time=0.673 ms
--- teguht-ha01 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.673/0.673/0.673/0.000 ms
[root@teguht-ha02 ~]#
[root@teguht-ha02 ~]# ping -c1 teguht-ha02
PING teguht-ha02 (10.10.10.20) 56(84) bytes of data.
64 bytes from teguht-ha02 (10.10.10.20): icmp_seq=1 ttl=64 time=0.044 ms
--- teguht-ha02 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.044/0.044/0.044/0.000 ms
[root@teguht-ha02 ~]#
[root@teguht-ha02 ~]#
3. Configure SSH in Server01
# ssh-keygen -t dsa -f ~/.ssh/id_dsa -N ""
# scp -r ~/.ssh teguht-ha02:
# ssh teguht-ha02 -- uname -n
4. Update Configuration Server01 and Server02
# yum -y update
B. Instalation and Configuration PCS, COROSYNC, and Pacemaker
1. Install the Cluster Software on Server01 and Server02
# yum install -y pacemaker pcs psmisc policycoreutils-python
# firewall-cmd --permanent --add-service=high-availability
# firewall-cmd --reload
# systemctl disable firewalld
# systemctl stop firewalld
# systemctl start pcsd.service
# systemctl enable pcsd.service
2. enable password hacluster Server01 and Server02
# echo "recomendation password as same as root"
# passwd hacluster
3. Configure Corosync on Server01
# pcs cluster auth teguht-ha01 teguht-ha02
# pcs cluster setup --name mycluster teguht-ha01 teguht-ha02
4. Start cluster on Server01
# pcs cluster start --all
5. Start and Enable service Server01 and Server02
# systemctl enable corosync.service
# systemctl enable pacemaker.service
# systemctl enable pcsd.service
# pcs status
# pcs property set stonith-enabled=false
# crm_verify -L
output
[root@teguht-ha01 ~]# pcs status
Cluster name: mycluster
Stack: corosync
Current DC: teguht-ha01 (version 1.1.18-11.el7_5.3-2b07d5c5a9) - partition with quorum
Last updated: Tue Aug 28 15:59:07 2018
Last change: Sat Aug 25 11:05:01 2018 by root via cibadmin on teguht-ha01
2 nodes configured
1 resource configured
Online: [ teguht-ha01 teguht-ha02 ]
Full list of resources:
ClusterIP (ocf::heartbeat:IPaddr2): Started teguht-ha01
Daemon Status:
corosync: active/enabled
pacemaker: active/enabled
pcsd: active/enabled
[root@teguht-ha01 ~]#
6. Add ClusterIP/FloatingIP/VirtualIP on Server01
# pcs resource create ClusterIP ocf:heartbeat:IPaddr2 ip=10.10.10.30 cidr_netmask=24 nic=eth0 op monitor interval=30s
7. Check pcs Status
# pcs status
[root@teguht-ha01 ~]# pcs status
Cluster name: mycluster
Stack: corosync
Current DC: teguht-ha01 (version 1.1.18-11.el7_5.3-2b07d5c5a9) - partition with quorum
Last updated: Tue Aug 28 15:57:57 2018
Last change: Sat Aug 25 11:05:01 2018 by root via cibadmin on teguht-ha01
2 nodes configured
1 resource configured
Online: [ teguht-ha01 teguht-ha02 ]
Full list of resources:
ClusterIP (ocf::heartbeat:IPaddr2): Started teguht-ha01
Daemon Status:
corosync: active/enabled
pacemaker: active/enabled
pcsd: active/enabled
[root@teguht-ha01 ~]#
root@teguht-ha02 ~]# pcs status
Cluster name: mycluster
Stack: corosync
Current DC: teguht-ha01 (version 1.1.18-11.el7_5.3-2b07d5c5a9) - partition with quorum
Last updated: Tue Aug 28 15:59:12 2018
Last change: Sat Aug 25 11:05:01 2018 by root via cibadmin on teguht-ha01
2 nodes configured
1 resource configured
Online: [ teguht-ha01 teguht-ha02 ]
Full list of resources:
ClusterIP (ocf::heartbeat:IPaddr2): Started teguht-ha01
Daemon Status:
corosync: active/enabled
pacemaker: active/enabled
pcsd: active/enabled
[root@teguht-ha02 ~]#
8. Test Failover
Acton Server01
# echo "if you want to test failover"
# pcs cluster stop teguht-ha01
# pcs status
Error: cluster is not currently running on this node
[root@teguht-ha01 ~]# pcs cluster stop teguht-ha01
teguht-ha01: Stopping Cluster (pacemaker)...
teguht-ha01: Stopping Cluster (corosync)...
[root@teguht-ha01 ~]#
[root@teguht-ha01 ~]# pcs status
Error: cluster is not currently running on this node
[root@teguht-ha01 ~]#
Action Server02
# pcs status
[root@teguht-ha02 ~]# pcs status
Cluster name: mycluster
Stack: corosync
Current DC: teguht-ha02 (version 1.1.18-11.el7_5.3-2b07d5c5a9) - partition with quorum
Last updated: Tue Aug 28 16:00:54 2018
Last change: Sat Aug 25 11:05:01 2018 by root via cibadmin on teguht-ha01
2 nodes configured
1 resource configured
Online: [ teguht-ha02 ]
OFFLINE: [ teguht-ha01 ]
Full list of resources:
ClusterIP (ocf::heartbeat:IPaddr2): Started teguht-ha02
Daemon Status:
corosync: active/enabled
pacemaker: active/enabled
pcsd: active/enabled
[root@teguht-ha02 ~]#
9. if you want to Set Master to Master(Replica) and Master to Slave(Mirroring) On MySQL (Include MariaDB) visit
http://teguhth.blogspot.com/2018/08/how-to-redundant-set-master-to-master.html
10. note for add & remove Ip virtual
add IP Virtual
# pcs resource create ClusterIP ocf:heartbeat:IPaddr2 ip=10.10.10.30 cidr_netmask=24 nic=eth0 op monitor interval=30s
delete ip virtual
# pcs resource delete ClusterIP
No comments:
Post a Comment