设为首页 收藏本站
查看: 2159|回复: 3

[经验分享] Heartbeat+MySQL+NFS 实现高可用(HA)的MySQL集群

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2013-8-13 09:14:45 | 显示全部楼层 |阅读模式
本帖最后由 buns 于 2013-8-13 09:16 编辑

大纲

一、环境准备二、拓扑准备三、安装与配置heartbrat四、配置NFS服务五、安装与配置mysql六、crm配置资源
一、环境准备1.操作系统
  • CentOS 5.5 X86_64 位系统
2.软件环境
  • heartbeat-2.1.4-11.el5
  • heartbeat-gui-2.1.4-11.el5
  • mysql-5.5.33(注:这里用的mysql版本是通用二进制包,直接解压就能用的
3.高可用集群使用条件(1).节点名称必须跟 uname -n 命令的执行结果一致
[Shell] 纯文本查看 复制代码
node1:
[iyunv@node1 src]# uname -n
node1.test.com
[iyunv@node1 src]# vim /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail. 
127.0.0.1               localhost.localdomain localhost 
::1             localhost6.localdomain6 localhost6 
192.168.18.201  node1.test.com  node1 
192.168.18.202  node2.test.com  node2
node2:

[iyunv@node2 ~]# uname -n
node2.test.com 
[iyunv@node2 ~]# vim /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail. 
127.0.0.1               localhost.localdomain localhost 
::1             localhost6.localdomain6 localhost6 
192.168.18.201  node1.test.com  node1 
192.168.18.202  node2.test.com  node2
(2).各节点之间ssh互信

node1:
ssh-keygen  -t rsa -f ~/.ssh/id_rsa  -P ''  
ssh-copy-id -i .ssh/id_rsa.pub [email]root@node2.test.com[/email]
node2:
ssh-keygen  -t rsa -f ~/.ssh/id_rsa  -P '' 
ssh-copy-id -i .ssh/id_rsa.pub [email]root@node2.test.com[/email]
(3).各节点之间时间同步

node1:
[iyunv@node1 ~]# ntpdate 202.120.2.101
node2:
[iyunv@node2 ~]# ntpdate 202.120.2.101
4.增加EPEL yum源
node1,node2:

[iyunv@node src]# wget [url]http://download.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm[/url]
[iyunv@node src]# rpm -ivh epel-release-5-4.noarch.rpm
warning: epel-release-5-4.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 217521f6
Preparing...                ########################################### [100%]
1:epel-release           ########################################### [100%]
[iyunv@node src]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
[iyunv@node src]# yum list
5.关闭防火墙与SELinux

node1,node2:
[iyunv@node ~]# service iptables stop
[iyunv@node ~]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
SELINUXTYPE=targeted

二、拓扑准备


2033581_1376296668o17u.jpg

说明:拓扑与上几篇博客一致,这里就不详细说明了。

三、安装与配置heartbrat

[Shell] 纯文本查看 复制代码
1.heartbeat v2安装与配置
(1).安装heartbrat
node1:

[iyunv@node ~]# yum -y install heartbeat*
node2:

[iyunv@node ~]# yum -y install heartbeat*
(2).配置heartbeat
说明:默认安装好heartbeat没有配置文件,但是样例文件
root@node1 ~]# cd /usr/share/doc/heartbeat-2.1.4/
[iyunv@node1 heartbeat-2.1.4]# ls 
apphbd.cf  COPYING           faqntips.txt         HardwareGuide.html  hb_report.txt       README             rsync.txt 
authkeys   COPYING.LGPL      GettingStarted.html  HardwareGuide.txt   heartbeat_api.html  Requirements.html  startstop 
AUTHORS    DirectoryMap.txt  GettingStarted.txt   haresources         heartbeat_api.txt   Requirements.txt 
ChangeLog  faqntips.html     ha.cf                hb_report.html      logd.cf            rsync.html
注:这里我们只需要两个文件,ha.cf 与 authkeys

[iyunv@node1 ha.d]# dd if=/dev/random bs=512count=1| openssl md5 #生成密钥随机数
0+1records in
0+1records out
128bytes (128B) copied, 0.000214seconds, 598kB/s
a4d20b0dd3d5e35e0f87ce4266d1dd64
[iyunv@node1 ~]# vim /etc/ha.d/authkeys
auth 1
1 md5 a4d20b0dd3d5e35e0f87ce4266d1dd64
[iyunv@node1 ha.d]# chmod 600 authkeys  #修改密钥文件的权限为600

