Heartbeat implementation of Web services high Availability (III)

Source: Internet
Author: User
Tags rsync

VI: Heartbeat implementation of Web services high Availability cases

6.1 Deployment of preparations

Resource environment: Continue to use two servers node01.cn and node02.cn that we have deployed heartbeat before, two machines heartbeat is dual master mode
Let's just take a second.
node01.cn eth0 172.10.25.26 External network management IP
Eth1 10.25.25.16 Heartbeat Direct connection
VIP 172.10.25.18
node02.cn eth0 172.10.25.27 External network management IP
Eth1 10.25.25.16 Heartbeat Direct connection
VIP 172.10.25.10

6.2 Installing the Configuration HTTP service

We use heartbeat to achieve high availability of HTTP services, so simply use Yum to install HTTP, detailed installation methods for Apache, Nginx, Tomcat see other articles in this blog

Bash
[[email protected] ~]# yum install httpd -y[[email protected] ~]# yum install httpd -y

If the service is turned on we have to stop it and cancel the boot and give it to heartbeat to control the startup and shutdown of the httpd service.

Bash
[[Email protected] ~]#/ETC/INIT.D/HTTPD Stop[[Email protected] ~]#/ETC/INIT.D/HTTPD Stop[[Email protected] ~]# chkconfig httpd off[[Email protected] ~]# chkconfig httpd off[[email protected] ~]# cd/var/www/html/[[email protected] HTML]# echo 172.10.25.26 >index.html[[email protected] ~]# cd/var/www/html/[[email protected] HTML  ]# echo 172.10.25.27 >index.html             

6.3 Configuring the HTTPD service startup script

Copy the httpd boot script to/etc/ha.d/resource.d/on both machines separately. Make sure you have executable permissions

Bash
[[email protected] ~]# cp /etc/init.d/httpd /etc/ha.d/resource.d/[[email protected] ~]# cp /etc/init.d/httpd /etc/ha.d/resource.d/

It is also possible not to copy the past, Heartbeat will find the service startup script under/etc/init.d/
Hint:/etc/ha.d/resource.d/is the default script directory for heartbeat

Script Requirements for Heartbeat control
1. Script path to be placed in the/etc/init.d/or/etc/ha.d/resource.d/directory
2, script execution, need to/etc/init.d/httpd Stop/start way
3. Scripts have executable permissions
4, script name and configuration in the same name, such as/etc/init.d/httpd name and Ipaddr::172.10.25.18/24/eth0 httpd

6.4 Modifying the Haresource configuration

Configuration of the node01.cn

Bash
[[email protected] ~]# cd /etc/ha.d/[[email protected] ha.d]# cp haresources haresources.bk[[email protected] ha.d]# vim haresources node01.cn IPaddr::172.10.25.18/24/eth0 httpd node02.cn IPaddr::172.10.25.10/24/eth0 httpd

Configuration of the node02.cn

Bash
[[email protected] ~]# cd /etc/ha.d/[[email protected] ha.d]# cp haresources haresources.bk[[email protected] ha.d]# vim haresources node01.cn IPaddr::172.10.25.18/24/eth0 httpd node02.cn IPaddr::172.10.25.10/24/eth0 httpd

6.5 Restart heartbeat, test for web high availability

We restarted heartbeat, tested it to control httpd boot, and achieved high availability

Bash
[[email protected] ~]# /etc/init.d/heartbeat stop[[email protected] ~]# /etc/init.d/heartbeat start[[email protected] ~]# /etc/init.d/heartbeat stop[[email protected] ~]# /etc/init.d/heartbeat start
Bash
[[Email protected] ~]# lsof-i: 80COMMAND PID USER FD TYPE DEVICE size/off NODE nameclock-app 4049 root 22u IPv4 118999 0t 0 TCP node01.cn:49022->a23-62-109-161.deploy.static.akamaitechnologies.com:http(close_wait) httpd 15319 root 8u IPv6 121255 0t0 TCP *:http(LISTEN) httpd 15321 Apache 8u IPv6 121255 0t0 TCP *:http(LISTEN) httpd 15322 Apache 8u IPv6 121255 0t0 TCP *:http(LISTEN) httpd 15323 Apache 8u IPv6 121255 0t0 TCP *:http(LISTEN) httpd 15324 Apache 8u IPv6 121255 0t0 tcp *:http (LISTEN) httpd 15325 Apache 8u IPv6 121255 0t0 TCP *:http (LISTEN) httpd 15326 Apache 8u IPv6 121255 0t0 TCP *:http (LISTEN) httpd 15327 Apache 8u IPv6 121255 0t0 TCP *:http (LISTEN) httpd 15328 Apache 8u IPv6 121255 0t0 TCP *:http (LISTEN) /c7> 
Bash
[[Email protected] ~]# lsof-i: 80COMMAND PID USER FD TYPE DEVICE size/off NODE namehttpd 15563 root 8u IPv6 122138 0t0 T CP *:http(LISTEN) httpd 15565 Apache 8u IPv6 122138 0t0 TCP *:http(LISTEN) httpd 15566 Apache 8u IPv6 122138 0t0 TCP *:http(LISTEN) httpd 15567 Apache 8u IPv6 122138 0t0 TCP *:http(LISTEN) httpd 15568 Apache 8u IPv6 122138 0t0 tcp *:http (LISTEN) httpd 15569 Apache 8u IPv6 122138 0t0 TCP *:http (LISTEN) httpd 15570 Apache 8u IPv6 122138 0t0 TCP *:http (LISTEN) httpd 15571 Apache 8u IPv6 122138 0t0 TCP *:http (LISTEN) httpd 15572 Apache 8u IPv6 122138 0t0 TCP *:http (LISTEN) /c7> 

