Configuring an NFS-based MySQL ha cluster based on the Heartbeat V2 CRM implementation

Source: Internet
Author: User

Host Planning:

The highly available server installs the V2 version of Heartbeat, while the two nodes are installed with MySQL, the runtime only one node can run MySQL, the other node is standby, and the backend has an NFS shared storage, which provides a shared directory for storing data for the database.

The IP address is set to:

ha1:172.16.103.1

ha2:172.16.103.2

nfs:172.16.103.3


Experimental process:

First, prepare Server for NFS

# mkdir-pv/nfs/shared# Groupadd-g 3306 mysql# useradd-u 3306-g mysql-s/sbin/nologin-m mysql# chown-r mysql.mysql /nfs/shared# vim/etc/exportsnfs/shared 172.16.0.0/16 (no_root_squash,rw,async) # Service NFS Start

Second, the configuration of HA1 and HA2 two servers, so that they can be based on the SSH public key communication, and data interaction based on the hosts file to resolve the host name of the other side, and synchronize the time, these are the prerequisites for configuring the following steps. For specific steps, please refer to the previous blog content.

Configuration HA1:

Pre-installation of MySQL preparation work:

# groupadd-g 3306 mysql# useradd-u 3306-g mysql-s/sbin/nologin-m mysql# mkdir-pv/mydata/data# chown-r mysql.mysql /mydata/data

Initialize the database:

# mount-t NFS 172.16.103.3:/nfs/shared/mydata/data# tar XF mariadb-5.5.30-linux-x86_64.tar.gz-c/usr/local/# Cd/usr/lo cal# LN-SV mariadb-5.5.39-linux-x86_64.tar.gz mysql# cd mysql# chown-r mysql.mysql./# scripts/mysql_install_db--user=m Ysql--datadir=/mydata/data# CP support-files/my-large.cnf/etc/my.cnf #添加数据库的数据目录 # vim/etc/my.cnfdatadir =/mydata/ data# CP Support-files/mysql.server/etc/rc.d/init.d/mysqld

Try starting the database and testing for normal access, note that NFS is mounted, and if you need to start or deactivate the database later, be sure to note that the NFS shared directory is in the mounted State:

# service Mysqld Start

Another high-availability node HA2 the database initialization and HA1 are consistent, no longer duplicates.


Install the heartbeat on the HA1 and HA2 two base points:

To resolve dependencies:

# yum Install perl_timedata net-snmp-libs libnet PyXML

Install Heartbeat:

# RPM-IVH heartbeat-2.1.4-12.el6.x86_64.rpm heartbeat-pils-2.1.4-12.el6.x86_64.rpm heartbeat-stonith-2.1.4-12.el6.x86_64.rpm

Provide resource files, key files, and configuration files for heartbeat:

# cd/usr/share/doc/heartbeat-2.1.4/# cp-p ha.cf haresources authkeys/etc/ha.d/

Modify the properties of the key file because the heartbeat service detects the properties of the file when it starts, and if it is not 600, it will error.

# cd/etc/ha.d# chmod Authkeys

Modify the configuration file to add the corresponding two highly available nodes, add the multicast address and the Pingnode device, the most important point is to enable the heartbeat V2 feature, add a line in the configuration file for CRM on, and create a secret key for communication between the two nodes, Please refer to the content of the previous blog for this section.

# Vim Ha.cfcrm on

After the installation of the two-node heartbeat is complete, try to start the heartbeat, and be sure to deactivate the MySQL-related service before booting and unmount the mounted NFS disk device.

# Service Heartbeat Start

After the service starts, you can check to see if the Port the heartbeat service is listening to is normal.

# SS-TUNLP TCP LISTEN 0 *:5560 *:*

The heartbeat program automatically creates a user in the/etc/passwd file when the client program is connected to a server-side configuration of a highly available service, and the user name is Hacluster, but the user does not set a password when created and needs to create a password for the user to use.

# passwd Hacluster

Start the Heartbeat client program, Hb_gui, configure a highly available service under the graphical interface, preferably with a Xmanager program in Windows to start the graphical interface.

# Hb_gui &

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/49/1C/wKioL1QPBdDyf7daAAIXTSrFlpk614.jpg "title=" 2014-09-09 15_51_58-31_55_90_44 player.jpg "alt=" Wkiol1qpbddyf7daaaixtsrflpk614.jpg "/> First, MySQL's highly available resources require 3, IP, Mysqld,nfs, the 3 resource boot order is limited, the 3 resources are to run on a node, and mysqld to start after the NFS boot, IP address and mysqld service is not dependent on, the service is ready to start IP is also possible, The highly available HTTPD service is required to start the IP first, since the service starts with a clear need for the IP address of the resource. There is a difference between these two types of highly available resources.

The steps to define a highly available resource are as follows: first define the IP address used by MySQL.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/49/1B/wKiom1QPCFeDyGVEAAIIs6ptUT0433.jpg "title=" 2014-09-09 22_01_36-linux HA Management client.jpg "alt=" wkiom1qpcfedygveaaiis6ptut0433.jpg "/>650" this.width=650 ; "Src=" http://s3.51cto.com/wyfs02/M02/49/1B/wKiom1QPCJPDqWxBAAMAoDWF5J0885.jpg "title=" 2014-09-09 22_02_36-linux HA Management client.jpg "alt=" Wkiom1qpcjpdqwxbaamaodwf5j0885.jpg "/> Defines the second resource, which is the native type of three resources.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/49/1C/wKioL1QPCSTT3v7XAAMowcvHn_Y006.jpg "title=" 2014-09-09 22_04_10-linux HA Management client.jpg "alt=" wkiol1qpcstt3v7xaamowcvhn_y006.jpg "/> Define a third resource:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/49/1C/wKioL1QPCW2SGC3kAALOw30_tZ0596.jpg "title=" 2014-09-09 22_05_54-linux HA Management client.jpg "alt=" wkiol1qpcw2sgc3kaalow30_tz0596.jpg "/> Define the constraints between these three resources