[iyunv@node1 ha.d]# vim ha.cf
主要修改两处(其它都可以默认):
(1).修改心跳信息的传播方式(这里是组播)
mcast eth0 225.100.100.100 694 1 0
(2).配置集群中的节点数
node    node1.test.com
node    node2.test.com
(3).启用crm
crm on
2.复制以上两个配置文件到node2上
1
[iyunv@node1 ha.d]# scp authkeys ha.cf  node2:/etc/ha.d/
3.启动节点

[iyunv@node1 ha.d]# ssh node2 "service heartbeat start"
Strting High-Availability services:
[确定]
logd is already stopped
[iyunv@node1 ha.d]# service heartbeat start     
Starting High-Availability services:
2013/08/07_17:19:22 INFO:  Resource is stopped
[确定]
4.查看一下端口
node1:

[iyunv@node1 ~]# netstat -ntulp
Active Internet connections (only servers) 
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:616                 0.0.0.0:*                   LISTEN      2554/rpc.statd   
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      2515/portmap     
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      2850/cupsd       
tcp        0      0 0.0.0.0:5560                0.0.0.0:*                   LISTEN      3170/mgmtd       
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      2940/sendmail: acce  
tcp        0      0 127.0.0.1:6010              0.0.0.0:*                   LISTEN      17808/0          
tcp        0      0 :::22                       :::*                        LISTEN      2837/sshd        
tcp        0      0 ::1:6010                    :::*                        LISTEN      17808/0          
udp        0      0 0.0.0.0:50185               0.0.0.0:*                               2925/heartbeat: wri  
udp        0      0 0.0.0.0:47376               0.0.0.0:*                               3069/avahi-daemon:
udp        0      0 0.0.0.0:694                 0.0.0.0:*                               2925/heartbeat: wri  
udp        0      0 0.0.0.0:610                 0.0.0.0:*                               2554/rpc.statd   
udp        0      0 0.0.0.0:613                 0.0.0.0:*                               2554/rpc.statd   
udp        0      0 0.0.0.0:5353                0.0.0.0:*                               3069/avahi-daemon:
udp        0      0 0.0.0.0:111                 0.0.0.0:*                               2515/portmap     
udp        0      0 0.0.0.0:631                 0.0.0.0:*                               2850/cupsd       
udp        0      0 :::5353                     :::*                                    3069/avahi-daemon:
udp        0      0 :::46332                    :::*                                    3069/avahi-daemon:
node2:

[iyunv@node1 ~]# netstat -ntulp
Active Internet connections (only servers) 
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:616                 0.0.0.0:*                   LISTEN      2554/rpc.statd   
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      2515/portmap     
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      2850/cupsd       
tcp        0      0 0.0.0.0:5560                0.0.0.0:*                   LISTEN      3170/mgmtd       
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      2940/sendmail: acce  
tcp        0      0 127.0.0.1:6010              0.0.0.0:*                   LISTEN      17808/0          
tcp        0      0 :::22                       :::*                        LISTEN      2837/sshd        
tcp        0      0 ::1:6010                    :::*                        LISTEN      17808/0          
udp        0      0 0.0.0.0:50185               0.0.0.0:*                               2925/heartbeat: wri  
udp        0      0 0.0.0.0:47376               0.0.0.0:*                               3069/avahi-daemon:
udp        0      0 0.0.0.0:694                 0.0.0.0:*                               2925/heartbeat: wri  
udp        0      0 0.0.0.0:610                 0.0.0.0:*                               2554/rpc.statd   
udp        0      0 0.0.0.0:613                 0.0.0.0:*                               2554/rpc.statd   
udp        0      0 0.0.0.0:5353                0.0.0.0:*                               3069/avahi-daemon:
udp        0      0 0.0.0.0:111                 0.0.0.0:*                               2515/portmap     
udp        0      0 0.0.0.0:631                 0.0.0.0:*                               2850/cupsd       
udp        0      0 :::5353                     :::*                                    3069/avahi-daemon:
udp        0      0 :::46332                    :::*                                    3069/avahi-daemon:

注:上面端口号可以看出,heartbeat已经正常启动。

5.查看一下集群状态

2033581_13762966681MI4.jpg

注:两个节点都在线,资源暂时还没有配置。

6.测试一下hb_gui图形配置界面
[iyunv@node1 ~]# hb_gui &
[1] 20377




