Heartbeat V2 for Mysql+nfs high availability

Source: Internet
Author: User

HeartbeatV2 for Mysql+nfs High availability


Preparation before the experiment

1. time needs to be synchronized, we recommend using NTP Server synchronization time and create time synchronization schedule

#ntpdate 172.16.0.1//First node #ntpdate 172.16.0.1//second node CRONTAB-E */3 * * * */usr/sbin/ntpdate 172.16.0.1 > /dev/null

2. The root user is based on key authentication

Ssh-keygen-t rsa-p "//Node one ssh-copy-id-i ~/.ssh/id_rsa.pub node3ssh-keygen-t rsa-p"//Node two ssh-copy-id-i ~/.ssh/id_r Sa.pub Node2

3./etc/hosts file for IP corresponding host name resolution

172.16.249.122 Node2 172.16.249.141 Node3

When it's all ready.

Download the required packages for installation:

Ready to install: I am here to store the FTP server.

Lftp172.16.0.1:/pub/sources/6.x86_64> Mirror heartbeat2/

To resolve dependencies and package installation:

#yum-y installnet-snmp-libs libnet PyXML #rpm-ivh heartbeat-pils-2.1.4-12.el6.x86_64.rpm #rpm- ivhheartbeat-stonith-2.1.4-12.el6.x86_64.rpm #rpm-ivhheartbeat-gui-2.1.4-12.el6.x86_64.rpm #rpm- ivhheartbeat-2.1.4-12.el6.x86_64.rpm

idea: Achieve high availability of MYSQL+NFS. Use NFS as a shared storage server for MySQL. First you need a machine, as an NFS Server, and then create two nodes for MySQL. initialize the MySQL database as a directory for NFS mounts, respectively. Manage through HEARTBEATV2.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/58/27/wKioL1SqnBDQv8oyAAB8TfMS5HI247.jpg "title=" Topology diagram. png "alt=" wkiol1sqnbdqv8oyaab8tfms5hi247.jpg "/>



Building an NFS server

[[email protected] ~]# mkdir /mydata/data[[email protected] ~]# cat/etc/ "passwd | cut -d: -f 3 | grep " [[email protected] ~]# groupadd -r -g 400 mysql[[email protected] ~]# useradd-r -g 400  -u 400 mysql[[email protected] ~]# id mysqluid=400 (MySQL) gid=400 (MySQL)  groups=400 (MySQL) [[email protected] ~]# chown -r mysql:mysql /mydata/data[ [email protected] ~]# ll -d /var/lib/mysqldrwxr-xr-x 4 mysql mysql4096  jan  1 15:31 /mydata/data[[email protected] ~]# vim/etc/exports/data/ MYSQL          172.16.0.0/16 (Rw,no_root_squash) [[email  protected]~]# exportfs -arv         //re-export mounts all file systems

To the MySQL node to view the results:

[[email protected] ntp]# SHOWMOUNT-E 172.16.249.239//This IP is our NFS ip,exportlist for 172.16.249.239:/mydata/data/ Mydata172.16.11.1/16

MySQL creation for each node

Start building now MySQL Costume Service Device

The process of installing MySQL using a binary version is a few steps:

1. Create a user to access the library for the data.

2. Create A directory that is stored by MySQL data, and the main array is mysql.

3. Modify the extracted files of all the owner is the root group of MySQL

4. Initialize the script.

5.

[[email protected] ~]# groupadd -r -g 400 mysql   // Keep the ID number consistent, or you can't write the operation [[email protected] ~]# useradd -r -g 400 -u 400  mysql# mkdir /var/lib/mysql            / /Create a separate file for MySQL to Mount NFS as a database using chown -r mysql:mysql /var/lib/mysql    //   Give database permissions lftp172.16.0.1:/pub/sources/6.x86_64/mariadb> mgetmariadb-5.5.36-linux-x86_64. Tar.gzlftp172.16.0.1:/pub/sources/6.x86_64/mariadb> bye[[email protected] tmp]# tar  -zxf mariadb-5.5.36-linux-x86_64.tar.gz -c /usr/local/[[email protected] local] # ln-sv mariadb-5.5.36-linux-x86_64/ mariadb#cd  mariadb           creating easy-to-use soft connections #chown-r root:mysql ./*     Replace all files in the extracted MySQL directory with the main root&nbsp, and the group to MySQL. [[EMAIL PRotected] mariadb]#./scripts/mysql_install_db --user=mysql --datadir=/var/lib/mysql#cd  Support-files#cp mysql.server /etc/init.d/mysqld#[[email protected]]# cp my-large.cnf  /etc/mysql/my.cnf#vim /etc/mysql/my.cnfthread_concurrency = 8datadir = /mydata  INNODB_FILE_PER_TABLE= ON SKIP_NAME_RESOLVE = ON[[EMAIL PROTECTED] INIT.D] #chkconfig  --list mysqldservice mysqld supportschkconfig, but is not  referenced in any runlevel  (run  ' chkconfig --add mysqld ') [[email  protected]]# chkconfig --add mysqld   join service [[Email protected]]# chkconfig  mysqld off       let the service in the cluster not automatically restart the card machine

