一、简述HA高可用集群
高可用集群就是当集群中的一个节点发生各种软硬件及人为故障时,集群中的其他节点能够自动接管故障节点的资源并向外提供服务。以实现减少业务中断时间,为用户提供更可靠,更高效的服务。
二、基于nfs实现mysql的高可用集群配置
环境准备接上文 heartbeat-gui部署
实验环境:
nfs server准备
1、在nfs server准备LVM存储空间 [root@node3 ~]# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building 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): n Command action e extended p primary partition (1-4) p Partition number (1-4): 3 First cylinder (1-1305, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +10G Value out of range. Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +5G Command (m for help): t Selected partition 3 Hex code (type L to list codes): 8e Changed system type of partition 3 to 8e (Linux LVM) Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@node3 ~]# partx -a /dev/sdb [root@node3 ~]# pvcreate /dev/sdb3 Physical volume "/dev/sdb3" successfully created [root@node3 ~]# vgcreate myvg /dev/sdb3 Volume group "myvg" successfully created [root@node3 ~]# lvcreate -L 5G -n mydata myvg Logical volume "mydata" created. [root@node3 ~]# mke2fs -t ext4 /dev/myvg/mydata mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 327680 inodes, 1310720 blocks 65536 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1342177280 40 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 36 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. 2、开机自动挂载,并nfs导出 [root@node3 ~]# mkdir /mydata [root@node3 ~]# vim /etc/fstab /dev/myvg/mydata /mydata ext4 defaults 0 0 [root@node3 ~]# mount -a [root@node3 ~]# mount | grep /mydata /dev/mapper/myvg-mydata on /mydata type ext4 (rw) [root@node3 ~]# vim /etc/exports /mydata 192.168.0.0/24(rw,no_root_squash) #共享给192.168.0.0/24网段,可读可写,允许root用户登录便于初始化,配置结束可取消root用户登录 3、导出nfs共享目录 #创建mysql用户,指明uid,gid。各节点的mysql用户uid,gid一致。 [root@node3 ~]# groupadd -r -g 306 mysql [root@node3 ~]# useradd -r -g 306 -u 306 mysql #创建共享目录,并修改属主属组。 [root@node3 ~]# mkdir /mydata/data [root@node3 ~]# chown -R mysql.mysql /mydata/data #导出nfs共享目录 [root@node3 ~]# exportfs -arv exporting 192.168.0.0/24:/mydata
各节点准备mysql,并测试nfs。以下步骤,各节点一致。
node1配置
[root@node1 ~]# mkdir /mydata [root@node1 ~]# showmount -e 192.168.0.20 Export list for 192.168.0.20: /mydata 192.168.0.0/24 [root@node1 ~]# mount -t nfs 192.168.0.20:/mydata /mydata [root@node1 ~]# mount | grep /mydata 192.168.0.20:/mydata on /mydata type nfs (rw,vers=4,addr=192.168.0.20,clientaddr=192.168.0.15) [root@node1 ~]# groupadd -r -g 306 mysql [root@node1 ~]# useradd -r -g 306 -u 306 mysql #验证mysql用户是否拥有共享目录权限 [root@node1 ~]# su - mysql su: 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$ ls node1.txt -bash-4.1$ rm node1.txt -bash-4.1$ exit logout #在nfs server端验证 [root@node3 ~]# cd /mydata/data [root@node3 data]# ll total 0 -rw-rw-r--. 1 mysql mysql 0 Nov 19 19:59 node2.txt #验证root用户对目录是否有权限 [root@node2 ~]# touch /mydata/data/node.txt [root@node2 ~]# ll /mydata/data total 0 -rw-r--r--. 1 root root 0 Nov 19 20:02 node.txt #安装mariadb [root@node1 ~]# tar xf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local [root@node1 ~]# cd /usr/local [root@node1 local]# ln -sv mariadb-5.5.46-linux-x86_64 mysql `mysql‘ -> `mariadb-5.5.46-linux-x86_64‘ [root@node1 local]# cd mysql/ [root@node1 mysql]# chown -R root.mysql ./* #初始化mysql至nfs,此步骤只需一个节点操作即可,本文node1执行,那么node2就不需要执行 #初始化操作后,可以将nfs server的共享选项中的no_root_squash移除了 [root@node1 mysql]# ./scripts/mysql_install_db --datadir=/mydata/data/ --user=mysql #nfs server验证 [root@node3 data]# ls aria_log.00000001 aria_log_control mysql performance_schema test #为mysql节点准备配置文件 [root@node1 mysql]# mkdir /etc/mysql [root@node1 mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf #编辑配置文件,加入以下三行 [root@node1 mysql]# vim /etc/mysql/my.cnf datadir = /mydata/data innodb_file_per_table = on skip_name_resolve = on #为mysql节点准备服务脚本,并禁止mysqld开机自启 [root@node1 mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld [root@node1 mysql]# chkconfig --add mysqld [root@node1 mysql]# chkconfig mysqld off #启动mysql,创建mydb数据库 [root@node1 mysql]# service mysqld start [root@node1 mysql]# /usr/local/mysql/bin/mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 5.5.46-MariaDB-log MariaDB Server Copyright (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)]> exit Bye [root@node1 mysql]# service mysqld stop
node2配置
[root@node2 ~]# tar xf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local [root@node2 ~]# cd /usr/local/ [root@node2 local]# ln -sv mariadb-5.5.46-linux-x86_64 mysql `mysql‘ -> `mariadb-5.5.46-linux-x86_64‘ [root@node2 local]# cd mysql/ [root@node2 mysql]# chown root.mysql ./* #将node1的mysql配置文件复制给node2 [root@node1 mysql]# scp /etc/mysql/my.cnf node2:/etc/mysql/ #准备服务脚本,并禁止开机自启 [root@node2 mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld [root@node2 mysql]# chkconfig --add mysqld [root@node2 mysql]# chkconfig mysqld off #启动服务并查看共享数据库 [root@node2 mysql]# service mysqld start [root@node2 mysql]# /usr/local/mysql/bin/mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.46-MariaDB-log MariaDB Server Copyright (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)]> EXIT Bye #授权root用户远程访问mysql [root@node2 ~]# /usr/local/mysql/bin/mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 5.5.46-MariaDB-log MariaDB Server Copyright (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) [root@node2 mysql]# service mysqld stop
在node1和node2卸载共享目录
[root@node1 mysql]# umount /mydata
三、在heartbeat-gui界面配置
1、添加组资源,以及ip资源
2、添加共享文件系统资源
3、添加mysql-server资源
注意:定义的次序就是启动的次序。
本文出自 “linux启航” 博客,请务必保留此出处http://jiayimeng.blog.51cto.com/10604001/1874668
heatbeat-gui实现基于nfs的mysql高可用集群
原文地址:http://jiayimeng.blog.51cto.com/10604001/1874668