mysql高可用方案之HeartBeat+nfs
环境规划:node1192.168.1.10510.10.10.1
node2192.168.1.10610.10.10.2
集群软件:heartbeat-3.0.4
数据库:mysql-5.7.4二进制包
mysql dba技术群 378190849
武汉-linux运维群 236415619
1.节点上的网络配置
node1节点:
# hostname
node1
# ifconfigeth0
eth0 Link encap:EthernetHWaddr 00:0C:29:79:7F:C7
inet addr:192.168.1.105Bcast:192.168.1.255Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe79:7fc7/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
RX packets:21417 errors:0 dropped:0 overruns:0 frame:0
TX packets:15243 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4313797 (4.1 MiB)TX bytes:2401808 (2.2 MiB)
Interrupt:19 Base address:0x2000
# vim /etc/hosts
192.168.1.105 node1
192.168.1.106 node2
10.10.10.1 node1
10.10.10.2 node2
#
node2节点:
# hostname
node2
# ifconfigeth0
eth0 Link encap:EthernetHWaddr 00:0C:29:2E:A0:37
inet addr:192.168.1.106Bcast:192.168.1.255Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe2e:a037/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
RX packets:16702 errors:0 dropped:0 overruns:0 frame:0
TX packets:11660 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3872149 (3.6 MiB)TX bytes:1574050 (1.5 MiB)
Interrupt:19 Base address:0x2000
# vim /etc/hosts
192.168.1.105 node1
192.168.1.106 node2
10.10.10.1 node1
10.10.10.2 node2
#
2.创建mysql用户和mysql数据共享目录
node1节点:
# groupadd-g 502 mysql
# useradd-r -s /sbin/nologin -u 502 -g mysql mysql
# mkdir /mysql/data -p
node2节点:
# groupadd-g 502 mysql
# useradd-r -s /sbin/nologin -u 502 -g mysql mysql
# mkdir /mysql/data -p
3.安装mysql数据库软件
node1节点:
# wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.4-m14-linux-glibc2.5-i686.tar.gz
# tar xvf mysql-5.7.4-m14-linux-glibc2.5-i686.tar.gz
# mv mysql-5.7.4-m14-linux-glibc2.5-i686 /usr/local/mysql-5.7.4
# cd /usr/local/mysql-5.7.4
# cp -a support-files/my-default.cnf/etc/my.cnf
# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql-5.7.4/ --datadir=/mysql/data/
# ll /mysql/data/
total 122904
-rw-rw----. 1 mysql mysql 56 Dec 29 00:06 auto.cnf
-rw-rw----. 1 mysql mysql 12582912 Dec 29 00:06 ibdata1
-rw-rw----. 1 mysql mysql 50331648 Dec 29 00:06 ib_logfile0
-rw-rw----. 1 mysql mysql 50331648 Dec 29 00:03 ib_logfile1
-rw-rw----. 1 mysql mysql 12582912 Dec 29 00:06 ibtmp1
drwx------. 2 mysql mysql 4096 Dec 29 00:04 mysql
-rw-rw----. 1 rootroot 6 Dec 29 00:06 mysqld_safe.pid
-rw-r-----. 1 mysql root 3919 Dec 29 00:06 node1.err
-rw-rw----. 1 mysql mysql 6 Dec 29 00:06 node1.pid
drwx------. 2 mysql mysql 4096 Dec 29 00:04 performance_schema
# vim /etc/my.cnf
basedir = /usr/local/mysql-5.7.4
datadir = /var/lib/mysql
port = 3306
# chown mysql:mysql /var/lib/mysql/
# cp -a support-files/mysql.server/etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfigmysqld off
# vim /etc/exports
/mysql/data 192.168.1.0/24(no_root_squash,rw)
# exportfs-arv
exporting 192.168.1.0/24:/mysql/data
# mount.nfs 192.168.1.105:/mysql/data/ /var/lib/mysql/
# /etc/init.d/mysqld restart
ERROR! MySQL server PID file could not be found!
Starting MySQL..... SUCCESS!
# netstat -antp | grep 3306
tcp 0 0 :::3306 :::* LISTEN 27729/mysqld
# /usr/local/mysql-5.7.4/bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.7.4-m14 MySQL Community Server (GPL)
Copyright (c) 2000, 2014, 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> exit
Bye
# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
# umount /var/lib/mysql/
# scp /etc/my.cnf node2:/etc/
root@node2's password:
my.cnf 100% 1142 1.1KB/s 00:00
# scp /etc/init.d/mysqld node2:/etc/init.d/mysqld
root@node2's password:
mysqld 100% 11KB 10.7KB/s 00:00
#
node2节点:
# showmount-e node1
Export list for node1:
/mysql/data 192.168.1.0/24(no_root_squash,rw)
# mount.nfs 192.168.1.105:/mysql/data/ /var/lib/mysql/
# /etc/init.d/mysqld restart
ERROR! MySQL server PID file could not be found!
Starting MySQL........ SUCCESS!
# netstat -antup | grep 3306
tcp 0 0 :::3306 :::* LISTEN 7355/mysqld
#
4.安装和配置HeartBeat集群软件
node1节点:
# yum install heartbeat*
# cp -a /usr/share/doc/heartbeat-3.0.4/{authkeys,haresources,ha.cf} /etc/ha.d/
# cd /etc/ha.d/
# vim authkeys
auth 3
3 md5 Hello!
# vim ha.cf
bcast eth1
node node1
node node2
# vim haresources
node1 IPaddr::192.168.1.100/24/eth0 Filesystem::192.168.1.105:/mysql/data::/var/lib/mysql::nfs mysqld
#
node2节点:
# yum install heartbeat*
# scp node1:/etc/ha.d/{authkeys,haresources,ha.cf} /etc/ha.d/
5.启动heartbea服务
node1节点:
# /etc/init.d/mysqld stop
ERROR! MySQL server PID file could not be found!
# /etc/init.d/heartbeat stop
Stopping High-Availability services: Done.
# /etc/init.d/heartbeatstart
Starting High-Availability services: INFO:Resource is stopped
Done.
#
node2节点:
# /etc/init.d/mysqld stop
Shutting down MySQL. SUCCESS!
# /etc/init.d/heartbeat stop
Stopping High-Availability services: Done.
# /etc/init.d/heartbeat start
Starting High-Availability services: INFO:Resource is stopped
Done.
#
6.创建mysql远程连接帐号
node1节点:
# /usr/local/mysql-5.7.4/bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.7.4-m14 MySQL Community Server (GPL)
Copyright (c) 2000, 2014, 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> grant all privileges on *.* to 'remote'@'%' identified by 'system'; --创建远程帐号
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
# /usr/local/mysql-5.7.4/bin/mysql -u remote -p -h 192.168.1.100
Enter password:
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.4-m14 MySQL Community Server (GPL)
Copyright (c) 2000, 2014, 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> create database tong;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| tong |
+--------------------+
4 rows in set (0.01 sec)
mysql>
7.资源切换,测试mysqk服务是否正常
node1节点:
# netstat -antup | grep 3306
tcp 0 0 :::3306 :::* LISTEN 28750/mysqld
# /usr/share/heartbeat/hb_standby
Going standby .
# netstat -antup | grep 3306
#
node2节点:
# netstat -antp | grep 3306
tcp 0 0 :::3306 :::* LISTEN 11091/mysqld
# /usr/local/mysql-5.7.4/bin/mysql -u remote -p -h 192.168.1.100
Enter password:
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.22 Source distribution
Copyright (c) 2000, 2014, 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 |
| tong |
+--------------------+
4 rows in set (0.03 sec)
mysql>
页:
[1]