码迷,mamicode.com
首页 > 数据库 > 详细

mysql高可用方案之HeartBeat+nfs

时间:2014-12-28 18:21:53      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:mysql高可用方案之heartbeat+nfs

环境规划:

node1  192.168.1.105  10.10.10.1

node2  192.168.1.106  10.10.10.2

集群软件:heartbeat-3.0.4

数据库:mysql-5.7.4二进制包

 

1.节点上的网络配置

node1节点:

[root@node1 ~]# hostname
node1
[root@node1 ~]# ifconfig  eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:29:79:7F:C7 
          inet addr:192.168.1.105  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe79:7fc7/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric: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

[root@node1 ~]# vim /etc/hosts

192.168.1.105 node1
192.168.1.106 node2
10.10.10.1 node1
10.10.10.2 node2

[root@node1 ~]#

 

node2节点:

[root@node2 ha.d]# hostname
node2
[root@node2 ha.d]# ifconfig  eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:29:2E:A0:37 
          inet addr:192.168.1.106  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe2e:a037/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric: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

[root@node2 ha.d]# vim /etc/hosts

192.168.1.105 node1
192.168.1.106 node2
10.10.10.1 node1
10.10.10.2 node2

[root@node2 ha.d]#

 

2.创建mysql用户和mysql数据共享目录

node1节点:

[root@node1 ~]# groupadd  -g 502 mysql

[root@node1 ~]# useradd  -r -s /sbin/nologin -u 502 -g mysql mysql

[root@node1 ~]# mkdir /mysql/data -p

 

node2节点:

[root@node2 ~]# groupadd  -g 502 mysql

[root@node2 ~]# useradd  -r -s /sbin/nologin -u 502 -g mysql mysql

[root@node2 ~]# mkdir /mysql/data -p

 

3.安装mysql数据库软件

node1节点:

[root@node1 ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.4-m14-linux-glibc2.5-i686.tar.gz

[root@node1 ~]# tar xvf mysql-5.7.4-m14-linux-glibc2.5-i686.tar.gz

[root@node1 ~]# mv mysql-5.7.4-m14-linux-glibc2.5-i686 /usr/local/mysql-5.7.4

[root@node1 ~]# cd /usr/local/mysql-5.7.4

[root@node1 mysql-5.7.4]# cp -a support-files/my-default.cnf  /etc/my.cnf

[root@node1 mysql-5.7.4]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql-5.7.4/ --datadir=/mysql/data/

[root@node1 mysql-5.7.4]# 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 root  root         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

[root@node1 mysql-5.7.4]# vim /etc/my.cnf

basedir = /usr/local/mysql-5.7.4
datadir = /var/lib/mysql
port = 3306

[root@node1 mysql-5.7.4]# chown mysql:mysql /var/lib/mysql/

[root@node1 mysql-5.7.4]# cp -a support-files/mysql.server  /etc/init.d/mysqld

[root@node1 mysql-5.7.4]# chkconfig --add mysqld

[root@node1 mysql-5.7.4]# chkconfig  mysqld off

[root@node1 mysql-5.7.4]# vim /etc/exports

/mysql/data       192.168.1.0/24(no_root_squash,rw)

[root@node1 mysql-5.7.4]# exportfs  -arv
exporting 192.168.1.0/24:/mysql/data
[root@node1 mysql-5.7.4]# mount.nfs 192.168.1.105:/mysql/data/ /var/lib/mysql/

[root@node1 mysql-5.7.4]# /etc/init.d/mysqld restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL..... SUCCESS!
[root@node1 mysql-5.7.4]# netstat -antp | grep 3306
tcp        0      0 :::3306                     :::*                        LISTEN      27729/mysqld     

[root@node1 mysql-5.7.4]# /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 

[root@node1 mysql-5.7.4]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
[root@node1 mysql-5.7.4]# umount /var/lib/mysql/
[root@node1 mysql-5.7.4]# scp /etc/my.cnf node2:/etc/
root@node2‘s password:
my.cnf                                                                              100%           1142        1.1KB/s         00:00   
[root@node1 mysql-5.7.4]# scp /etc/init.d/mysqld node2:/etc/init.d/mysqld
root@node2‘s password:
mysqld                                                                             100%           11KB        10.7KB/s       00:00   
[root@node1 mysql-5.7.4]#

 

node2节点:

[root@node2 ha.d]# showmount  -e node1
Export list for node1:

/mysql/data       192.168.1.0/24(no_root_squash,rw)

[root@node2 ha.d]# mount.nfs 192.168.1.105:/mysql/data/ /var/lib/mysql/
[root@node2 ha.d]# /etc/init.d/mysqld restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL........ SUCCESS!
[root@node2 ha.d]# netstat -antup | grep 3306
tcp        0      0 :::3306                     :::*                        LISTEN      7355/mysqld        
[root@node2 ha.d]#

 

4.安装和配置HeartBeat集群软件

node1节点:

[root@node1 ~]# yum install heartbeat*

[root@node1 ~]# cp -a /usr/share/doc/heartbeat-3.0.4/{authkeys,haresources,ha.cf} /etc/ha.d/

[root@node1 ~]# cd /etc/ha.d/
[root@node1 ha.d]# vim authkeys

auth 3
3 md5 Hello!

[root@node1 ha.d]# vim ha.cf

bcast   eth1 

node node1
node node2

[root@node1 ha.d]# vim haresources

node1 IPaddr::192.168.1.100/24/eth0 Filesystem::192.168.1.105:/mysql/data::/var/lib/mysql::nfs mysqld

[root@node1 ha.d]#

 

node2节点:

[root@node2 ~]# yum install heartbeat*

[root@node2 ~]# scp node1:/etc/ha.d/{authkeys,haresources,ha.cf} /etc/ha.d/

 

5.启动heartbea服务

node1节点:

[root@node1 ha.d]# /etc/init.d/mysqld stop
 ERROR! MySQL server PID file could not be found!
[root@node1 ha.d]# /etc/init.d/heartbeat stop
Stopping High-Availability services: Done.

[root@node1 ha.d]# /etc/init.d/heartbeat  start
Starting High-Availability services: INFO:  Resource is stopped
Done.

[root@node1 ha.d]#

 

node2节点:

[root@node2 ~]# /etc/init.d/mysqld stop
Shutting down MySQL. SUCCESS!
[root@node2 ~]# /etc/init.d/heartbeat stop
Stopping High-Availability services: Done.

[root@node2 ~]# /etc/init.d/heartbeat start
Starting High-Availability services: INFO:  Resource is stopped
Done.

[root@node2 ~]#

 

6.创建mysql远程连接帐号

node1节点:

[root@node1 ha.d]# /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

[root@node1 ha.d]# /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节点:

[root@node1 ~]# netstat -antup | grep 3306
tcp        0      0 :::3306                     :::*                        LISTEN      28750/mysqld       
[root@node1 ~]# /usr/share/heartbeat/hb_standby
Going standby [all].
[root@node1 ~]# netstat -antup | grep 3306
[root@node1 ~]#

 

node2节点:

[root@node2 ~]# netstat -antp | grep 3306
tcp        0      0 :::3306                     :::*                        LISTEN      11091/mysqld       

[root@node2 ~]# /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>

 

本文出自 “一起走过的日子” 博客,请务必保留此出处http://tongcheng.blog.51cto.com/6214144/1596959

mysql高可用方案之HeartBeat+nfs

标签:mysql高可用方案之heartbeat+nfs

原文地址:http://tongcheng.blog.51cto.com/6214144/1596959

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!