2033581_1376296669UuU8.jpg

四、配置NFS服务

[Shell] 纯文本查看 复制代码
1.创建LVM逻辑卷(用来存放mysql数据文件)

[iyunv@nfs ~]# pvcreate /dev/sdb #创建物理卷
[iyunv@nfs ~]# vgcreate myvg /dev/sdb #创建卷组 
[iyunv@nfs ~]# lvcreate -L 10G -n mydata myvg #创建逻辑卷 
[iyunv@nfs ~]# mke2fs -j /dev/myvg/mydata #格式化逻辑卷 
[iyunv@nfs ~]# lvs #查看逻辑卷 
[iyunv@nfs ~]# mkdir /mydata #创建挂载目录 
[iyunv@nfs ~]# mount /dev/myvg/mydata /mydata/ #挂载 
[iyunv@nfs ~]# cd /mydata/ #进入挂载目录 
[iyunv@nfs ~]# mkdir data #创建数据目录
2.创建mysql的用户与mysql组
node1,node2,nfs:(三个节点都要创建相同的用户与组)
(1).创建mysql组   
1
[iyunv@nfs ~]# groupadd -g 3306 mysql
(2).创建mysql用户   

[iyunv@nfs ~]# useradd -u 3306 -g mysql -s /sbin/nologin -M mysql
(3).查看

[iyunv@nfs ~]# id mysql
uid=3306(mysql) gid=3306(mysql) groups=3306(mysql)
说明:在node1与node2也要创建相同的用户和组
3.修改数据目录的用户与组

[iyunv@nfs ~]# chow -R mysql.mysql /mydata/data/
[iyunv@nfs ~]# ll /mydata/
总计 12 
drwxr-xr-x 6 mysql mysql 4096 08-12 13:40 data
4.修改nfs配置文件

[iyunv@nfs ~]# vim /etc/exports
/mydata              192.168.18.0/24(no_root_squash,rw,async)
5.重新输出一下nfs

[iyunv@nfs ~]# exportfs -arv
exporting 192.168.18.0/24:/mydata
6.查看输出的nfs共享存储

[iyunv@nfs ~]# showmount -e 192.168.18.208
Export list for 192.168.18.208: 
/mydata 192.168.18.0/24
7.测试挂载
node1:
[iyunv@node1 ~]# mkdir /mydata
[iyunv@node1 ~]# mount -t nfs 192.168.18.208:/mydata/ /mydata/
[iyunv@node1 ~]# ll /mydata/
total 12 
drwxr-xr-x 6 mysql mysql 4096 Aug 12 13:40 data
node2:

[iyunv@node2~]# mkdir /mydata
[iyunv@node2 ~]# mount -t nfs 192.168.18.208:/mydata/ /mydata/
[iyunv@node2 ~]# ll /mydata/
total 12 
drwxr-xr-x 6 mysql mysql 4096 Aug 12 13:50 data
五、安装与配置mysql
node1:
1.解压并链接mysql

[iyunv@node1 ~]# tar -zxvf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local/ #直接解压到/usr/local目录下
[iyunv@node1 ~]# ln -sv mysql-5.5.33-linux2.6-x86_64 mysql #设置一个软链接
[iyunv@node1 ~]# cd /usr/local/mysql
[iyunv@node1 mysql]# ll 
total 204 
drwxr-xr-x  2 root mysql   4096 Aug 11 14:45 bin 
-rw-r--r--  1 root mysql  17987 Jul 15 20:01 COPYING 
drwxr-xr-x  3 root mysql   4096 Aug 12 13:11 data 
drwxr-xr-x  2 root mysql   4096 Aug 11 14:45 docs 
drwxr-xr-x  3 root mysql   4096 Aug 11 14:45 include 
-rw-r--r--  1 root mysql 134493 Jul 15 20:01 INSTALL-BINARY 
drwxr-xr-x  3 root mysql   4096 Aug 11 15:27 lib 
drwxr-xr-x  4 root mysql   4096 Aug 11 14:45 man 
drwxr-xr-x 10 root mysql   4096 Aug 11 14:45 mysql-test 
-rw-r--r--  1 root mysql   2496 Jul 15 20:01 README 
drwxr-xr-x  2 root mysql   4096 Aug 11 14:45 scripts 
drwxr-xr-x 27 root mysql   4096 Aug 11 14:45 share 
drwxr-xr-x  4 root mysql   4096 Aug 11 14:45 sql-bench 
drwxr-xr-x  3 root mysql   4096 Aug 11 14:45 support-files
2.初始化mysql
1
[iyunv@node1 ~]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/mydata/data/ --user=mysql
3.提供mysql配置文件

