Keeping alived + Nginx to Build High Availability Master-Slave Cluster

Preface

This thing has been done for two days, the head is big, finally with the help of a small partner, built up, below record the problems and steps in the process of building!

Environmental preparation

Before the keepalived installation, you need the support of the environment: wget, gcc, pcre, openssl, zlib, popt-devel
The installation commands are as follows:

yum -y install wget 

yum install gcc-c++

yum install -y pcre pcre-devel

yum install -y openssl openssl-devel 

yum install -y zlib zlib-devel

yum install –y popt-devel

Installation tutorial for nginx

Keeping alived installation and configuration
  1. Unzip keep alived to root directory
tar -zxvf keepalived-2.0.18.tar.gz 
  1. Enter the keepalived-2.0.18 directory after decompression and configure it
cd keepalived-2.0.18

./configure -prefix=/usr/local/keepalived-2.0.18
  1. Compile and install
	make && make install 
  1. Because my installation path is not the default path, I need to modify the relevant path to ensure that keepalived can start normally.
Modify the/etc/init.d/keepalived file

Modify. /etc/sysconfig/keepalived to
. /usr/local/keepalived-2.0.18/etc/sysconfig/keepalived**
  1. Register keepalived as a service
cp /root/keepalived-1.3.4/keepalived/etc/init.d/keepalived /etc/init.d/keepalived 

cp /root/keepalived-1.3.4/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
  1. Editing configuration files (* most important)
    I use Xftp to find a response profile for editing

Host Profile

! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
   vrrp_skip_check_adv_addr
   #vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state MASTER   #The host is MASTER slave is BACKUP
    interface enp0s3   # Is the name of your network card?,Be sure not to make mistakes.
    virtual_router_id 51
    priority 100      #Priority Host100 Slave machine90  The bigger the priority, the higher the priority.
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
		192.168.56.99    #VIP is set up by yourself, but don't repeat it in one segment.
    }
}

Slave configuration file

! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
   vrrp_skip_check_adv_addr
   #vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state BACKUP
    interface enp0s3
    virtual_router_id 51
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
		192.168.56.99  
    }
}

  1. Test startup keepalived
	service keepalived start 
  1. View the status of keepalived
	service keepalived status 

You have to see running to start up successfully.

  1. Modify the welcome page index.html of host nginx to distinguish master from slave

  2. Testing the cluster we built
    Both host and slave nginx and keepalived are started

	systemctl stop nginx.service
	
	service keepalived start

11 Enter the VIP we set on the browser. My VIP is 192.168.56.99.

  1. Obviously it chose the host first, and then we turned off the mainframe keepalived service.
	service keepalived stop


In the case of downtime of the host, he will start the slave, so far we have finished building the master-slave cluster, the following are some of the problems I encountered!

View Network Card Name
  1. cd to / etc/sysconfig/network-scripts / directory
	cd /etc/sysconfig/network-scripts/
  1. ls View Files in the Directory
  2. ifcfg-enp0s3 is my network card name, but configuring keepalived only writes enp0s3

pcre-8.36/missing: Line 81: aclocal-1.14: No command found

If the above error occurs, just execute the autoreconf-iv f command. that will do

Tags: firewall yum network Nginx

Posted on Sat, 10 Aug 2019 06:26:55 -0700 by nitation