Add environment variables and other files

#Vim/etc/profile.d/mysql.sh//Add the following line #export Path=/usr/local/mysql/bin: $PATH

to be MySQL Add Mans file

Cd/usr/local/mysql/man/man1 gzip./* CP./*/usr/share/man/man1/

Man MySQL view effect

Export Library files

# cd/etc/ld.so.conf.d/vim/etc/ld.so.conf.d/mariadb.conf write to lib file path/usr/local/mysql/lib

Start MySQL

[[email protected] mysql]# service mysqld start  mysql>  showdatabases;  +--------------------+  | database            |  +--------------------+  | information_schema  |  | mysql               |  | test                |  +--------------------+  3 rows in set  (0.00sec)    mysql> GRANT ALL ON *.* TO  ' root ' @ ' 172.16.%.% '  identified by   ' Password ';  query ok, 0 rowsaffected  (0.00 sec)   mysql>  FLUSH PRIVILEGES;  Query OK, 0 rowsaffected  (0.00 sec)     //I use a remote user login here: View results    #service  mysql restart  [[email protected] local]# mysql - uroot-h172.16.11.3 -p   enter password:    welcome to  the mariadb monitor.  commands end with ; or \g.    Your MariaDB connection id is 2   Server version:  5.5.36-mariadb-log mariadbserver   copyright  (c)  2000, 2014, oracle,  MontyProgram Ab and others.   Type  ' help; '  or  ' \h '  for help. Type  ' \c '  toclear the current input  Statement.

At this point, our first node of MySQL is available.

now it's time to create a second node. Note, however, that the first node has been initialized before. Therefore, it is possible to mount it directly here. But before using it, it is best to unload the node before it is used.

The same steps add the MySQL of node two. It is not described here.

Verify that MySQL is available

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/58/30/wKioL1SryPjwuZ1pAAFhTY5eCXc847.jpg "title=" Verify that MySQL is available. png "alt=" wkiol1srypjwuz1paafhty5ecxc847.jpg "/>

Verify that another node is available for MySQL

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/58/30/wKioL1SryVaAUCcWAAMAFE_pqVU591.jpg "title=" Node 2 authentication mysql.png "alt=" Wkiol1sryvaauccwaamafe_pqvu591.jpg "/>

Configuration heartbeatV2 Available

On the Node2 node, perform the following actions:

Cp/usr/share/doc/heartbeat-2.1.4/{ha.cf,authkeys}/etc/ha.d/# vim/etc/ha.d/ha.cf Modify the following: Mcast eth0 226.11.11.11 694 1 0 auto_failback onnode node2node node3ping 172.16.0.1# Vim/etc/ha.d/authkeys Add the following: Auth SHA1 8d64d1aeff0dchmod 60 0/etc/ha.d/authkeys# SCP ha.cf authkeys node node3:/ect/ha.d//etc/init.d/heartbeat start;ssh node3 '/etc/init.d/ Heartbeat Start '

Open the graphical interface for resource configuration:

service Heartbeat start;ssh node3 ' service heartbeat start '

# Hb_gui &

Add a group Resource


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/58/30/wKioL1SrzkKDKxSuAAHEzJRlORw193.jpg "title=" Node 2.png "alt=" Wkiol1srzkkdkxsuaahezjrlorw193.jpg "/>


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/58/34/wKiom1SrzaHCdU5bAAGXL2a3I1k366.jpg "title=" Add a group resource. png "alt=" wkiom1srzahcdu5baagxl2a3i1k366.jpg "/>

Add mobile IP and MySQL and file system resources in turn

The first two comparisons simply demonstrate how the file system is added:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/58/34/wKiom1SrzsqR2dWmAAPjhszqcuY446.jpg "title=" Filesystem.png "alt=" Wkiom1srzsqr2dwmaapjhszqcuy446.jpg "/>

To add a constraint relationship for a resource: order:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/58/30/wKioL1Srz-TR9t_eAAIjlWK0IZk451.jpg "title=" Order.png "alt=" Wkiol1srz-tr9t_eaaijlwk0izk451.jpg "/>

Switch node test

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/58/30/wKioL1Sr0E3BPdMFAAHXhBGaFhI262.jpg "title=" Switch node test. png "alt=" wkiol1sr0e3bpdmfaahxhbgafhi262.jpg "/>


Log in to MySQL verification results!



This article is from the "I and Linux those Years" blog, reprint please contact the author!

Heartbeat V2 for Mysql+nfs high availability

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.