[iyunv@node1 ~]# cp /usr/local/mysql/support-files/my-large.cnf  /etc/my.cnf
[iyunv@node1 ~]# vim /etc/my.cnf
datadir = /mydata/my.cnf #指定数据目录
innodb_file_per_table = 1 #innodb表单独表空间
4.提供mysql启动脚本
[iyunv@node1 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[iyunv@node1 ~]# chmod +x /etc/init.d/mysqld
5.启动mysql
[iyunv@node1 mysql]# service mysqld start
Starting MySQL...                                          [  OK  ]
6.查看数据目录

[iyunv@node1 ~]# mount
/dev/sda2 on / type ext3 (rw) 
proc on /proc type proc (rw) 
sysfs on /sys type sysfs (rw) 
devpts on /dev/pts type devpts (rw,gid=5,mode=620) 
/dev/sda3 on /data type ext3 (rw) 
/dev/sda1 on /boot type ext3 (rw) 
tmpfs on /dev/shm type tmpfs (rw) 
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) 
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) 
192.168.18.208:/mydata/ on /mydata type nfs (rw,addr=192.168.18.208) 
[iyunv@node1 ~]# cd /mydata/data/ 
[iyunv@node1 data]# ll 
total 28784 
-rw-rw---- 1 mysql mysql 18874368 Aug 12 13:40 ibdata1 
-rw-rw---- 1 mysql mysql  5242880 Aug 12 14:27 ib_logfile0 
-rw-rw---- 1 mysql mysql  5242880 Aug 12 08:05 ib_logfile1 
-rw-r--r-- 1 root  root      4721 Aug 12 07:55 my.cnf 
drwx------ 2 mysql mysql     4096 Aug 12 08:07 mydb 
drwx------ 2 mysql root      4096 Aug 12 07:39 mysql 
-rw-rw---- 1 mysql mysql      126 Aug 12 13:40 mysql-bin.000001 
-rw-rw---- 1 mysql mysql       19 Aug 12 13:18 mysql-bin.index 
-rw-r----- 1 mysql root     18748 Aug 12 14:28 node1.test.com.err 
-rw-rw---- 1 mysql mysql        6 Aug 12 14:27 node1.test.com.pid 
drwx------ 2 mysql mysql     4096 Aug 12 07:39 performance_schema 
drwx------ 2 mysql root      4096 Aug 12 07:39 test
7.登录测试一下
[iyunv@node1 data]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g. 
Your MySQL connection id is 1 
Server version: 5.5.33-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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 | 
| mydb               | 
| mysql              | 
| performance_schema | 
| test               | 
+--------------------+ 
5 rows in set (0.02 sec)
注:node1节点mysql配置完成,下面我们来配置node2
node2:
1.卸载数据文件目录

[iyunv@node1 data]# service mysqld stop
Shutting down MySQL.                                       [  OK  ] 
[iyunv@node1 data]# cd 
[iyunv@node1 ~]# umount /mydata/ 
[iyunv@node1 ~]# mount 
/dev/sda2 on / type ext3 (rw) 
proc on /proc type proc (rw) 
sysfs on /sys type sysfs (rw) 
devpts on /dev/pts type devpts (rw,gid=5,mode=620) 
/dev/sda3 on /data type ext3 (rw) 
/dev/sda1 on /boot type ext3 (rw) 
tmpfs on /dev/shm type tmpfs (rw) 
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) 
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
2.挂载数据目录到node2上

