1、涉及机器
192.168.130.61 node1.ha.com mysql
192.168.130.62 node2.ha.com mysql
192.168.130.63 node3.ha.com nfs
2、安装heartbeat V2
rpm -ivh https://mirrors.aliyun.com/epel/6Server/x86_64/Packages/e/epel-release-6-8.noarch.rpm
yum -y install net-snmp-libs libnet PyXML libtool-ltdl
rpm -ivh heartbeat-2.1.4-12.el6.x86_64.rpm heartbeat-pils-2.1.4-12.el6.x86_64.rpm heartbeat-stonith-2.1.4-12.el6.x86_64.rpm
3、配置hearbeat V2
openssl rand -hex 16
c20954be14c956fc9dec4f8b6565da34
cp /usr/share/doc/heartbeat-2.1.4/{authkeys,ha.cf} /etc/ha.d/
cd /etc/ha.d
echo -e "auth 2\n2 sha1 c20954be14c956fc9dec4f8b6565da34" >> authkeys
chmod 600 authkeys
grep -v ^# ha.cf | grep -v ^$
logfile /var/log/ha-log
keepalive 1
deadtime 10
warntime 5
initdead 120
udpport 694
mcast eth0 225.0.0.1 694 1 0
auto_failback on
node node1.ha.com node2.ha.com
ping 192.168.130.2
compression bz2
compression_threshold 2
crm on
scp -p authkeys ha.cf node2.ha.com:/etc/ha.d/
service iptables stop
chkconfig iptables off
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0
4、安装NFS共享存储
mkdir /mydata
groupadd -r -g 306 mysql
useradd -u 306 -g mysql mysql
setfacl -m u:mysql:rwx /mydata
yum -y install nfs-utils rpcbind
echo "/mydata 192.168.130.0/24(rw,sync,no_root_squash)" >> /etc/exports
service rpcbind start
service nfs start
chkconfig rpcbind on
chkconfig nfs on
需要确保node1和node2的mysql和root用户对共享目录有读写权限,分别在root和mysql用户下对目录就行读写操作
groupadd -r -g 306 mysql
useradd -u 306 -g mysql mysql
5、安装mysql
5.1、第一台配置
mkdir /mydata
mount -t nfs 192.168.130.63:/mydata /mydata
mkdir /mydata/binlog
chown mysql:mysql /mydata/binlog -R
tar xf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
mv /usr/local/mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql
chown root:mysql /usr/local/mysql -R
cd /usr/local/mysql/
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
vim /etc/my.cnf
[mysqld]
bind-address = 0.0.0.0
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/mydata/data
log-bin=/mydata/binlog/log-bin
server-id=1
skip-name-resolve
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/mydata/data
/etc/init.d/mysqld start
/usr/local/mysql/bin/mysql
GRANT ALL ON *.* TO 'testuser'@'192.168.%.%' IDENTIFIED BY 'testpass';
FLUSH PRIVILEGES;
mysql> create database testdb;
Query OK, 1 row affected (0.10 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| testdb |
+--------------------+
5 rows in set (0.00 sec)
mysql>
/etc/init.d/mysqld stop
chkconfig mysqld off
umount /mydata
5.2、第二台配置:
mkdir /mydata
mount -t nfs 192.168.130.63:/mydata /mydata
tar xf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
mv /usr/local/mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql
chown root:mysql /usr/local/mysql -R
cd /usr/local/mysql/
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
vim /etc/my.cnf
[mysqld]
bind-address = 0.0.0.0
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/mydata/data
log-bin=/mydata/binlog/log-bin
server-id=1
skip-name-resolve
/etc/init.d/mysqld start
/usr/local/mysql/bin/mysql
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| testdb |
+--------------------+
5 rows in set (0.00 sec)
mysql>
/etc/init.d/mysqld stop
chkconfig mysqld off
umount /mydata
6、基于heartbeat-gui配置heartbeat V2
需要安装xmanager和xsell
yum -y install pygtk2-libglade
rpm -ivh heartbeat-gui-2.1.4-12.el6.x86_64.rpm
启用heartbeat-gui的机器需要设置hacluster的密码
passwd hacluster
service heartbeat start
yum -y install xorg-x11-xauth dejavu-lgc-sans-fonts
hb_gui &
7、测试
mysql -h 192.168.130.15 -u testuser -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| testdb |
+--------------------+
5 rows in set (0.01 sec)