Build Nginx+heartbeat under Linux

Source: Internet
Author: User

I. Overview of the theory

HA is highly available, also known as dual-machine hot standby.

High Availability principle: Two machines A and B, normal a service, B idle, when a down or service outage, switch to B to continue to provide services, use heartbeat for communication and election

Heartbeat principle: Two parts of heartbeat detection and resource takeover. The hosts in the cluster send messages to each other, telling each other their current state, if they have not received the other message within a certain period of time, they determine the death

Popular high-availability software: Heartbeat, keepalived

Brain fissure: Both sides cannot transmit heartbeat information, resulting in the inability to get other node state information

Heartbeat suitable for service high availability

Keepalived suitable for making LVS highly available

Two methods of detection: sending messages to each other, a second ping gateway or other third-party

Function of the Heartbeat line (intranet IP): sending messages to each other

Experiment: AB Two virtual machines are installed Nginx and Heartbeat,ab Two VMs are put heartbeat up, but do not start nginx.

The Nginx on the master node will automatically start and receive the VIP.

Under normal circumstances is a service, VIP on a, if the nginx on a fails to stop working, the VIP will drift to B, the B on the nginx will automatically start, in order to achieve high availability effect

Second, build

Focus: Time synchronization

Each cluster node can parse each other

(1) Three configuration files:

Secret key file: Authkeys

Heartbeat service configuration file: ha.cf

Resource Management configuration file: Haresouce

(2) Preparation environment

1. Two virtual machines are installed heartbeat and Nginx

2. Hostname: Node1 node2

        3. Two machines are added two intranet address: 192.168.100.20,192.168.100.30 (used to simulate the heartbeat line)
        4. Turn off firewall  service iptables stop
        5.  turn off SELinux   Setenforce 0
        6. Add parsing  vim/etc/hosts            #增加内容如下:  

              192.168.1.104  node1                        #外网地址和主机名
            192.168.1.106  node2            & nbsp           #外网地址和主机名     

 

  #cd  /usr/share/doc/heartbeat-3.0.4/    #cp   authkeys  ha.cf  haresources   /etc/ha.d/         #拷贝模版配置文件       #cd  /etc/ha.d                                                 #vim    authkeys                     #设置互相检测心跳时的加密方式     #vim  haresources                   #设置主节点, spare top not modified                          node1  192.168.1.109/24/eth0:0 nginx    #主节点的主机名/Extranet ip/Mask/virtual interface/high-availability service     #vim   HA.CF                                           debugfile /var/log/ha-debug              #记录调试信息     ogfile /var/log/ha-log                   #记录日志信息      logfacility     local0                   #日志级别     keepalive 2                             &nbSP; #发送心跳报文的间隔               deadtime  30                              #等待30秒, if the heartbeat is forfeited to the other, as downtime        warntime 10                              #10秒收不到, logging      initdead 60                             # Network start-Up time          udpport 694                               #设置广播通信Ports Used     ucast eth1 192.168.100.20          #第一种: The broadcast form detects the other person's heartbeat line information (each other, intranet IP)     auto_failback on                   #主节点恢复后, whether to take over the services from the node      respawn hacluster /usr/lib64/heartbeat/ipfail    #配合ping语句指定的ping   node to detect the connectivity of the network     node    zhaijunming                #主节点     node     zhaijunming1              #从节点      ping 192.168.1.254                 #第二种检测方式,ping  third-party stable nodes                   #两种检测方式:   1. Sending heartbeat messages to each other    2.ping third-party stable nodes 


(4) Standby node

1. Copy the configuration file to the slave server

             SCP ha.cf  haresources authkeyszhaijunming1:/etc/ha.d/  #把配置文件拷贝到从上

     2. Backup node modification/etc/ha.cf       VIM  /etc/ha.d/ha.cf           # Just need to change one place, modify the jumper address for each other's hearts
        "Ucast eth1192.168.100.20" to   "Ucasteth1 192.168.100.30"

Third, testing

Main:1.StartHeartbeat: Wait a minute or so to executeifconfig-aSee if there are anyVIP, and thenNginxis the service automatically up?

start heartbeat vip nginx

stop on the master node httpd , see if VIP go to alternate node, standby node httpd whether the service is started


This article from "Style," blog, declined reprint!

Build Nginx+heartbeat under Linux

Related Article

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.