Nginx + PHP + MySQL dual-host mutual backup, full automatic switch Solution

Source: Internet
Author: User
Article Title: Nginx + PHP + MySQL dual-host mutual backup and automatic switch solution. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

In production applications, a data server with the "Nginx + PHP + MySQL" interface plays a very important role. If the server hardware or Nginx or MySQL fails, however, it cannot be recovered within a short period of time, and the consequences will be very serious. In order to avoid single point of failure, I designed this solution and compiled the failover. sh script to implement dual-host mutual backup and automatic failover. The failover takes only dozens of seconds.

  I. Dual-host mutual backup and automatic switching solution:
1. Topology:


2. Explanation:
(1) assume that the Internet domain name blog.s135.com is resolved to the Internet virtual IP address 72.249.146.214, and the Intranet hosts sets db10 to the Intranet virtual IP address 192.168.146.214.

(2) by default, the host is bound with an intranet or Internet virtual IP address, and the slave is used as a backup. When the MySQL, Nginx, or server of the host fails to be accessed, the slave node automatically takes over the Intranet and Internet virtual IP addresses. Both servers start the daemon process that monitors and automatically switches the virtual IP Address/usr/bin/nohup/bin/sh/usr/local/webserver/failover. sh 2> & 1>/dev/null &

(3) The master and slave MySQL servers are mutually active and standby. When the host is active (that is, when the host is bound with a virtual IP address), the MySQL of the read/write host and data written to the host will be synchronized to the slave machine; when the slave machine is active, the data written to the slave database is synchronized to the master database, the data is automatically synchronized from the backup machine, and vice versa ).

(4) When the host is active,/data0/htdocs/(directory for storing webpages, programs, and images) is stored every 20 seconds) /usr/local/webserver/php/etc/(php. ini and other configuration file directories),/usr/local/webserver/nginx/conf/(Nginx configuration file directory) files under the three directories are pushed to the corresponding directory on the backup server through rsync (incremental push, the same files on the two servers are not repeatedly pushed ), if the standby machine is active, files are pushed to the host every 20 seconds. For the rsync configuration file, see/etc/rsyncd. conf on the two servers. The rsync daemon is the startup command of the rsync daemon.

[1] [2] [3] [4] [5] Next page

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.