First, the preparatory work
To undertake the above: Corosync+pacemaker using CRMSH to build a highly available cluster
II. MariaDB Server Configuration (NFS-based)
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 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 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, 884736 Writing inode tables: done creating journal (32768 blocks): donewriting superblocks and filesystem accounting information: done this filesystem will be automatically checked every 36 mounts or180 days, whichever comes first. use tune2fs -c or -i to override. 2, boot auto mount, and NFS export [[Email protected] ~]# 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 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 #创建共享目录, and modify the genus Master Group. [[email protected] ~]# mkdir /mydata/data[[email protected] ~]# chown -r mysql.mysql /mydata/data #导出nfs共享目录 [[email protected] ~]# exportfs - Arvexporting 192.168.0.0/24:/mydata[[email protected] ~]# service nfs start
Three, each node to prepare MySQL
Node1
Create MySQL user, UID and gid consistent with nfs server MySQL user [[email protected] ~]# groupadd -r -g 306 mysql[[email protected] ~]# useradd -r -g 306 -u 306 mysql 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 ./* mount NFS File System [[email protected] mysql]# Mount -t nfs 192.168.0.20:/mydata /mydata[[email protected] mysql]# mount | grep /mydata192.168.0.20:/mydata on /mydata type nfs (rw,vers=4, addr=192.168.0.20,clientaddr=192.168.0.15) InitialMySQL to NFS, this step requires only one node operation, this article Node1 execution, then node2 do not need to perform initialization operation, you can nfs server the sharing options in the No_root_squash removed [[email Protected] mysql]# ./scripts/mysql_install_db --datadir=/mydata/data/ --user=mysqlnfs server end View [[email protected] ~]# cd /mydata/data[[email protected] data]#  LLTOTAL 32-RW-RW---- 1 mysql mysql 16384 nov 21 20:32 aria_ LOG.00000001-RW-RW---- 1 mysql mysql 52 nov 21 20:32  ARIA_LOG_CONTROLDRWX------ 2 mysql root 4096 nov 21 20:32  MYSQLDRWX------ 2 mysql mysql 4096 Nov 21 20:32 PERFORMANCE_SCHEMADRWX------ 2 mysql root 4096 nov 21 20:32  TESTNODE1 node Configuration mysql[[email protected] mysql]# mkdir /etc/mysql[[email protected] mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf[[email protected] mysql]# vim /etc/mysql/ my.cnfdatadir = /mydata/datainnodb_file_per_table = onskip_name_resolve = On provides a service script for MySQL and prevents it from booting [[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 startstarting mysql..... success! [[Email protected] mysql]# vim /root/.bashrc path=/usr/local/mysql/bin: $PATHexport PATH[[email protected] mysql]# source /root/.bashrc[[email protected] Mysql]# mysqlwelcome 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)]> create database mydb; query ok, 1 row affected (0.16 sec) mariadb [(none)]> flush privileges; query ok, 0 rows affected (0.03 sec) mariadb [(none)]> exitBye[[ Email protected] mysql]# service mysqld stopshutting down mysql. SUCCESS! Uninstall shared directory [[Email protected] mysql]# umount /mydata
Node2
[[email protected] ~]# groupadd -r -g 306 mysql[[email protected] ~]# useradd -r -g 306 -u 306 mysql[[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 ./* Copy the Node1 configuration file to Node2[[email protected] mysql]# mkdir /etc/mysql/[[email protected] mysql]# scp /etc/mysql/my.cnf node2:/etc/mysql/prepares the service script for the Node2 node and disables boot [[ Email protected] mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld[[email protected] mysql]# chkconfig --add&nbSp;mysqld[[email protected] mysql]# chkconfig mysqld off hangs on shared file system, starts mysql[[email protected] mysql]# mkdir /mydata[[email protected] mysql]# mount -t nfs 192.168.0.20:/mydata /mydata[[email protected] mysql]# service mysqld Startstarting mysql. success! [[email protected] mysql]# vim /root/.bashrc path=/usr/local/ Mysql/bin: $PATHexport path[[email protected] mysql]# source /root/.bashrcmariadb [(None)]> show databases;+--------------------+| database |+--------------------+| information_schema | | mydb | | mysql | | performance_schema | | test |+---------- ----------+5 rows in set (0.02 SEC) Authorized remote Access mariadb [(none)]> grant all on *.* to ' root ' @ ' 192.168.%.% ' identified by ' jymlinux '; query ok, 0 rows affected (0.03 sec) mariadb [(none)]> flush privileges; query ok, 0 rows affected (0.01 sec) mariadb [(none)]> Exitbye stop MySQL and uninstall the shared directory [[email protected] mysql]# service mysqld stopshutting Down mysql. success! [[email protected] mysql]# umount /mydata
Iv. using CRMSH configuration mariadb High Availability
[[Email protected] ~]# crmcrm (Live) # cd configurecrm (live) configure# primitive myip ocf:heartbeat:IPaddr params ip=192.168.0.17 nic=eth0 cidr_netmask=24 Op monitor interval=10s timeout=20scrm (Live) Configure# verifycrm (live) configure# Commitcrm (Live) configure# primitive mystore ocf:heartbeat:filesystem params device= 192.168.0.20:/mydata/data directory=/mydata fstype=nfs crm (Live) Configure# verifywarning: mystore: default timeout 20s for start is smaller than the advised 60warning: mystore: default timeout 20s for stop is smaller than the advised 60crm (Live) Configure# commitwarning: mystore: default timeout 20s for start is smaller than the advised 60warning: mystore:&Nbsp;default timeout 20s for stop is smaller than the advised 60crm (Live) configure# primitive myserver ocf:heartbeat:mysql params binary= "/ Usr/local/mysql/bin/mysqld_safe " config="/etc/mysql/my.cnf " datadir="/mydata/data " op start timeout=120s op stop timeout=120s op monitor interval=20s Timeout=30scrm (Live) Configure# verifycrm (live) configure# commit define Group Resource CRM (live) Configure# group myservice myip mystore myserver
This article is from the "Linux Sailing" blog, make sure to keep this source http://jiayimeng.blog.51cto.com/10604001/1875183
Corosync+pacemaker to achieve highly available MARIADB