NFS and MYSQLD to run on one node:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/49/1B/wKiom1QPCb6jECPgAAC76KQtXxo526.jpg "title=" 2014-09-09 22_07_37-linux HA Management client.jpg "alt=" wkiom1qpcb6jecpgaac76kqtxxo526.jpg "/>650" this.width=650 ; "Src=" http://s3.51cto.com/wyfs02/M01/49/1C/wKioL1QPChbwTfoEAALLjODpjkU852.jpg "title=" 2014-09-09 22_08_56-linux HA Management client.jpg "alt=" Wkiol1qpchbwtfoeaalljodpjku852.jpg "/>

Mysqlip and Mysql-service are to run on a single node:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/49/1B/wKiom1QPCnyCv2kIAALVwUdvJPM586.jpg "title=" 2014-09-09 22_10_40-linux HA Management client.jpg "alt=" Wkiom1qpcnycv2kiaalvwudvjpm586.jpg "/> Define this good colocation constraints, these 3 resources run on the same node at the same time. It is also important that the MYSQLD service is started after the NFS partition is mounted, so you define the order constraints for the resources:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/49/1B/wKiom1QPC0OQXmznAANiJVRsnNY554.jpg "title=" 2014-09-09 22_14_04-linux HA Management client.jpg "alt=" Wkiom1qpc0oqxmznaanijvrsnny554.jpg "/> After defining the constraints of the boot order, you can also define the propensity to run on the highly available service node, defined in the locations constraint:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/49/1C/wKioL1QPDACTKrfhAAJY-HT_JwE937.jpg "title=" 2014-09-09 22_17_08-suek1ng Blog Management Backstage -51cto Technology blog-Leading IT technology blog. jpg "alt=" wkiol1qpdactkrfhaajy-ht_jwe937.jpg "/>650" this.width=650, "src=" http://s3.51cto.com/wyfs02/M02/49/1B/wKiom1QPDCCzj6D9AAJSjeRZiE0794.jpg "title=" 2014-09-09 22_17_53-linux HA Management client.jpg "alt=" Wkiom1qpdcczj6d9aajsjerzie0794.jpg "/> Set the ID and corresponding resources, You need to add an expression to the resource and a bias towards that node:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/49/1D/wKioL1QPDLqAS933AAK0GH9-6bQ716.jpg "title=" 2014-09-09 22_19_53-linux HA Management client.jpg "alt=" Wkiol1qpdlqas933aak0gh9-6bq716.jpg "/>

You can now try to start all of the resources and see the effect of the resource switching between the various high-availability points, the first time you start, the default is to run on the HA1 node, because resource constraints define the propensity to run on HA1 when the resource constraint is defined:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/49/1B/wKiom1QPDWnC7H3OAAH9BWq_v7A056.jpg "title=" 2014-09-09 22_21_57-linux HA Management client.jpg "alt=" Wkiom1qpdwnc7h3oaah9bwq_v7a056.jpg "/>

Try to have HA1 run in the standby state to see the effect of the service switchover:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/49/1D/wKioL1QPDceSVgGgAAHQf4cwPEo564.jpg "title=" 2014-09-09 22_24_36-linux HA Management client.jpg "alt=" Wkiol1qpdcesvgggaahqf4cwpeo564.jpg "/>

Now the resources are running on HA2. Use commands such as ifconfig on the host side to view:

[[Email protected] ha.d]# ifconfigeth0      link encap: ethernet  hwaddr 00:0c:29:e1:37:51             inet addr:172.16.103.2  Bcast:172.16.255.255  Mask:255.255.0.0           inet6 addr: fe80::20c:29ff:fee1:3751/64  scope:link          up broadcast running  multicast  mtu:1500  metric:1           rx packets:180619 errors:0 dropped:0 overruns:0 frame:0           tx packets:122944 errors:0 dropped:0 overruns:0 carrier :0          collisions:0 txqueuelen:1000            RX bytes:110119869  (105.0 MIB)   TX bytes:21043781  ( 20.0 MIB) eth0:0    link encap:ethernet  hwaddr 00:0c:29:e1:37:51             inet addr:172.16.103.60   Bcast:172.16.255.255  Mask:255.255.0.0           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1lo         Link encap:Local Loopback             inet addr:127.0.0.1  Mask:255.0.0.0           inet6 addr: ::1/128 Scope:Host           up loopback running  mtu:16436  metric:1           rx packets:0 errors:0 dropped:0 overruns:0 frame:0           TX packets:0 errors:0 dropped:0  overruns:0 carrier:0          collisions:0  txqueuelen:0           rx bytes:0  (0.0 b )   TX bytes:0  (0.0 B)

The

configured IP address runs correctly on HA2. Connect database test:

[[Email protected] ha.d]# service mysqld Statusmysql running (22193) [OK][[email  Protected] ha.d]# Mysqlwelcome to the MariaDB Monitor. Commands End With; or \g.your MariaDB connection ID is 2Server version:5.5.39-mariadb-log MariaDB servercopyright (c) #, Oracle, Mo Nty program Ab and others. Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement. MariaDB [(None)]>

Database access is also normal.

Configuring an NFS-based MySQL ha cluster based on the Heartbeat V2 CRM implementation

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.