[iyunv@node2 ~]# mount 
/dev/sda2 on / type ext3 (rw) 
proc on /proc type proc (rw) 
sysfs on /sys type sysfs (rw) 
devpts on /dev/pts type devpts (rw,gid=5,mode=620) 
/dev/sda3 on /data type ext3 (rw) 
/dev/sda1 on /boot type ext3 (rw) 
tmpfs on /dev/shm type tmpfs (rw) 
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) 
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) 
[iyunv@node2 ~]# mount -t nfs 192.168.18.208:/mydata/ /mydata/ 
[iyunv@node2 ~]# mount 
/dev/sda2 on / type ext3 (rw) 
proc on /proc type proc (rw) 
sysfs on /sys type sysfs (rw) 
devpts on /dev/pts type devpts (rw,gid=5,mode=620) 
/dev/sda3 on /data type ext3 (rw) 
/dev/sda1 on /boot type ext3 (rw) 
tmpfs on /dev/shm type tmpfs (rw) 
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) 
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) 
192.168.18.208:/mydata/ on /mydata type nfs (rw,addr=192.168.18.208) 
[iyunv@node2 ~]# cd /mydata/data/ 
[iyunv@node2 data]# ll 
total 28780 
-rw-rw---- 1 mysql mysql 18874368 Aug 12 14:30 ibdata1 
-rw-rw---- 1 mysql mysql  5242880 Aug 12 14:30 ib_logfile0 
-rw-rw---- 1 mysql mysql  5242880 Aug 12 08:05 ib_logfile1 
-rw-r--r-- 1 root  root      4721 Aug 12 07:55 my.cnf 
drwx------ 2 mysql mysql     4096 Aug 12 08:07 mydb 
drwx------ 2 mysql root      4096 Aug 12 07:39 mysql 
-rw-rw---- 1 mysql mysql      126 Aug 12 13:40 mysql-bin.000001 
-rw-rw---- 1 mysql mysql       19 Aug 12 13:18 mysql-bin.index 
-rw-r----- 1 mysql root     19162 Aug 12 14:30 node1.test.com.err 
-rw-r----- 1 mysql root      4442 Aug 12 13:40 node2.test.com.err 
drwx------ 2 mysql mysql     4096 Aug 12 07:39 performance_schema 
drwx------ 2 mysql root      4096 Aug 12 07:39 test
3.将配置文件与启动脚本复制到node2上

[iyunv@node1 ~]# scp /etc/my.cnf node2:/etc/
my.cnf                                                                                 100% 4721     4.6KB/s   00:00 
[iyunv@node1 ~]# scp /etc/init.d/mysqld node2:/etc/init.d/ 
mysqld                                                                                 100%   11KB  10.6KB/s   00:00
4.启动mysql

[iyunv@node2 data]# service mysqld start
Starting MySQL..                                           [  OK  ] 
[iyunv@node2 data]# ll 
total 28784 
-rw-rw---- 1 mysql mysql 18874368 Aug 12 14:30 ibdata1 
-rw-rw---- 1 mysql mysql  5242880 Aug 12 14:33 ib_logfile0 
-rw-rw---- 1 mysql mysql  5242880 Aug 12 08:05 ib_logfile1 
-rw-r--r-- 1 root  root      4721 Aug 12 07:55 my.cnf 
drwx------ 2 mysql mysql     4096 Aug 12 08:07 mydb 
drwx------ 2 mysql root      4096 Aug 12 07:39 mysql 
-rw-rw---- 1 mysql mysql      126 Aug 12 13:40 mysql-bin.000001 
-rw-rw---- 1 mysql mysql       19 Aug 12 13:18 mysql-bin.index 
-rw-r----- 1 mysql root     19162 Aug 12 14:30 node1.test.com.err 
-rw-r----- 1 mysql root      5738 Aug 12 14:33 node2.test.com.err 
-rw-rw---- 1 mysql mysql        5 Aug 12 14:33 node2.test.com.pid 
drwx------ 2 mysql mysql     4096 Aug 12 07:39 performance_schema 
drwx------ 2 mysql root      4096 Aug 12 07:39 test
5.登录并查看

[iyunv@node2 data]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g. 
Your MySQL connection id is 1 
Server version: 5.5.33-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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 | 
| mydb               | 
| mysql              | 
| performance_schema | 
| test               | 
+--------------------+ 
5 rows in set (0.01 sec)
6.停止mysql并卸载数据目录

[iyunv@node2 data]# service mysqld stop
Shutting down MySQL.                                       [  OK  ] 
[iyunv@node2 data]# cd 
[iyunv@node2 ~]# umount /mydata/ 
[iyunv@node2 ~]# mount 
/dev/sda2 on / type ext3 (rw) 
proc on /proc type proc (rw) 
sysfs on /sys type sysfs (rw) 
devpts on /dev/pts type devpts (rw,gid=5,mode=620) 
/dev/sda3 on /data type ext3 (rw) 
/dev/sda1 on /boot type ext3 (rw) 
tmpfs on /dev/shm type tmpfs (rw) 
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) 
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

注:到这里mysql配置全部完成,下面我们来具体配置一下,高可用的mysql集群

六、crm配置资源

1.新建组资源

