I. Brief description of HA high availability cluster
A high-availability cluster is when a node in a cluster has a variety of hardware and software and human failures, the other nodes in the cluster can automatically take over the resources of the failed node and provide services to the outside. To reduce business interruption time, to provide users with more reliable, more efficient service.
Ii. High-availability cluster configuration for MySQL based on NFS
Environment ready for HEARTBEAT-GUI deployment above
Lab Environment:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/8A/71/wKioL1gwZJGREhRLAAAhpP38qyw735.png "title=" 10.png "alt=" Wkiol1gwzjgrehrlaaahpp38qyw735.png "/>
NFS Server Preparation
1. Prepare the LVM storage space in Nfs server [[email protected] ~]# fdisk /dev/sdbdevice contains Neither a valid dos partition table, nor sun, sgi or osf disklabelBuilding a new DOS disklabel with disk identifier 0x61284c6a. changes will remain in memory only, until you decide to Write them. After that, of course, the previous content won ' t be recoverable. warning: invalid flag 0x0000 of partition table 4 will be Corrected by w (rite) warning: dos-compatible mode is deprecated. it ' s strongly recommended to switch off the mode (command ' C ') and change display units to & nbsp; sectors (command ' u '). command (m for help): ncommand action e extended p primary partition (1-4) ppartition number (1-4): 3first cylinder (1-1305, default 1): using default value 1last cylinder, +cylinders or +size{k,m,g} (1-1305, default 1305): +10GValue out of range. last cylinder, +cylinders or +size{k,m,g} (1-1305, default 1305): +5G Command (m for help): tselected partition 3hex code (Type L to list codes): 8echanged system type of partition 3 to 8e (LINUX LVM) command (m for help): wthe partition table has been altered! Calling iocTL () to re-read partition table. Syncing disks. [[email protected] ~]# partx -a /dev/sdb[[email protected] ~]# pvcreate /dev/sdb3 physical volume "/DEV/SDB3" successfully created[[email protected] ~]# vgcreate myvg /dev/sdb3 Volume group "MYVG" successfully created[[email protected] ~]# lvcreate -L 5G -n mydata myvg logical volume "MyData" created. [[email protected] ~]# mke2fs -t ext4 /dev/myvg/mydatamke2fs 1.41.12 ( 17-may-2010) filesystem label=os type: linuxblock size=4096 (log=2) Fragment size= 4096 (log=2) stride=0 blocks, stripe width=0 blocks327680 inodes, 1310720 blocks65536 blocks (5.00%)  RESERVED FOR THE SUPER USERFIRST&NBsp;data block=0maximum filesystem blocks=134217728040 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupsuperblock backups stored on blocks: 32768, 98304, 163840, 229376 , 294912, 819200, 884736writing inode tables: done Creating journal (32768 blocks): donewriting Superblocks and filesystem accounting information: donethis filesystem will be automatically checked every 36 mounts or180 days, whichever  COMES FIRST.  USE TUNE2FS -C OR -I TO OVERRIDE.2, Boot automatically mount, and NFS Export [[EMAIL PROTECTED] ~]#&NBsp;mkdir /mydata[[email protected] ~]# vim /etc/fstab /dev/myvg/mydata /mydata ext4 defaults 0 0[[email protected] ~]# mount -a[[email protected] ~]# mount | grep /mydata/dev/mapper/myvg-mydata on /mydata type ext4 (rw) [[email protected] ~]# vim /etc/exports /mydata      192.168.0.0/24 (Rw,no_root_squash) #共享给192.168.0.0/24 network segment, readable and writable, allowing the root user to log in for easy initialization, Configure end to cancel root user login 3, export NFS shared directory # Create a MySQL user, indicate Uid,gid. MySQL user uid,gid for each node is consistent. [[email protected] ~]# groupadd -r -g 306 mysql[[email protected] ~]# useradd -r -g 306 -u 306 mysql# Create a shared directory and modify the genus Master Group. [[email protected] ~]# mkdir /mydata/data[[email protected] ~]# chown -r mysql.mysql /mydata/data# export NFS Shared directory [[email protected] ~]# exportfs - Arvexporting 192.168.0.0/24:/mydata
Each node prepares MySQL and Tests for NFS. The following steps are consistent across nodes.
Node1 Configuration
[[email protected] ~]# mkdir /mydata[[email protected] ~]# showmount - e 192.168.0.20export list for 192.168.0.20:/mydata 192.168.0.0/24[[email Protected] ~]# mount -t nfs 192.168.0.20:/mydata /mydata[[email protected] ~]# mount | grep /mydata192.168.0.20:/mydata on /mydata type nfs (rw,vers=4,addr=192.168.0.20,clientaddr=192.168.0.15) [[Email protected] ~]# groupadd -r -g 306 mysql[[email protected] ~]# useradd -r -g 306 -u 306 mysql# Verify that the MySQL user has shared directory permissions [[EMAIL PROTECTED] ~]# SU - MYSQLSU: warning: cannot change directory to /home/mysql: no such file or directory-bash-4.1$ -bash-4.1$ -bash-4.1$ cd /mydata/data-bash-4.1$ Touch node1.txt-bash-4.1$ lsnode1.txt-bash-4.1$ rm node1.txt -bash-4.1$ exitlogout# verification on the nfs server side [[Email protected] ~]# cd /mydata/data[[email protected] data]# lltotal 0- Rw-rw-r--. 1 mysql mysql 0 nov 19 19:59 node2.txt# Verify that the root user has permission to the directory [[ Email protected] ~]# touch /mydata/data/node.txt[[email protected] ~]# ll /mydata/datatotal 0-rw-r--r--. 1 root root 0 Nov 19 20:02 node.txt# installation mariadb[[email protected] ~]# tar xf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local[[email protected] ~]# cd /usr/local[[email protected] Local]# ln -sv mariadb-5.5.46-linux-x86_64 mysql ' MySQL ' -> ' Mariadb-5.5.46-linux-x86_64 ' [[email protected] local]# cd mysql/[[email protected] mysql]# chown -r root.mysql ./* #初始化mysql至nfs, this step requires only one node operation, this article Node1 execution, then node2 do not need to perform the # initialization operation, you can nfs server the sharing options No_root_ Squash removed [[email protected] mysql]# ./scripts/mysql_install_db --datadir=/mydata/data/ --user=mysql#nfs server Verification [[email protected] data]# lsaria_log.00000001 aria_log_control mysql performance_schema test# preparing the configuration file for the MySQL node [[email protected] mysql]# mkdir /etc/mysql[[email protected] mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf# Edit the configuration file, add the following three lines [[Email protected] mysql]# vim /etc/mysql/my.cnfdatadir = /mydata/datainnodb_file_per_table = onskip_name_resolve = on# prepares the service script for the MySQL node and disables mysqld boot [[email protected] mysql]# cp support-files/ mysql.server /etc/rc.d/init.d/mysqld[[email protected] mysql]# chkconfig --add Mysqld[[email protected] mysql]# chkconfig mysqld off# start MySQL, create the MyDB database [[email protected] mysql]# service Mysqld start[[email protected] mysql]# /usr/local/mysql/bin/mysqlwelcome to the mariadb monitor. commands end with ; or \g.your mariadb connection id is 3Server version: 5.5.46-MariaDB-log MariaDB servercopyright (c) 2000, 2015, oracle, mariadb corporation ab and others. type ' help; ' or ' \h ' for help. Type ' \c ' to clear the current input statement. mariadb [(None)]> create database mydb; query ok, 1 row affected (0.03 sec) mariadb [(none)]> exitBye[[email protected] mysql]# service mysqld stop
Node2 Configuration
[[email protected] ~]# tar xf mariadb-5.5.46-linux-x86_64.tar.gz -c / Usr/local[[email protected] ~]# cd /usr/local/[[email protected] local]# ln -sv mariadb-5.5.46-linux-x86_64 mysql ' MySQL ' -> ' mariadb-5.5.46-linux-x86_64 ' [[ email protected] local]# cd mysql/[[email protected] mysql]# chown root.mysql ./* #将node1的mysql配置文件复制给node2 [[email protected] mysql]# scp /etc/mysql/ my.cnf node2:/etc/mysql/#准备服务脚本 and disable boot [[email protected] mysql]# cp support-files/ mysql.server /etc/rc.d/init.d/mysqld[[email protected] mysql]# chkconfig --add mysqld[[email protected] mysql]# chkconfig mysqld off# Start the service and view the shared database [[email protected] mysql]# service mysqld start[[email protected] mysql]# /usr/ Local/mysql/bin/mysqlwelcome&nbsP;to the mariadb monitor. commands end with ; or \g.your mariadb connection id is 2server version: 5.5.46-mariadb-log mariadb ServerCopyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab And others. type ' help; ' or ' \h ' for help. Type ' \c ' to clear the current input statement. mariadb [(None)]> show databases;+--------------------+| database |+--------------------+| information_schema | | mydb | | mysql | | performance_schema | | test |+--------------------+5 rows in set (0.02 sec) mariadb [(None)]> exitbye# authorized root user remote access mysql[[email protected] ~]# /usr/local/mysql/bin/ Mysqlwelcome to the mariadb monitor. commands end with ; or \g.your mariadb connection id is 3server version: 5.5.46-mariadb-log MariaDB ServerCopyright (c) 2000, 2015, oracle, mariadb corporation ab and others. type ' help; ' or ' \h ' for help. Type ' \c ' to clear the current input statement. mariadb [(none)]> grant all on *.* to ' root ' @ ' 192.168.%.% ' identified by ' 123456 '; query ok, 0 rows affected (0.06 sec) mariadb [(none)]> flush privileges; Query ok, 0 rows affected (0.01 SEC) [[Email protected] mysql]# service mysqld stop
Uninstalling shared Directories in Node1 and Node2
[Email protected] mysql]# Umount/mydata
Third, in the Heartbeat-gui interface configuration
1. Add group resources, and IP resources
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/8A/75/wKiom1gwUpPjPeESAAC4LqjgjRw030.png "title=" 1.png " alt= "Wkiom1gwuppjpeesaac4lqjgjrw030.png"/>
2. Adding shared File system resources
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/8A/71/wKioL1gwU_eSQjafAAC1zfD5c24481.png "title=" 3.png " alt= "Wkiol1gwu_esqjafaac1zfd5c24481.png"/>
3. Add Mysql-server Resources
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/8A/71/wKioL1gwUy-wA25fAACkAzq0tq4511.png "title=" 2.png " alt= "Wkiol1gwuy-wa25faackazq0tq4511.png"/>
Note: The order of the definitions is the order in which they are started.
This article is from the "Linux Sailing" blog, make sure to keep this source http://jiayimeng.blog.51cto.com/10604001/1874668
Heatbeat-gui implementing a MySQL-based high-availability cluster for NFS