Small Q: All things must be seen farther, farther, when you take the first step, the heart must be a third step,
The second step can be your chips, no chips of life,
Destined to live in the palm of others.
Today I learned a very good knowledge, I found that my recent slow progress, extenuating, all day just to see two or three knowledge points, but every knowledge point I will study for a long time, although I know I will forget, but
Perhaps I review again, the principle I will not forget, the purpose of the first time to achieve;
Introduction
HA (High Available), highly available cluster, also known as dual standby hot (active/passive) for critical business, is an effective solution to ensure business continuity, usually has two or more than two nodes; when there is a problem with the active node, the standby node is detected at this time. And immediately follow the active node to execute the business. Commonly used high-availability open source software has heartbeat and keepalived, where keepalived has load-balanced functionality.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/74/58/wKiom1YaV3XSvqpyAAKWDADGuFc295.jpg "style=" width : 550px;height:314px;float:left; "title=" 11.PNG "width=" 550 "height=" 314 "border=" 0 "hspace=" 0 "vspace=" 0 "alt=" Wkiom1yav3xsvqpyaakwdadgufc295.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/74/55/wKioL1YaV5HwbzvpAAFbecF-JuE315.jpg "style=" width : 600px;height:300px; "title=" 111.PNG "width=" "height=" "border=" 0 "hspace=" 0 "vspace=" 0 "alt=" Wkiol1yav5hwbzvpaafbecf-jue315.jpg "/>
Figure one is the way of high-availability clusters, very clear, I do not introduce;
Figure Two is his working principle, explain, just my understanding ah, the wrong words, hope that many advice:
WEB1 server as the main node, WEB2 as the primary standby server, of course, can also add web3 for the main standby service, mobile IP is the virtual IP (VIP), the upper left corner for the user, multicast for the transmission of heartbeat information;
The user via switch to connect the mobile IP (mobile IP at the same time in two servers), the service provided by the WEB1 master server, when the Web1 service is interrupted, WEB2 will detect the heartbeat information to stop, so take the mobile IP, continue the user process
Of course, this process is transparent to the user, she just has been connected to the mobile IP, unless two machines are down, VIP interrupt
Otherwise web1 outage, VIP transfer to WEB2 continue to provide services;
Today's practice is to build high-availability servers with heartbeat.
Pre-preparation
Two servers, I use two virtual machines, IP is the main 192.168.1.103, standby 192.168.1.113, mobile IP 192.168.1.104
For easy experimentation, change the host name
Master: hostname Master >>> Bash
From: hostname slave >>> bash
Dual-machine co-operation
Off firewall: iptables-f setenforce 0 (Getenforce)
Domain point: vim/etc/hosts
192.168.1.103 Master IP host name
192.168.1.113 slave
Install the extension source in order to download the open source software used to configure HA Heartbeat
wget www.lishiming.net/data/attachment/forum/epel-release-6-8_32.noarch.rpm CENTOS6 version 32-bit
Cd/usr/locla/src
RPM-IVH epel-release-6-8_32.noarch.rpm
Yum install-y heartbeat application software for installing HA
Yum install-y libnet ha application-dependent packages
So the prep work is done.
Configure the primary and standby dual machine
Because HA high-availability cluster is only for dual-machine hot standby, so he needs to provide hot standby services, such as MySQL master-slave data hot standby Tomcat Service · Apache Services
Today we use Nginx service to show
Enter the location of the heartbeat newspaper, copy three template files
cd/usr/share/doc/heartbeat-3.0.4/
CP ha.cf Haresources authkeys/etc/ha.d/
cd/etc/ha.d/
VIM Authkeys certification file, about security level settings
Modify the place as:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/74/58/wKiom1YaXHuA_vkNAAB3aEpZ0Ic302.jpg "title=" 1.1. PNG "alt=" Wkiom1yaxhua_vknaab3aepz0ic302.jpg "/>
chmod authkeys Change Permissions
Vim haresources file, used to set the host, mobile IP, hot standby service
Near the bottom of the location add format: Host name VIP service
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/74/58/wKiom1YaXMSSdccVAACklvUz2hE267.jpg "title=" 1.2. PNG "alt=" Wkiom1yaxmssdccvaacklvuz2he267.jpg "/>
192.168.1.114/24/eth0:1
Represents the virtual IP192.168.1 of this network segment, and this IP is eth0 virtual network card, named Eth0:1; add the virtual network card method See me expand the Knowledge module; (The IP in my file is wrong, I'm missing a 1.)
Vim HA.CF This is the most important configuration file, first with redirect empty, add;
Logfile/var/log/ha.log log files
Debugfile/var/log/ha-debug.log
#bcast eth1 Heartbeat using Ethernet broadcast, ETH1 for broadcast address
Ucast eth1 192.168.1.113 Unicast form of communication, with two selected one; NIC information
KeepAlive 2 broadcasts every 2 seconds
Warntime 10 warning time, no signal received from the other node in 10s, send warning to log
Deadtime 30s seizure to the other side of the node signal that the other side down, immediately take over the other node's services
Initdead 120 wait time to restart the system to prevent the system from restarting is not down
Udpport 694 port used for broadcast communication
Auto_failback on if it is on, the service automatically switches back when the primary node fails to recover
Node Master Master host name
node slave slave host name
Ping 192.168.1.11 Quorum node, is a relatively robust device, such as switches, to the same network segment
Respawn Hacluster/usr/lib/heartbeat/ipfail When Heartbeat is started, it is placed in a process that starts with the
it , Ipfail is a tool used to detect network connectivity,
Hacluster is the user who started the program
Then copy three files to the slave
SCP ha.cf haresources Authkeys [email protected]:/etc/ha.d/
Enter the slave password to
Other two files do not change, just change the ha.cf within the ucast, according to your host network card information Change OH
Ucast eth0 192.168.1.103 Note my NIC is eth0
This time the configuration is complete, because we use the Nginx service to test, so we have to install Nginx on both machines
Yum install-y Nginx
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/74/58/wKiom1YaXn7gDhrkAADSTvlZBok348.jpg "title=" 111111111111.PNG "alt=" Wkiom1yaxn7gdhrkaadstvlzbok348.jpg "/>
Test
Testing is nothing more than to take down the host, to see if the standby server will immediately take over, restore the host, the user process will not automatically switch back;
In fact, is to verify the configuration file configuration can be implemented, of course, some time tired will not be tested;
Start heartbeat, pay special attention to start the sequence, must first start the host
/etc/init.d/heartbeat start
Wait a moment to view the host
Ifconfig will find a virtual NIC read eth0:1
PS aux |grep nginx process is running up.
The same view from the opportunity to find nothing, because it is not possible for both servers to provide services to users
Modify the default page of the Nginx Service Site directory;
(Find the Site directory path into/etc/nginx/nginx.conf >>> include path >>> path/virtual (default). conf >>&G T Go to find
echo "1111111111master" >/usr/share/nginx
Access 192.168.1.104 Mobile IP
will be displayed: 1111111111master
and the dual-machine hot standby is mainly to detect the user and the server connectivity, when not connected, from the machine to replace him with the user connection;
And the nature of connectivity is that because of the ICMP protocol, shutting it down can disconnect
Iptables-a input-p icmp-j DROP
Host View:
Ifconfig PS aux |grep nginx tail/var/log/ha_log
From Machine view:
Ifconfig PS aux |grep nginx tail/var/log/ha_log
Host Open ICMP protocol
iptables-d input-p icmp-j drop-d Delete
And on the same way to view, will find the host and the user's services automatically switched back;
You can also stop the host's Heartbeat service Test View:
/etc/init.d/heartbeat stop
In fact, the configuration of a variety of highly available services, just changed the service name in the ha.cf file;
Then install the appropriate service software, such as reference to the following MySQL high availability, is a bit too messy
Extensions: concept http://www.linuxidc.com/Linux/2013-08/88522.htm
Select software According to http://svsky.blog.51cto.com/10184644/1672431
MySQL High availability http://tianshi10cool.blog.51cto.com/1870184/1665900
= = = Clearer http://colderboy.blog.51cto.com/485582/104872
Day 27th: HA High Availability Cluster setup