yum -y --nogpgcheck localinstall heartbeat-3.0.4-2.el6.x86_64.rpm,heartbeat-libs-3.0.4-2.el6.x86_64.rpm
cd /etc/ha.d/
复制heartbeat需要的三个配置文件:
cp -a /usr/share/doc/heartbeat-3.0.4/{authkeys,ha.cf,haresources} /etc/ha.d/
cd /etc/ha.d/
1、配置authkeys
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 664 5120000 83 Linux
Partition 2 does not end on cylinder boundary.
/dev/sda3 664 1301 5120000 83 Linux
/dev/sda4 1301 2611 10525696 5 Extended
/dev/sda5 1301 1429 1024000 82 Linux swap / Solaris
/dev/sda6 1429 1821 3155279 8e Linux LVM
[root@NFS ~]#
[root@NFS ~]# pvcreate /dev/sda6
Physical volume "/dev/sda6" successfully created
[root@NFS ~]# vgcreate myvg /dev/sda6
Volume group "myvg" successfully created
[root@NFS ~]# lvcreate -L 2G -n mylv myvg
Logical volume "mylv" created
[root@NFS ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
mylv myvg -wi-a---- 2.00g
mkdir /mydata/data
groupadd -g 3306 mysql
useradd -g mysql -u 3306 -s /sbin/nologin -M mysql
chown -R mysql:mysql /mydata/data
[root@NFS ~]# ls -l /mydata/
总用量 20
drwxr-xr-x. 2 mysql mysql 4096 5月 15 01:11 data
drwx------. 2 root root 16384 5月 15 01:04 lost+found
vi /etc/exports
/mydata 192.168.31.0/24(no_root_squash,rw)
接下来配置节点上的mysql数据库
node1:192.168.31.111
选用的是通用二进制格式mysql:mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz
[root@node1 ~]# tar xf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
[root@node1 ~]# cd /usr/local/
[root@node1 local]# ls
bin etc games include lib lib64 libexec mysql-5.6.30-linux-glibc2.5-x86_64 sbin share src
[root@node1 local]# ln -s mysql-5.6.30-linux-glibc2.5-x86_64/ /usr/local/mysql
[root@node1 local]# cd mysql
[root@node1 mysql]# ls
bin COPYING data docs include lib man mysql-test README scripts share sql-bench support-files
在节点上各自也分别创建mysql用户与组
groupadd -g 3306 mysql
useradd -g mysql -u 3306 -s /sbin/nologin -M mysql
vi my.cnf加上如下两行
socket = /tmp/mysql.sock
datadir = /mydata/data
[root@node1 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@node1 mysql]# /usr/local/mysql/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.30 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.09 sec)
mysql> grant all on *.* to root@'%' identified by 'redhat';
接下来配置node2:192.168.31.112
选用的是通用二进制格式mysql:mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz
[root@node1 ~]# tar xf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
[root@node1 ~]# cd /usr/local/
[root@node1 local]# ls
bin etc games include lib lib64 libexec mysql-5.6.30-linux-glibc2.5-x86_64 sbin share src
[root@node1 local]# ln -s mysql-5.6.30-linux-glibc2.5-x86_64/ /usr/local/mysql
[root@node1 local]# cd mysql
[root@node1 mysql]# ls
bin COPYING data docs include lib man mysql-test README scripts share sql-bench support-files
mkdir /mydata
由于数据文件在nfs服务器上面,及node2并不需要初始化mysql,只需要配备配置文件,以及启动脚本即可
于是停止node1上面的mysql以及卸载数据目录
service mysqld stop
umount /mydata
将配置文件以及启动脚本复制到节点2上
scp my.cnf node2:/etc/
scp /etc/init.d/mysqld node2:/etc/init.d/
mysql准备就绪后,就挂载数据目录
mount -t nfs 192.168.31.114:/mydata /mydata
然后可以开始启动mysql了
[root@node2 data]# service mysqld start
Starting MySQL..... SUCCESS!
[root@node2 data]# /usr/local/mysql/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.30 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
[root@NFS mydata]# mysql -uroot -h192.168.31.113 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.30 MySQL Community Server (GPL)
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| huang |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.21 sec)