2033581_13762966706Z9Z.jpg

2.给组资源增加ID名

2033581_1376296671dhMn.jpg

3.增加vip资源

2033581_1376296671Ssgd.jpg

4.增加共享存储资源

2033581_1376296672uOy5.jpg

5.增加mysql服务资源

2033581_13762966732dIk.jpg

6.资源增加完成

2033581_1376296674lGc0.jpg

7.启动全部资源

2033581_13762966758Z26.jpg

8.查看一下端口号



[Shell] 纯文本查看 复制代码
[iyunv@node2 ~]# netstat -ntulp
Active Internet connections (only servers) 
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:610                 0.0.0.0:*                   LISTEN      2548/rpc.statd   
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      8507/mysqld      
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      2509/portmap     
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      2842/cupsd       
tcp        0      0 0.0.0.0:36600               0.0.0.0:*                   LISTEN      -                
tcp        0      0 0.0.0.0:5560                0.0.0.0:*                   LISTEN      3157/mgmtd       
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      2933/sendmail: acce  
tcp        0      0 127.0.0.1:6011              0.0.0.0:*                   LISTEN      6706/1           
tcp        0      0 :::22                       :::*                        LISTEN      2829/sshd        
tcp        0      0 ::1:6011                    :::*                        LISTEN      6706/1           
udp        0      0 0.0.0.0:40975               0.0.0.0:*                               2918/heartbeat: wri  
udp        0      0 0.0.0.0:33809               0.0.0.0:*                               -                
udp        0      0 0.0.0.0:57110               0.0.0.0:*                               3062/avahi-daemon:
udp        0      0 0.0.0.0:694                 0.0.0.0:*                               2918/heartbeat: wri  
udp        0      0 0.0.0.0:604                 0.0.0.0:*                               2548/rpc.statd   
udp        0      0 0.0.0.0:607                 0.0.0.0:*                               2548/rpc.statd   
udp        0      0 0.0.0.0:5353                0.0.0.0:*                               3062/avahi-daemon:
udp        0      0 0.0.0.0:111                 0.0.0.0:*                               2509/portmap     
udp        0      0 0.0.0.0:631                 0.0.0.0:*                               2842/cupsd       
udp        0      0 :::46858                    :::*                                    3062/avahi-daemon:
udp        0      0 :::5353                     :::*                                    3062/avahi-daemon:
9.查看一下接口IP



[Shell] 纯文本查看 复制代码
[iyunv@node2 ~]# ifconfig 
eth0      Link encap:Ethernet  HWaddr 00:0C:29:EA:CE:79
          inet addr:192.168.18.202  Bcast:192.168.18.255  Mask:255.255.255.0 
          inet6 addr: fe80::20c:29ff:feea:ce79/64 Scope:Link 
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1 
          RX packets:133635 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:46597 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000  
          RX bytes:46103367 (43.9 MiB)  TX bytes:9677373 (9.2 MiB)
eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:EA:CE:79
          inet addr:192.168.18.200  Bcast:192.168.18.255  Mask:255.255.255.0 
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0 
          inet6 addr: ::1/128 Scope:Host 
          UP LOOPBACK RUNNING  MTU:16436  Metric:1 
          RX packets:287 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:287 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:0  
          RX bytes:27967 (27.3 KiB)  TX bytes:27967 (27.3 KiB)
10.查看一下资源状态

2033581_1376296675BfUK.jpg

说明:从图中可以看出,所有资源全部运行在node2上,现在我们就去访问一下mysql服务

11.node2上测试连接mysql

