设为首页 收藏本站
查看: 812|回复: 0

[经验分享] mysql高可用方案之HeartBeat+nfs

[复制链接]

尚未签到

发表于 2019-1-7 07:51:45 | 显示全部楼层 |阅读模式
  环境规划:
  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二进制包
  

  
  mysql dba技术群 378190849
  武汉-linux运维群 236415619

  
  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>
  
  




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-660132-1-1.html 上篇帖子: mysql热备+heartbeat集群 下篇帖子: 图形界面配置heartbeat高可用集群
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表