Ha+nginx High-availability environment construction

Source: Internet
Author: User

An experimental environment:

1 Prepare two Liunx hosts and add two lines of content to the respective/etc/hosts/

192.168.141.131 Master (host name)

192.168.141.132 Slave (host name)

Each server has two network card, wherein eth1 as the heartbeat between two machines, eth0 used for ordinary communication (I use a network card to do the experiment)


2 shut down the iptables and SELinux for both hosts


3 Installing the software yum install heartbeat-y and yum install libnet-y


Two configuration file changes

(master)

1 cd/usr/share/doc/heartbeat-3.0.4/

CP Authkeys HA.CF haresources/etc/ha.d/
Go to/etc/ha.d/This directory, edit Authkeys

Vim Authkeys
Auth 3 (Certified in a third way)
#1 CRC
#2 SHA1 hi!
3 MD5 hello! Encryption
Change permissions

chmod Authkeys (the current user can execute)


2

Edit haresources This configuration file

Add a Master 192.168.141.110/24/eth0:0 Nginx (master refers to the host name of the current host this IP address is custom if in the actual environment, this is generally a public IP address, you can add other services later, for example: MySQL Apache, etc.)


3 Editing the HA.CF configuration file

VI ha.cf//change to the following:

Debugfile/var/log/ha-debuglogfile/var/log/ha-loglogfacility local0keepalive 2 #多长时间探测一次deadtime 30 # If the 30-second Ping does not #10秒ping不通会发出警告initdead #防止对方服务器重启预留一段时间udpport 694 #心跳线通讯端口ucast eth1 192.168.141.198 (SLA warntime). ve host address) Auto_failback Onnode master #你的主服务器的主机名 (can't write wrong) node slave #从的服务器的主机名ping 192.168.141.1 # (Arbitration address, judge who dies who live ) respawn Hacluster/usr/lib64/heartbeat/ipfail (Detect network connectivity) if the system is 32-bit, don't add this 64.



(slave)

Copy three files to the top of the file
SCP Authkeys haresources ha.cf slave:/etc/ha.d/
Change only ha.cf This configuration file
Ucast eth0 192.168.141.131 (IP for primary server)


Three-Mount Nginx

Since we are testing nginx here, all two machines need to install Nginx software package, here we install with Yum
After installing the Yum install, do some setup on both machines
Lord: Echo "master1111111111111111" >/usr/share/nginx/html/index.html
From top: echo "slave22222222222222222" >/usr/share/nginx/html/index.html
It helps us see it.


Four-start service

/etc/init.d/heartbeat start

Start the main heartbeat service first, and then enable the From, Nginx service does not start manually, will follow the heartbeat this service to start

Finally, use Ifconfig-a or IP add to see if you see etho0:0 This IP, which represents success.


Five Test

Add a non-ping on the main, iptables-a input-p icmp-j DROP

To see if the Nginx service will start automatically, if you can start it yourself, it means success.

Note: When the primary heartbeat service is stopped, the Nginx service above it will also stop, and when the primary heartbeat service resumes, the Hearbeat service will stop automatically and the Nginx service will stop.



This article is from the "Drifting Away" blog, make sure to keep this source http://825536458.blog.51cto.com/4417836/1890476

Ha+nginx High-availability environment construction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.