How to Configure Nginx High Availability Cluster Using Pacemaker on Ubuntu 16.04

Requirements

  1. Two fresh Alibaba Cloud ECS instance with Ubuntu 16.04 server installe.
  2. A static IP address is configured on both instances with a floating IP Address. Note that your IP address will differ based on your ECS instance.
  3. Root password is setup on both instances.

Launch Alibaba Cloud ECS Instance

Getting Started

Node1_IP_Address node1
Node2_IP_Address node2
ping node1
ping node2

Install and Configure Nginx

systemctl start nginx
systemctl enable nginx
<h1>
Nginx Cluster ::: Node1
</h1>
<h1>
Nginx Cluster ::: Node2
</h1>

Install Pacemaker, Corosync, and Crmsh

systemctl stop corosync
systemctl stop pacemaker

Configure Corosync

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 = 920).
Writing corosync key to /etc/corosync/authkey.
You can also see the generated key using the following command:
ls -l /etc/corosync/
-r-------- 1 root root  128 Feb 28 20:39 authkey
-rw-r--r-- 1 root root 3929 Oct 21 2015 corosync.conf
cd /etc/corosync/
rm -rf corosync.conf
totem {
version: 2
cluster_name: lbcluster
transport: udpu
interface {
ringnumber: 0
bindnetaddr: Node1_IP_Address
broadcast: yes
mcastport: 5405
}
}
quorum {
provider: corosync_votequorum
two_node: 1
}
nodelist {
node {
ring0_addr: Node1_IP_Address
name: primary
nodeid: 1
}
node {
ring0_addr: Node2_IP_Address
name: secondary
nodeid: 2
}
}
logging {
to_logfile: yes
logfile: /var/log/corosync/corosync.log
to_syslog: yes
timestamp: on
}
service {
name: pacemaker
ver: 1
}

Start Cluster Service

systemctl start corosync
systemctl enable corosync
systemctl start pacemaker
systemctl enable pacemaker
Last updated: Wed Feb 28 21:13:27 2018        Last change: Wed Feb 28 21:12:44 2018 by hacluster via crmd on primary
Stack: corosync
Current DC: primary (version 1.1.14-70404b0) - partition with quorum
2 nodes and 0 resources configured
Online: [ primary secondary ]Full list of resources:
runtime.totem.pg.mrp.srp.members.1.config_version (u64) = 0
runtime.totem.pg.mrp.srp.members.1.ip (str) = r(0) ip(192.168.0.102)
runtime.totem.pg.mrp.srp.members.1.join_count (u32) = 1
runtime.totem.pg.mrp.srp.members.1.status (str) = joined
runtime.totem.pg.mrp.srp.members.2.config_version (u64) = 0
runtime.totem.pg.mrp.srp.members.2.ip (str) = r(0) ip(192.168.0.103)
runtime.totem.pg.mrp.srp.members.2.join_count (u32) = 1
runtime.totem.pg.mrp.srp.members.2.status (str) = joined

Configure Cluster

crm configure property stonith-enabled=false
crm configure property no-quorum-policy=ignore
node 1: primary
node 2: secondary
property cib-bootstrap-options: \
have-watchdog=false \
dc-version=1.1.14-70404b0 \
cluster-infrastructure=corosync \
cluster-name=debian \
stonith-enabled=false \
no-quorum-policy=ignore
virtual_ip    (ocf::heartbeat:IPaddr2):    Started
webserver (ocf::heartbeat:nginx): Started
virtual_ip    (ocf::heartbeat:IPaddr2):    Started
webserver (ocf::heartbeat:nginx): Started

Test High Availability

Last updated: Wed Feb 28 21:35:21 2018        Last change: Wed Feb 28 21:34:50 2018 by root via cibadmin on primary
Stack: corosync
Current DC: primary (version 1.1.14-70404b0) - partition with quorum
2 nodes and 2 resources configured
Online: [ primary secondary ]Full list of resources: Resource Group: hakase_balancing
virtual_ip (ocf::heartbeat:IPaddr2): Started primary
webserver (ocf::heartbeat:nginx): Started primary
Last updated: Wed Feb 28 22:00:59 2018        Last change: Wed Feb 28 21:46:57 2018 by root via cibadmin on primary
Stack: corosync
Current DC: secondary (version 1.1.14-70404b0) - partition with quorum
2 nodes and 2 resources configured
Online: [ secondary ]
OFFLINE: [ primary ]
Full list of resources: Resource Group: hakase_balancing
virtual_ip (ocf::heartbeat:IPaddr2): Started secondary
webserver (ocf::heartbeat:nginx): Started secondary

Troubleshoot Cluster

Last updated: Wed Feb 28 23:46:46 2018          Last change: Wed Feb 28 22:00:43 2018 by root via cibadmin on primary
Stack: corosync
Current DC: secondary (version 1.1.14-70404b0) - partition WITHOUT quorum
2 nodes and 2 resources configured
Online: [ secondary ]
OFFLINE: [ primary ]
Resource Group: hakase_balancing
virtual_ip (ocf::heartbeat:IPaddr2): Started secondary
webserver (ocf::heartbeat:nginx): Started secondary
node 1: primary
node 2: secondary
primitive virtual_ip IPaddr2 \
params ip=Floating_IP_Address cidr_netmask=32 \
op monitor interval=10s \
meta migration-threshold=10
primitive webserver nginx \
params configfile="/etc/nginx/nginx.conf" \
op start timeout=40s interval=0 \
op stop timeout=60s interval=0 \
op monitor interval=10s timeout=60s \
meta migration-threshold=10
group hakase_balancing virtual_ip webserver
property cib-bootstrap-options: \
have-watchdog=false \
dc-version=1.1.14-70404b0 \
cluster-infrastructure=corosync \
cluster-name=debian \
stonith-enabled=false \
no-quorum-policy=ignore

Related Alibaba Cloud Products

--

--

--

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

A light introduction to vim and how to config it for python dev

Getting Started with Kubernetes | API Programming Paradigm

The Diamond Head Problem in Java and why interfaces are almost always a good option for Data…

Pull request template for the win!

How to build a successful MVP in just six months

Spring MVC

Get Kubernetes+Docker Container Platform on Azure

Tryhackme | Tokyo Ghoul write-up

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

More from Medium

Host your Golang app on Azure App Services using Docker

Schedule PostgreSQL Backups with IBM Cloud Code Engine

Initialize MongoDB running on a Docker container

ElasticSearch with docker in macbook M1.