Installation environment: Centos 6.4, Httpd2.4,mysql5.5,heartbeat v2
Two machines Node1 and Node2 are provided, name resolution is added to the/etc/hosts file, and the host name is the same as the node name, that is, the name of the uname-n must be the same as the name defined by the hosts.
# IP HOSTNAME ALIAS
10.204.80.79 node1.mylinux.com Node1
10.204.80.80 node2.mylinux.com Node2
Establish SSH trust between the two servers
#ssh-kegen–t rsa–p "" to generate id_rsa.pub and id_rsa public and private key files
#ssh-copy-id–i. ssh/id_rsa.pub [email protected] Copy the public key file to Node2, in Node2, and then copy the public key file to Node1, so that the two hosts Can be exchanged without a password.
Install HTTPD, and provide access to the page, in order to show the effect, you can add a tag on the Web page file on both machines to display the difference, I use the Web page is Phpinfo logo to identify, the basic environment has been installed.
Install Heartbeat v2 Version
Because the heartbeat V2 version already does not support the RPM package on the CENTOS6 version, it cannot be installed directly with Yum and needs to be compiled with the SRC source installation package. I am using a compiled RPM package, the installation process to resolve dependencies,
Yum-y Install perl-mailtools net-snmp-libs pygtk2-libglade libnetsnmp net-snmp-libs
And then through RPM–IVH heartbeat-2.1.4-12.el6.x86_64.rpm heartbeat-gui-2.1.4-12.el6.x86_64.rpm heartbeat-stonith-2.1.4-12.el6.x86_64.rpm heartbeat-pils-2.1.4-12.el6.x86_64.rpm
650) this.width=650; "Style=" background-image:none; border-right-0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832458nk1x.png "width=" 747 "height="/>
Installation Heartbeat v2.14 version complete
Heartbeat v2 configuration file location in the/etc/ha.d/directory, there are three configuration files, Authkeys ha.cf Haresource, after the installation is completed by default there are no these three files, can be created manually, or in/usr/share/doc/ The sample files for these three files are copied to the/etc/ha.d/directory under the heartbeat-2.1.4/directory.
The role of the configuration file:
Authkeys: Authentication file, which is enabled in which encryption method and encryption key, CRC, SHA1 and MD5 three kinds of authentication mechanism.
650) this.width=650; "Style=" background-image:none; border-right-0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832459uhvq.png "width=" 313 "height=" 102 "/>
If you want to enable which authentication method, select the corresponding data after auth, and then specify the authentication key, which is a randomly generated string of 16-bit characters with OpenSSL
Haresource: This is a resource management provisioning file that is brought in by the Heartbeat V1 release, defining dependency and resource conditions.
650) this.width=650; "Style=" background-image:none; border-right-0px; margin:0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832459opgr.png "width=" 344 "height="/>
This is defined when the resource node is dependent on the Node1 node by default, vip:10.204.80.89, the default binding on Eth0, and the service defined is HTTPD24
HA.CF: Master profile, define node, log, transmit heartbeat and so on.
Logfile/var/log/ha-log
Node node1.mylinux.com
Node node2.mylinux.com
Mcast eth0 225.4.0.4 694 1 0
Ping 10.204.80.3
Configuration is complete, start heartbeat
Start heartbeat on Node1, prompting Heartbeat to start successfully, but the resource is stopped.
650) this.width=650; "Style=" background-image:none; border-right-0px; margin:0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832459y4zo.png "width=" 369 "height="/>
Viewing the boot log
650) this.width=650; "Style=" background-image:none; border-right-0px; margin:0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832460p8hl.png "width=" 562 "height=" 151 "/>
View Enable ports
650) this.width=650; "Style=" background-image:none; border-right-0px; margin:0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832460rmts.png "width=" 562 "height="/>
Multicast port 694 has been started
Start Node2 on the current node
650) this.width=650; "Style=" background-image:none; border-right-0px; margin:0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832461xihn.png "width=" 430 "height="/>
View Resources
650) this.width=650; "Style=" background-image:none; border-right-0px; margin:0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832461lcpu.png "width=" 430 "height=" "/>"
650) this.width=650; "Style=" background-image:none; border-right-0px; margin:0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832462teuz.png "width=" 562 "height=" 126 "/>
Both VIP and httpd have been started. The Web page also displays correctly
650) this.width=650; "Style=" background-image:none; border-right-0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832462kuqw.png "width=" 599 "height=" 233 "/>
Stop the heartbeat service on Node1
650) this.width=650; "Style=" background-image:none; border-right-0px; margin:0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 14098324638uoz.png "width=" 313 "height="/>
Then view the resources on the Node2
650) this.width=650; "Style=" background-image:none; border-right-0px; margin:0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832463uifa.png "width=" 562 "height=" 249 "/>
650) this.width=650; "Style=" background-image:none; border-right-0px; margin:0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832464tjkp.png "width=" 562 "height=" 119 "/>
VIP and httpd have been successfully transferred to Node2, and the Web Access page also shows the page on Node2
650) this.width=650; "Style=" background-image:none; border-right-0px; margin:0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832464ajk8.png "width=" 621 "height=" 213 "/>
Restart the heartbeat on Node1
650) this.width=650; "Style=" background-image:none; border-right-0px; margin:0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832465mnl9.png "width=" 559 "height=" 332 "/>
The resource is back on the Node1 because the Haresource defines the resource at the default Node1. Heartbeat Configuring a highly available Web service success
Configure a MySQL high availability cluster based on NFS shared storage
Two machines MYSQL1 and MYSQL2 are provided, name resolution is added to the/etc/hosts file, and the host name is the same as the node name, that is, the name of the uname-n must be the same as the name defined by the hosts.
# IP HOSTNAME ALIAS
10.204.80.86 mysql1.mylinux.com MYSQL1
10.204.80.85 mysql2.mylinux.com MYSQL2
Server for NFS 10.204.80.71
650) this.width=650; "Style=" background-image:none; border-right-0px; margin:0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832465lgew.png "width=" 301 "height="/>
MYSQL1 and MYSQL2 build trust and add MySQL accounts with the same UID and GID on three servers
650) this.width=650; "Style=" background-image:none; border-right-0px; margin:0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832465vqde.png "width=" 376 "height=" 98 "/>
Mount NFS on MYSQL1 and MYSQL2 two machines, mount directory as/mysqldata, and create a data directory for the/mysqldata/data directory for MySQL
650) this.width=650; "Style=" background-image:none; border-right-0px; margin:0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832466dg0o.png "width=" 562 "height=" 161 "/>
Install mysql5.5.38 in binary format and specify MySQL data directory as/mysqldata/data
650) this.width=650; "Style=" background-image:none; border-right-0px; margin:0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832466srfk.png "width=" 643 "height=" "/>,
The MySQL service started successfully on the MYSQL1 node,
650) this.width=650; "Style=" background-image:none; border-right-0px; margin:0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832467h3lh.png "width=" 562 "height=" 263 "/>
Then stop the MySQL service on the MYSQL1 node and start the MySQL service on the MYSQL2 node as well, note that you must add DataDir =/mysqldata/data as a configuration file in the/etc/my.cnf file.
650) this.width=650; "Style=" background-image:none; border-right-0px; margin:0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832467i5m0.png "Width=" 260 "height=" 275 "/>
Started MySQL service successfully on MYSQL2 node.
650) this.width=650; "Style=" background-image:none; border-right-0px; margin:0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832468glvz.png "width=" 307 "height=" "/>
The cluster environment has been set up, and the installation of the Heartbeat V2 version process refers to the above Web high availability cluster process. Enable graphical interface configuration resources
Write the following configuration in the/ETC/HA.D/HA.CF master configuration
Node mysql1.mylinux.com
Node mysql2.mylinux.com
Mcast eth0 225.5.0.4 694 1 0
Ping 10.204.80.3
CRM on # Enable graphical interface configuration resources
Enabling the validation feature in/etc/ha.d/authkeys
2 SHA1 7cd37bc0d0fbc374
Enter command Crm_mon to view status information for two nodes
650) this.width=650; "Style=" background-image:none; border-right-0px; margin:0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832468bmqw.png "width=" 527 "height=" 199 "/>
Two nodes are already online, but no resources are defined
Enter 650 at the command line) this.width=650; "Style=" background-image:none; border-right-0px; margin:0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832468lsuw.png "Width=" 192 "height="/> Enable graphical interface
650) this.width=650; "Style=" background-image:none; border-right-0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 14098324690az1.png "width=" 376 "height=" 314 "/>
After installing heartbeat will automatically create Hacluster account, add password to this account, start heartbeat service can log in to configure resources.
650) this.width=650; "Style=" background-image:none; border-right-0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832470ifg2.png "width=" 452 "height=" 377 "/>
Shows that two nodes are already in a normal online state. You can add resources
Since the MySQL service must be started with three resources: VIP NFS and MySQL service, the three resources are defined in the same resource group.
Add the resource Vip,ip address, the alias on which NIC is bound, specify netmask
650) this.width=650; "Style=" background-image:none; border-right-0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832470fe9t.png "width=" 434 "height=" 344 "/>
Also add filesystem resources for NFS and MYSQLD services, and then start the resources
650) this.width=650; "Style=" background-image:none; border-right-0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832471bzwe.png "width=" 472 "height=" 394 "/>
To define a constraint:
Because the previously defined resources are within the same group, the resources must be run on the same node, so the constraints to be defined are location constraints, and the default resources depend on the node mysql1. Sequential constraints, you must mount the NFS resource before you can enable the MySQL service, you must stop the MySQL service before you can stop the NFS service, define the performance
Location constraints: Defined on the MYSQL1, that is, if the MYSQL1 node is automatically transferred to the node mysql2, when the MYSQL1 node is back online, the resource is automatically transferred to the MYSQL1 node.
650) this.width=650; "Style=" background-image:none; border-right-0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 140983247297du.png "width=" 443 "height=" 370 "/>
Order constraints: Defining the order in which resources are started
650) this.width=650; "Style=" background-image:none; border-right-0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832472fatm.png "width=" 428 "height=" 293 "/>
The Red Circle section has already explained the order of resource initiation, and the cluster has already been defined.
Change the MYSQL1 node state to standby to show the conversion process
650) this.width=650; "Style=" background-image:none; border-right-0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832473knv3.png "width=" 590 "height=" 492 "/>
650) this.width=650; "Style=" background-image:none; border-right-0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832474yg8r.png "width=" 583 "height=" 486 "/>
Resource transfer completed, when the MYSQL1 node back online, the resources will be automatically transferred back.
650) this.width=650; "Style=" background-image:none; border-right-0px; padding-left:0px; padding-right:0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px; padding-top:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201409/4/287547_ 1409832474mg6b.png "width=" 579 "height=" 483 "/>
Heartbeat v2 Configure a highly available Web cluster and build MySQL high-availability cluster based on NFS