Access to page tests, or track log tests

Bash
INFO:  SuccessResourceManager(default)[15051]:        2016/02/27_23:25:38 info: Running /etc/ha.d/resource.d/httpd  startStarting httpd: [ OK ]ARPING 172.10.25.18 from 172.10.25.18 eth0Sent 5 probes (5 broadcast(s))Received 0 response(s)

Adding host parsing on a Windows physical machine

C:\Windows\System32\drivers\etc

172.10.25.18 pualinux.org
172.10.25.10 pualinux.org

Re-visit http://pualinux.org/

If the current host fails, let's take a look at the page that switches access

Bash
[[email protected] ~]# /etc/init.d/heartbeat stop

This simply enables the Web to be highly available

Database to do high availability to maintain data consistency, in real-time synchronization, can be combined with the use of DRBD

Other details can refer to Hearbeat's script and its comments

Bash
/etc/ha.d/rc.d/ip-request/etc/ha.d/rc.d/ip-request-resp/etc/init.d/heartbeat /etc/ha.d/resource.d/IPaddr/etc/ha.d/resource.d/drbd/etc/ha.d/resource.d/drbddisk/etc/ha.d/resource.d/Filesystem/usr/share/heartbeat/hb_standb /usr/share/heartbeat/hb_takeover

6.6 Production scenarios for heartbeat call resources

There are two common ways to implement high-availability scenarios in real-world work:
1, heartbeat can control the shift of VIP resources, not responsible for the start and shutdown of service resources (suitable for Web services)
2, Heartbeat is to control the VIP resource drift, but also control the start and shutdown of services, the above example is the use of this. Require IP and service to switch all, the drawback is that VIP normal, httpd service outage, then do not do high-usable switch, so we have to write a simple script timing or daemon process to determine whether the httpd service is normal, if there is a problem, Stop the heartbeat. Transfer its business to another host (for database, storage, only one end write operation)

6.7 Using heartbeat to implement httpd high availability summary

1, the log is very important, encountered problems to see the log to go wrong, not only heartbeat, other services are
2, the high availability of a single service in the production of relatively small, general Web services load-balanced use more, in load balancing, primary database, primary storage using high availability
3, MySQL high-availability implementation mode and HTTPD is basically the same, just httpd back-end use of shared storage, so do not need to do data synchronization. And the MySQL backend is not used for storage, so in order to do high availability, the master-slave, the main master synchronization

6.8 Enterprise production heartbeat high-availability switching instructions

1, high-availability switch is generally used for main fault standby automatic switching takeover, rapid replacement of the fault machine to provide services

2, after the takeover after the aftermath of the work, it is best to manually deal with

3, no matter how well prepared, monitoring multi-intelligence, generally will not automatically cut back to the main library, but manual control, because this failback is controllable, there is time to prepare, and the main one hanging, ready to automatically switch the replacement is not controllable

4, important data services can not be automatically cut back and forth, that is, auto_failback off should be off state

5, according to specific business specific analysis, it is best not to set up boot

6.9 Heartbeat and keepalived application scenario differences

1, for the general web, DB, load Balancing (nginx,haproxy), and so on, heartbeat and keepalived can achieve
2, LVS load Balancing is best combined with keepalived, although heartbeat can also invoke a script with ipvsadm command to start or stop the LVS load balancer, but heartbeat itself does not have the following node RS health check function, But can also be made up by Ldircetord plug-ins. Heartbeat+lvs+ldirectord
3. High-availability services that require data synchronization (with DRBD) are best used with heartbeat. such as MySQL dual master multi-slave, Nfs/mfs storage, they are characterized by the need for data synchronization, such business is best used heartbeat, because heartbeat comes with the script of DRBD, Synchronization can be achieved with the powerful DRBD synchronization software. Of course, if you do not use DRBD for data synchronization, use other shared storage (Inotify+rsync,sersync+rsync), or you can consider using keepalived
4, according to their own use of which software more familiar with the decision

Http://www.linux-ha.org/doc/users-guide/users-guide.html

Heartbeat implementation of Web services high Availability (III)

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.