[backcolor=white !important]
[Shell] 纯文本查看 复制代码
[iyunv@node2 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g. 
Your MySQL connection id is 2 
Server version: 5.5.33-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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 | 
| mydb               | 
| mysql              | 
| performance_schema | 
| test               | 
+--------------------+ 
5 rows in set (0.03 sec)
12.mysql授权
1
2
mysql> grant all on *.* to root@"192.168.18.%" identified by "123456";
mysql> flush privileges;
13.测试一下集群效果,直接访问192.168.18.200

[iyunv@nfs ~]# /usr/local/mysql/bin/mysql -uroot -p123456 -h 192.168.18.200
Welcome to the MySQL monitor.  Commands end with ; or \g. 
Your MySQL connection id is 3 
Server version: 5.5.33-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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 | 
| mydb               | 
| mysql              | 
| performance_schema | 
| test               | 
+--------------------+ 
5 rows in set (0.01 sec)


14.模拟故障

(1).将node2节点,设置为standby,大家可以看,所有资源全部切换到node1上

2033581_1376296676EL88.jpg

[Shell] 纯文本查看 复制代码
(2).node1上查看一下端口

[iyunv@node1 ~]# netstat -ntulp
Active Internet connections (only servers) 
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:616                 0.0.0.0:*                   LISTEN      2554/rpc.statd   
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      22825/mysqld     
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      2515/portmap     
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      2850/cupsd       
tcp        0      0 0.0.0.0:5560                0.0.0.0:*                   LISTEN      3170/mgmtd       
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      2940/sendmail: acce  
tcp        0      0 0.0.0.0:58330               0.0.0.0:*                   LISTEN      -                
tcp        0      0 127.0.0.1:6011              0.0.0.0:*                   LISTEN      20469/1          
tcp        0      0 :::22                       :::*                        LISTEN      2837/sshd        
tcp        0      0 ::1:6011                    :::*                        LISTEN      20469/1          
udp        0      0 0.0.0.0:50185               0.0.0.0:*                               2925/heartbeat: wri  
udp        0      0 0.0.0.0:47376               0.0.0.0:*                               3069/avahi-daemon:
udp        0      0 0.0.0.0:694                 0.0.0.0:*                               2925/heartbeat: wri  
udp        0      0 0.0.0.0:41302               0.0.0.0:*                               -                
udp        0      0 0.0.0.0:610                 0.0.0.0:*                               2554/rpc.statd   
udp        0      0 0.0.0.0:613                 0.0.0.0:*                               2554/rpc.statd   
udp        0      0 0.0.0.0:5353                0.0.0.0:*                               3069/avahi-daemon:
udp        0      0 0.0.0.0:111                 0.0.0.0:*                               2515/portmap     
udp        0      0 0.0.0.0:631                 0.0.0.0:*                               2850/cupsd       
udp        0      0 :::5353                     :::*                                    3069/avahi-daemon:
udp        0      0 :::46332                    :::*                                    3069/avahi-daemon:
(3).node1上查看一下IP
[iyunv@node1 ~]# ifconfig 
eth0      Link encap:Ethernet  HWaddr 00:0C:29:23:76:4D
          inet addr:192.168.18.201  Bcast:192.168.18.255  Mask:255.255.255.0 
          inet6 addr: fe80::20c:29ff:fe23:764d/64 Scope:Link 
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1 
          RX packets:285092 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:319282 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000  
          RX bytes:155185716 (147.9 MiB)  TX bytes:297534308 (283.7 MiB)
eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:23:76:4D
          inet addr:192.168.18.200  Bcast:192.168.18.255  Mask:255.255.255.0 
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0 
          inet6 addr: ::1/128 Scope:Host 
          UP LOOPBACK RUNNING  MTU:16436  Metric:1 
          RX packets:63015 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:63015 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:0  
          RX bytes:46067195 (43.9 MiB)  TX bytes:46067195 (43.9 MiB)
(4).node1上测试访问一下mysql
[iyunv@node1 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g. 
Your MySQL connection id is 1 
Server version: 5.5.33-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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 | 
| mydb               | 
| mysql              | 
| performance_schema | 
| test               | 
+--------------------+ 
5 rows in set (0.02 sec)
(5).远程测试连接一下mysql

[iyunv@nfs ~]# /usr/local/mysql/bin/mysql -uroot -p123456 -h 192.168.18.200
Welcome to the MySQL monitor.  Commands end with ; or \g. 
Your MySQL connection id is 2 
Server version: 5.5.33-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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 | 
| mydb               | 
| mysql              | 
| performance_schema | 
| test               | 
+--------------------+ 
5 rows in set (0.01 sec)

注:高可用的mysql集群,演示全部完成,最后粘一下cib配置文件,供大家参考!

15.cib.xml 集群资源信息库



[Shell] 纯文本查看 复制代码
[iyunv@node1 ~]# cat /var/lib/heartbeat/crm/cib.xml
 <cib generated="true" admin_epoch="0" have_quorum="true" ignore_dtd="false" num_peers="2"cib_feature_revision="2.0" crm_feature_set="2.0" ccm_transition="2" dc_uuid="4a0c6580-3e21-4523-a3bb-a921b3f487c0" epoch="217" num_updates="1" cib-last-written="Mon Aug 12 16:03:08 2013"> 
   <configuration> 
     <crm_config> 
       <cluster_property_set id="cib-bootstrap-options"> 
         <attributes> 
           <nvpair id="cib-bootstrap-options-dc-version" name="dc-version" value="2.1.4-node: aa909246edb386137b986c5773344b98c6969999"/> 
           <nvpair id="cib-bootstrap-options-last-lrm-refresh" name="last-lrm-refresh"value="1376291880"/> 
           <nvpair id="cib-bootstrap-options-default-resource-stickiness" name="default-resource-stickiness" value="100"/> 
         </attributes> 
       </cluster_property_set> 
     </crm_config> 
     <nodes> 
       <node uname="node2.test.com" type="normal" id="4a0c6580-3e21-4523-a3bb-a921b3f487c0"> 
         <instance_attributes id="nodes-4a0c6580-3e21-4523-a3bb-a921b3f487c0"> 
           <attributes> 
             <nvpair name="standby" id="standby-4a0c6580-3e21-4523-a3bb-a921b3f487c0"value="on"/> 
           </attributes> 
         </instance_attributes> 
       </node> 
       <node id="d1437638-90d9-4bbb-84fc-c897d8f8d6a2" uname="node1.test.com" type="normal"> 
         <instance_attributes id="nodes-d1437638-90d9-4bbb-84fc-c897d8f8d6a2"> 
           <attributes> 
             <nvpair id="standby-d1437638-90d9-4bbb-84fc-c897d8f8d6a2" name="standby"value="off"/> 
           </attributes> 
         </instance_attributes> 
       </node> 
     </nodes> 
     <resources> 
       <group id="Mysql Service"> 
         <meta_attributes id="Mysql Service_meta_attrs"> 
           <attributes> 
             <nvpair id="Mysql Service_metaattr_target_role" name="target_role"value="started"/> 
             <nvpair id="Mysql Service_metaattr_ordered" name="ordered" value="true"/> 
             <nvpair id="Mysql Service_metaattr_collocated" name="collocated" value="true"/> 
           </attributes> 
         </meta_attributes> 
         <primitive id="vip" class="ocf" type="IPaddr" provider="heartbeat"> 
           <instance_attributes id="vip_instance_attrs"> 
             <attributes> 
               <nvpair id="880a5e57-0d7b-448d-adb2-27191987f2bd" name="ip"value="192.168.18.200"/> 
               <nvpair id="9ede4882-ab99-4450-9828-b89bc8d43df4" name="nic" value="eth0"/> 
               <nvpair id="9179225c-a7f3-4190-8f7b-4d6012498e59" name="cidr_netmask"value="24"/> 
             </attributes> 
           </instance_attributes> 
         </primitive> 
         <primitive id="nfs" class="ocf" type="Filesystem" provider="heartbeat"> 
           <instance_attributes id="nfs_instance_attrs"> 
             <attributes> 
               <nvpair id="0615970e-633d-41a6-acd7-d6823c73d701" name="device"value="192.168.18.208:/mydata"/> 
               <nvpair id="4e2146f8-3890-40a8-8340-6e2787979a60" name="directory"value="/mydata"/> 
               <nvpair id="b7a1d528-a43f-4a46-bee9-fcb7b7b40ee6" name="fstype" value="nfs"/> 
             </attributes> 
           </instance_attributes> 
           <meta_attributes id="nfs_meta_attrs"> 
             <attributes/> 
           </meta_attributes> 
         </primitive> 
         <primitive id="mysql" class="lsb" type="mysqld" provider="heartbeat"> 
           <meta_attributes id="mysql_meta_attrs"> 
             <attributes/> 
           </meta_attributes> 
         </primitive> 
       </group> 
     </resources> 
     <constraints/> 
   </configuration> 
 </cib>
补充说明:在下一篇博文中我们会重点讲解,corosync的详细使用!^_^……



运维网声明 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-8342-1-1.html 上篇帖子: Linux 高可用(HA)集群之heartbeat基于crm进行资源管理详解 下篇帖子: heartbeat实现基于mysql服务自动切换
发表于 2013-8-26 00:55:30 | 显示全部楼层
男人靠的住,母猪能上树!

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

尚未签到

发表于 2013-9-22 21:23:48 | 显示全部楼层
真是 收益 匪浅

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

尚未签到

发表于 2013-11-30 18:35:31 | 显示全部楼层
单身很痛苦,单身久了更痛苦,前几天我看见一头母猪,都觉得它眉清目秀的……

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

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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