DRBD+HeartBeat+MYSQL

介绍

MySQL一主多从,能够保证数据库集群高可用,因为是多从,因此挂掉一个从库对集群没影响;若是挂了一个主库咱们能够把从库转换成主库,可是因为网络延迟问题主从角色切换会形成数据丢失,为了解决这个问题,解决主机单节点运行使用heartbeat作主节点高可用,主为了保证2个主节点数据同步可使用drbd作主节点数据同步。
多主可使用lvs来实现,若是是多主多从须要Mysql+DRBD+heartbeat来实现,架构以下(拷贝老男孩的一张架构图):
这里写图片描述
注意事项:
1.db-1-2热备主,跟db-1-1经过heartbeat作高可用,brdb作数据同步;
2.正常状况下,db-1-1对外提供写,从对外提供读;
3.mysql slave能够作一个lb,经过vip跟db-1-1作数据同步;
4.web server提供读写分离机制,读分发到mysql slave,写分发到db-1-1;
5.db-1-一、db-1-2数据同步使用专有链路,heartbeat也必须使用专有链路,也可使用串口线来完成,不建议使用同一链路。node

这里写图片描述
db-1-1故障以后,有db-1-2接管vip及数据库资源;
mysql slave因为是使用vip跟主库同步,因此故障发生以后能够自动跟db-1-2作数据同步;mysql

部署

Mysql支持多实例,drbd也支持多分区同步。若是节点流量比较大可使用网卡绑定。
咱们能够把mysql数据库和数据文件建立在/data目录,这样两个主节点均可以同步共享。
网卡及地址规划:web

这里写图片描述
主库sql

node1: 
eth0      10.37.2.100 //管理地址 
eth1      192.168.52.106//心跳线 
vip        10.37.2.240 //vip

node2: 
eth0    10.37.2.111 
eth1    192.168.52.103 
vip       10.37.2.241


从库
slave1
eth0    10.37.2.160
eth1    192.168.52.160

slave2
eth0    10.37.2.170
eth1    192.168.52.170

主库每台机器至少两块硬盘,容量大小一致。数据库

两台主库安装drbd和heartbeat,安装步骤及配置请参考前三个博客。api

heartbeat管理drbd

安装完成以后,heartbeat咱们还须要作一个配置,由heartbeat管理drbd。
两个主节点建立/data目录

mkdir -p /data

主节点格式化drbd0

mkfs -t ext3 /dev/drbd0
安全

主节点挂载

mount /dev/drbd0 /data

heartbeat禁止系统自启动ruby

[root@node1 data]# chkconfig heartbeat off

vi /etc/ha.d/haresources (注意不要换行,两个主节点都须要配置)服务器

##heartbeat drbd配置
 node1 IPaddr::10.37.2.240/24/eth0 drbddisk::data Filesystem::/dev/drbd0::/data::ext3
 ##把drbd0设备以ext3方式挂载到/data 上。
##heartbeat nfs 配置
  node1 IPaddr::10.37.2.240/24/eth0 drbddisk::data Filesystem::/dev/drbd0::/data::ext3 rsdata

 

启动heartbeat,查看vip和drbd是否正常启动.markdown

[root@node1 /]# /etc/init.d/heartbeat start Starting High-Availability services: INFO: Resource is stopped INFO: Resource is stopped Done. [root@node1 data]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000 link/ether 00:0c:29:50:f0:77 brd ff:ff:ff:ff:ff:ff inet 10.37.2.100/24 brd 10.37.2.255 scope global eth0 inet 10.37.2.240/24 brd 10.37.2.255 scope global secondary eth0 inet6 fe80::20c:29ff:fe50:f077/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000 link/ether 00:0c:29:50:f0:81 brd ff:ff:ff:ff:ff:ff inet 192.168.52.100/24 brd 192.168.52.255 scope global eth1 inet6 fe80::20c:29ff:fe50:f081/64 scope link valid_lft forever preferred_lft forever [root@node1 data]# cat /proc/drbd version: 8.4.4 (api:1/proto:86-101) GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@node1, 2017-08-30 11:34:17 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r----- ns:12 nr:8 dw:172 dr:8549339 al:3 bm:526 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0 [root@node1 data]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_ams-lv_root 36G 5.1G 29G 15% / tmpfs 1.6G 224K 1.6G 1% /dev/shm /dev/sda1 477M 32M 420M 8% /boot /dev/sr0 4.4G 4.4G 0 100% /media/CentOS_6.6_Final /dev/sr0 4.4G 4.4G 0 100% /mnt /dev/drbd0 15G 166M 14G 2% /data heartbeat启动日志: ep 01 11:31:27 node1 heartbeat: [24937]: info: Pacemaker support: false Sep 01 11:31:27 node1 heartbeat: [24937]: WARN: Logging daemon is disabled --enabling logging daemon is recommended Sep 01 11:31:27 node1 heartbeat: [24937]: info: ************************** Sep 01 11:31:27 node1 heartbeat: [24937]: info: Configuration validated. Starting heartbeat 3.0.4 Sep 01 11:31:27 node1 heartbeat: [24938]: info: heartbeat: version 3.0.4 Sep 01 11:31:27 node1 heartbeat: [24938]: info: Heartbeat generation: 1503900466 Sep 01 11:31:27 node1 heartbeat: [24938]: info: glib: UDP Broadcast heartbeat started on port 694 (694) interface eth1 Sep 01 11:31:27 node1 heartbeat: [24938]: info: glib: UDP Broadcast heartbeat closed on port 694 interface eth1 - Status: 1 Sep 01 11:31:27 node1 heartbeat: [24938]: info: glib: ucast: write socket priority set to IPTOS_LOWDELAY on eth0 Sep 01 11:31:27 node1 heartbeat: [24938]: info: glib: ucast: bound send socket to device: eth0 Sep 01 11:31:27 node1 heartbeat: [24938]: info: glib: ucast: set SO_REUSEPORT(w) Sep 01 11:31:27 node1 heartbeat: [24938]: info: glib: ucast: bound receive socket to device: eth0 Sep 01 11:31:27 node1 heartbeat: [24938]: info: glib: ucast: set SO_REUSEPORT(w) Sep 01 11:31:27 node1 heartbeat: [24938]: info: glib: ucast: started on port 694 interface eth0 to 192.168.52.103 Sep 01 11:31:27 node1 heartbeat: [24938]: info: glib: ping heartbeat started. Sep 01 11:31:28 node1 heartbeat: [24938]: info: G_main_add_TriggerHandler: Added signal manual handler Sep 01 11:31:28 node1 heartbeat: [24938]: info: G_main_add_TriggerHandler: Added signal manual handler Sep 01 11:31:28 node1 heartbeat: [24938]: info: G_main_add_SignalHandler: Added signal handler for signal 17 Sep 01 11:31:28 node1 heartbeat: [24938]: info: Local status now set to: 'up' Sep 01 11:31:28 node1 heartbeat: [24938]: info: Link node1:eth1 up. Sep 01 11:32:26 node1 heartbeat: [24938]: info: Link node2:eth1 up. Sep 01 11:32:26 node1 heartbeat: [24938]: info: Status update for node node2: status up harc(default)[24951]: 2017/09/01_11:32:26 info: Running /etc/ha.d//rc.d/status status Sep 01 11:33:28 node1 heartbeat: [24938]: WARN: node 192.168.52.103: is dead harc(default)[24971]: 2017/09/01_11:33:28 info: Running /etc/ha.d//rc.d/status status Sep 01 11:33:29 node1 heartbeat: [24938]: info: Comm_now_up(): updating status to active Sep 01 11:33:29 node1 heartbeat: [24938]: info: Local status now set to: 'active' Sep 01 11:34:27 node1 heartbeat: [24938]: info: Status update for node node2: status active harc(default)[25001]: 2017/09/01_11:34:27 info: Running /etc/ha.d//rc.d/status status Sep 01 11:34:37 node1 heartbeat: [24938]: info: remote resource transition completed. Sep 01 11:34:37 node1 heartbeat: [24938]: info: remote resource transition completed. Sep 01 11:34:37 node1 heartbeat: [24938]: info: Initial resource acquisition complete (T_RESOURCES(us)) /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.240)[25055]: 2017/09/01_11:34:37 INFO: Resource is stopped Sep 01 11:34:37 node1 heartbeat: [25019]: info: Local Resource acquisition completed. harc(default)[25136]: 2017/09/01_11:34:37 info: Running /etc/ha.d//rc.d/ip-request-resp ip-request-resp ip-request-resp(default)[25136]: 2017/09/01_11:34:37 received ip-request-resp IPaddr::10.37.2.240/24/eth0 OK yes ResourceManager(default)[25159]: 2017/09/01_11:34:37 info: Acquiring resource group: node1 IPaddr::10.37.2.240/24/eth0 drbddisk::data Filesystem::/dev/drbd0::/data::ext3 /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.240)[25187]: 2017/09/01_11:34:38 INFO: Resource is stopped ResourceManager(default)[25159]: 2017/09/01_11:34:38 info: Running /etc/ha.d/resource.d/IPaddr 10.37.2.240/24/eth0 start IPaddr(IPaddr_10.37.2.240)[25310]: 2017/09/01_11:34:38 INFO: Adding inet address 10.37.2.240/24 with broadcast address 10.37.2.255 to device eth0 IPaddr(IPaddr_10.37.2.240)[25310]: 2017/09/01_11:34:38 INFO: Bringing device eth0 up IPaddr(IPaddr_10.37.2.240)[25310]: 2017/09/01_11:34:38 INFO: /usr/libexec/heartbeat/send_arp -i 200 -r 5 -p /var/run/resource-agents/send_arp-10.37.2.240 eth0 10.37.2.240 auto not_used not_used /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.240)[25284]: 2017/09/01_11:34:38 INFO: Success ResourceManager(default)[25159]: 2017/09/01_11:34:38 info: Running /etc/ha.d/resource.d/drbddisk data start /usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_/dev/drbd0)[25438]: 2017/09/01_11:34:38 INFO: Resource is stopped ResourceManager(default)[25159]: 2017/09/01_11:34:38 info: Running /etc/ha.d/resource.d/Filesystem /dev/drbd0 /data ext3 start Filesystem(Filesystem_/dev/drbd0)[25528]: 2017/09/01_11:34:38 INFO: Running start for /dev/drbd0 on /data /usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_/dev/drbd0)[25520]: 2017/09/01_11:34:38 INFO: Success 

 

错误1:

ResourceManager(default)[21772]:        2017/09/02_12:32:34 ERROR: Return code 1 from /etc/ha.d/resource.d/drbddisk
ResourceManager(default)[21772]:        2017/09/02_12:32:35 info: Retrying failed stop operation [drbddisk::data]
ResourceManager(default)[21772]:        2017/09/02_12:32:35 info: Running /etc/ha.d/resource.d/drbddisk data stop
ResourceManager(default)[21772]:        2017/09/02_12:32:37 ERROR: Return code 1 from /etc/ha.d/resource.d/drbddisk
ResourceManager(default)[21772]:        2017/09/02_12:32:37 ERROR: Resource script for drbddisk::data probably not LSB-compliant.
ResourceManager(default)[21772]:        2017/09/02_12:32:37 WARN: it (drbddisk::data) MUST succeed on a stop when already stopped
ResourceManager(default)[21772]:        2017/09/02_12:32:37 WARN: Machine reboot narrowly avoided!
ResourceManager(default)[21772]:        2017/09/02_12:32:37 info: Running /etc/ha.d/resource.d/IPaddr 10.37.2.240/24/eth0 stop

 

解决方案:查看 ha-log日志,发现heartbeat管理drbd资源一直报错,能够先把drbd手动启动起来。
这样虽然能够正常启动,可是没有被heartbeat接管,可能会形成某一个节点宕机,另一个节点的drbd会起不起来,最好的方法是让heartbeat接管drbd。

以上能够看到,heartbeat正常启动并正常接管资源(drbd,vip),drbd0正常挂载。
以上drbd跟heartbeat整合完成,下面开始整合mysql。

4台服务器安装mysql,采用编译安装mysql-5.5.32
安装cmake
安装依赖包

yum -y install ncurses-devel bison gcc gcc-c++

 

进到cmake解压包目录,编译安装

./configure  
   make 
   make install

 

编译安装mysql-5.5.32

cmake . -DCMAKE_INSTALL_PREFIX=/data/app/mysql  \
-DMYSQL_DATADIR=/data/app/mysql/data \ -DMYSQL_UNIX_ADDR=/data/app/mysql/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \ -DENABLED_LOCAL_INFILE=on \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \ -DWITHOUT_PARTITION_STORAGE_ENGINE=1 \ -DWITH_FAST_MUTEXES=1 \ -DWITH_ZLIB=BUNDLED \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_READLINE=1 \ -DWITH_EMBEDDED_SERVER=1 \ -DWITH_DEBUG=0

 

 

错误:

CMake Error: The current CMakeCache.txt directory /data/app/mysql/CMakeCache.txt is different than the directory /home/mysql/mysql-5.5.32 where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt

 

解决:

rm -rf CMakeCache.txt

 

接下来开始编译安装

make 
 make install

 

建立mysql帐户

groupadd -u mysql 
useradd -u 5001 -g mysql -s /sbin/nologin   -d /home/ mysql  mysql

 

注意:“-s /sbin/nologin” 禁止该用户登陆。
配置
cp support-files/my-small.cnf /etc/my.cnf
配置环境变量:export PATH=/home/mysql/app/bin:$PATH
权限:chown -R mysql.mysql ./mysql/app/data/
chmod -R 1777
初始化:

[root@web app]# /home/mysql/app/scripts/mysql_install_db --basedir=/home/mysql/app 
--datadir=/home/mysql/app/data --user=mysql

 

启动:

[root@web app]# mysqld_safe --defaults-file=/home/mysql/app/data/my.conf 

 

错误1:

InnoDB: Error: space header page consists of zero bytes in data file ./ibdata1
170903 12:43:39 InnoDB: Could not open or create data files.
170903 12:43:39 InnoDB: If you tried to add new data files, and it failed here,
170903 12:43:39 InnoDB: you should now edit innodb_data_file_path in my.cnf back
170903 12:43:39 InnoDB: to what it was, and remove the new ibdata files InnoDB created
170903 12:43:39 InnoDB: in this failed attempt. InnoDB only wrote those files full of
170903 12:43:39 InnoDB: zeros, but did not yet use them in any way. But be careful: do not
170903 12:43:39 InnoDB: remove old data files which contain your precious data!
170903 12:43:39 [ERROR] Plugin 'InnoDB' init function returned error.
170903 12:43:39 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
170903 12:43:39 [ERROR] Unknown/unsupported storage engine: InnoDB
170903 12:43:39 [ERROR] Aborting

 

解决:
看如上提示,mysql在安装数据文件ibdata1失败,最简单的方法就是从新初始化mysql。

其他3台服务器相似如上步骤安装mysql。
两台从库开启binlog,用于同步。
到目前为止,两个主节点安装了heartbeat,drbd和mysql;
heartbeat接管drbd服务,drbd数据盘挂载到/data目录用于同步两个主节点数据,咱们能够把mysql数据文件挂在/data目录。
手工切换在drbd管理的node1节点,在node1节点执行

[root@node1 data]# /usr/share/heartbeat/hb_standby 
Going standby [all].

[root@node1 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_ams-lv_root
                       36G  7.6G   27G  23% /
tmpfs                 1.6G     0  1.6G   0% /dev/shm
/dev/sda1             477M   32M  420M   8% /boot

 

查看node2节点:

[root@node2 /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_web-lv_root
                       35G  5.7G   28G  18% /
tmpfs                 2.0G     0  2.0G   0% /dev/shm
/dev/sda1             477M   32M  420M   8% /boot
/dev/drbd0            8.1G  1.7G  6.0G  23% /data

 

发现node2节点已经自动挂载了/data目录。
在node2安装mysql数据库,把数据文件,my.cnf和mysql.sock文件映射到/data目录。(注意权限)
在node2节点启动mysql :

[root@node2 /]# mysqld_safe --defaults-file=/home/mysql/app/data/my.conf 
Warning: World-writable config file '/home/mysql/app/data/my.conf' is ignored
Warning: World-writable config file '/home/mysql/app/data/my.conf' is ignored
170903 16:29:36 mysqld_safe Logging to '/home/mysql/app/data/node2.err'.
170903 16:29:36 mysqld_safe Starting mysqld daemon with databases from /home/mysql/app/data

 

可知node2节点mysql启动正常。
因为heartbeat暂时没有接管mysql,因此先在node2把mysql杀掉,在node1节点接管资源,在启动mysql服务.以下:
node2节点杀掉mysql服务:

[root@node2 /]# mysqladmin -uroot -p'ckf77856' shutdown 

 

node1节点接管drbd资源

[root@node1 ~]# /usr/share/heartbeat/hb_takeover local
[root@node1 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_ams-lv_root
                       36G  6.4G   28G  19% /
tmpfs                 1.6G     0  1.6G   0% /dev/shm
/dev/sda1             477M   32M  420M   8% /boot
/dev/drbd0            8.1G  176M  7.5G   3% /data

 

在drbd主节点启动mysql服务
mysqld_safe --defaults-file=/home/mysql/app/data/my.conf
可知主节点mysql服务正常。

heartbeat管理mysql服务

以上都是手工管理mysql服务,下面使用heartbeat来实现mysql资源接管。
vi /etc/ha.d/haresources,把mysql添加以下配置(drbd两个节点都需执行)

#node-name resource1 resource2 ... resourceN
 node2 IPaddr::10.37.2.241/24/eth0
 node1 IPaddr::10.37.2.240/24/eth0 drbddisk::data Filesystem::/dev/drbd0::/data::ext3 mysql

 

把mysql启动脚本放在/etc/ha.d/resource.d/下面并添加可执行权限。(drbd两个节点都需执行)

[root@node2 ~]# cp /home/mysql/app/support-files/mysql.server /etc/ha.d/resource.d/mysql
[root@node2 ~]# chmod +x /etc/ha.d/resource.d/mysql

 

禁止mysql自启动

chkconfig mysqld off

 

启动heartbeat服务,在node1,node2节点查看查看vip和drbd角色启动状态。
在node1节点查看drbd管理drbd0设备挂载状况和mysql服务状态。
测试故障转移:
在node1节点把heartbeat中止掉,在node2节点查看vip,drbd角色状态,drbd0设备挂载和mysql服务状态。

node2节点:
启动heartbeat

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

 

查看heartbeat日志

tail -f /var/log/ha-log
 Sep 08 18:01:54 node2 heartbeat: [9343]: info: **************************
Sep 08 18:01:54 node2 heartbeat: [9343]: info: Configuration validated. Starting heartbeat 3.0.4
Sep 08 18:01:54 node2 heartbeat: [9344]: info: heartbeat: version 3.0.4
Sep 08 18:01:54 node2 heartbeat: [9344]: info: Heartbeat generation: 1503897788
Sep 08 18:01:54 node2 heartbeat: [9344]: info: glib: UDP Broadcast heartbeat started on port 694 (694) interface eth1
Sep 08 18:01:54 node2 heartbeat: [9344]: info: glib: UDP Broadcast heartbeat closed on port 694 interface eth1 - Status: 1
Sep 08 18:01:54 node2 heartbeat: [9344]: info: glib: ucast: write socket priority set to IPTOS_LOWDELAY on eth1
Sep 08 18:01:54 node2 heartbeat: [9344]: info: glib: ucast: bound send socket to device: eth1
Sep 08 18:01:54 node2 heartbeat: [9344]: info: glib: ucast: set SO_REUSEPORT(w)
Sep 08 18:01:54 node2 heartbeat: [9344]: info: glib: ucast: bound receive socket to device: eth1
Sep 08 18:01:54 node2 heartbeat: [9344]: info: glib: ucast: set SO_REUSEPORT(w)
Sep 08 18:01:54 node2 heartbeat: [9344]: info: glib: ucast: started on port 694 interface eth1 to 192.168.52.100
Sep 08 18:01:54 node2 heartbeat: [9344]: info: glib: ping heartbeat started.
Sep 08 18:01:54 node2 heartbeat: [9344]: info: G_main_add_TriggerHandler: Added signal manual handler
Sep 08 18:01:54 node2 heartbeat: [9344]: info: G_main_add_TriggerHandler: Added signal manual handler
Sep 08 18:01:54 node2 heartbeat: [9344]: info: G_main_add_SignalHandler: Added signal handler for signal 17
Sep 08 18:01:54 node2 heartbeat: [9344]: info: Local status now set to: 'up'
Sep 08 18:01:54 node2 heartbeat: [9344]: info: Link 192.168.52.100:192.168.52.100 up.
Sep 08 18:01:54 node2 heartbeat: [9344]: info: Status update for node 192.168.52.100: status ping
Sep 08 18:01:54 node2 heartbeat: [9344]: info: Link node2:eth1 up.
Sep 08 18:03:55 node2 heartbeat: [9344]: WARN: node node1: is dead
Sep 08 18:03:55 node2 heartbeat: [9344]: info: Comm_now_up(): updating status to active
Sep 08 18:03:55 node2 heartbeat: [9344]: info: Local status now set to: 'active'
Sep 08 18:03:55 node2 heartbeat: [9344]: WARN: No STONITH device configured.
Sep 08 18:03:55 node2 heartbeat: [9344]: WARN: Shared disks are not protected.
Sep 08 18:03:55 node2 heartbeat: [9344]: info: Resources being acquired from node1.
harc(default)[9357]:    2017/09/08_18:03:55 info: Running /etc/ha.d//rc.d/status status
mach_down(default)[9393]:       2017/09/08_18:03:55 info: Taking over resource group IPaddr::10.37.2.240/24/eth0
ResourceManager(default)[9444]: 2017/09/08_18:03:55 info: Acquiring resource group: node1 IPaddr::10.37.2.240/24/eth0 drbddisk::data Filesystem::/dev/drbd0::/data::ext3 mysql
/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.241)[9425]:    2017/09/08_18:03:55 INFO:  Resource is stopped
Sep 08 18:03:55 node2 heartbeat: [9358]: info: Local Resource acquisition completed.
/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.240)[9497]:    2017/09/08_18:03:55 INFO:  Resource is stopped
ResourceManager(default)[9444]: 2017/09/08_18:03:55 info: Running /etc/ha.d/resource.d/IPaddr 10.37.2.240/24/eth0 start
IPaddr(IPaddr_10.37.2.240)[9669]:       2017/09/08_18:03:55 INFO: Adding inet address 10.37.2.240/24 with broadcast address 10.37.2.255 to device eth0
IPaddr(IPaddr_10.37.2.240)[9669]:       2017/09/08_18:03:55 INFO: Bringing device eth0 up
IPaddr(IPaddr_10.37.2.240)[9669]:       2017/09/08_18:03:55 INFO: /usr/libexec/heartbeat/send_arp -i 200 -r 5 -p /var/run/resource-agents/send_arp-10.37.2.240 eth0 10.37.2.240 auto not_used not_used
/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.240)[9643]:    2017/09/08_18:03:55 INFO:  Success
ResourceManager(default)[9444]: 2017/09/08_18:03:55 info: Running /etc/ha.d/resource.d/drbddisk data start
/usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_/dev/drbd0)[9797]:     2017/09/08_18:03:55 INFO:  Resource is stopped
ResourceManager(default)[9444]: 2017/09/08_18:03:55 info: Running /etc/ha.d/resource.d/Filesystem /dev/drbd0 /data ext3 start
Filesystem(Filesystem_/dev/drbd0)[9887]:        2017/09/08_18:03:55 INFO: Running start for /dev/drbd0 on /data
/usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_/dev/drbd0)[9879]:     2017/09/08_18:03:55 INFO:  Success
ResourceManager(default)[9444]: 2017/09/08_18:03:55 info: Running /etc/ha.d/resource.d/mysql  start
mach_down(default)[9393]:       2017/09/08_18:03:56 info: /usr/share/heartbeat/mach_down: nice_failback: foreign resources acquired
mach_down(default)[9393]:       2017/09/08_18:03:56 info: mach_down takeover complete for node node1.
Sep 08 18:03:56 node2 heartbeat: [9344]: info: mach_down takeover complete.
Sep 08 18:03:56 node2 heartbeat: [9344]: info: Initial resource acquisition complete (mach_down)
harc(default)[10120]:   2017/09/08_18:03:56 info: Running /etc/ha.d//rc.d/ip-request-resp ip-request-resp
ip-request-resp(default)[10120]:        2017/09/08_18:03:56 received ip-request-resp IPaddr::10.37.2.241/24/eth0 OK yes
ResourceManager(default)[10143]:        2017/09/08_18:03:56 info: Acquiring resource group: node2 IPaddr::10.37.2.241/24/eth0
/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.241)[10171]:   2017/09/08_18:03:56 INFO:  Resource is stopped
ResourceManager(default)[10143]:        2017/09/08_18:03:57 info: Running /etc/ha.d/resource.d/IPaddr 10.37.2.241/24/eth0 start
IPaddr(IPaddr_10.37.2.241)[10294]:      2017/09/08_18:03:57 INFO: Adding inet address 10.37.2.241/24 with broadcast address 10.37.2.255 to device eth0
IPaddr(IPaddr_10.37.2.241)[10294]:      2017/09/08_18:03:57 INFO: Bringing device eth0 up
IPaddr(IPaddr_10.37.2.241)[10294]:      2017/09/08_18:03:57 INFO: /usr/libexec/heartbeat/send_arp -i 200 -r 5 -p /var/run/resource-agents/send_arp-10.37.2.241 eth0 10.37.2.241 auto not_used not_used
/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.241)[10268]:   2017/09/08_18:03:57 INFO:  Success
Sep 08 18:04:05 node2 heartbeat: [9344]: info: Local Resource acquisition completed. (none)
Sep 08 18:04:05 node2 heartbeat: [9344]: info: local resource transition completed.

 

vip分配状况

[root@node2 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:0c:29:d1:09:2b brd ff:ff:ff:ff:ff:ff
    inet 10.37.2.111/24 brd 10.37.2.255 scope global eth0
    inet 10.37.2.240/24 brd 10.37.2.255 scope global secondary eth0
    inet 10.37.2.241/24 brd 10.37.2.255 scope global secondary eth0
    inet6 fe80::20c:29ff:fed1:92b/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:0c:29:d1:09:35 brd ff:ff:ff:ff:ff:ff
    inet 192.168.52.111/24 brd 192.168.52.255 scope global eth1
    inet6 fe80::20c:29ff:fed1:935/64 scope link 
       valid_lft forever preferred_lft forever

 

共享文件系统挂载状态

[root@node2 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_web-lv_root
                       35G  5.7G   28G  18% /
tmpfs                 2.0G     0  2.0G   0% /dev/shm
/dev/sda1             477M   32M  420M   8% /boot
/dev/drbd0            8.1G  176M  7.5G   3% /data

 

drbd状态

[root@node2 ~]# cat /proc/drbd 
version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@node2, 2017-08-30 11:32:34
 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
    ns:96304 nr:19388 dw:25092 dr:126028 al:18 bm:24 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0

 

查看mysql服务是否能够正常登陆

[root@node2 ~]# mysql -uroot -pckf77856
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.32 Source distribution

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 | | #mysql50#lost+found | | mysql | | performance_schema  |
| test | +---------------------+
5 rows in set (0.01 sec)

 

以上可知,一切资源都正常启动,mysql能正常登陆。
能够测试把备节点heart中止模拟备节点主机故障,看主节点是否能正常接管。
能够经过/usr/share/heartbeat/hb_standby 把本几点置为备角色;
/usr/share/heartbeat/hb_takeover 把资源都接管过来,把本几点置为主。
角色划分由heartbeat来负责,根据haresource配置文件来决定,除非人为设置。
注意:
我把drbd,mysql服务在node1节点配置接管,在通常状况下,mysql和drbd都会随着node1漂移而漂移。
node2节点宕机,node1接管全部的服务;
node1都node2正常,drbd和mysql服务会在node1上启动;
node1节点宕机,node1节点的资源和ip都会在node2上启动;因此mysql服务对外提供的地址和端口应该跟node1 vip和端口一致。
node1和node2凡是跟主机节点相关的文件及配置都尽可能放在/data目录或者都配置成同样,这里建议都改为同样,如 binlog文件,relaylog文件,日志文件(错误日志文件,查询日志,慢查询日志),sock文件和配置文件
这里写图片描述

错误1:
node2节点不能正常接管node1的资源,可是node1能够接管node2。
防火墙也没问题,查node2后台日志

Sep 10 12:01:22 node2 heartbeat: [4416]: info: foreign HA resource release completed (standby).
Sep 10 12:01:22 node2 heartbeat: [2029]: info: Local standby process completed [foreign].
Sep 10 12:01:23 node2 heartbeat: [2029]: info: all clients are now resumed
Sep 10 12:01:23 node2 heartbeat: [2029]: info: Link 10.37.2.240:10.37.2.240 up.
Sep 10 12:01:23 node2 heartbeat: [2029]: WARN: Late heartbeat: Node 10.37.2.240: interval 53813710 ms
Sep 10 12:01:23 node2 heartbeat: [2029]: info: Status update for node 10.37.2.240: status ping Sep 10 12:01:25 node2 heartbeat: [2029]: WARN: 1 lost packet(s) for [node1] [13:15] Sep 10 12:01:25 node2 heartbeat: [2029]: info: remote resource transition completed. Sep 10 12:01:25 node2 heartbeat: [2029]: info: No pkts missing from node1! Sep 10 12:01:25 node2 heartbeat: [2029]: info: Other node completed standby takeover of foreign resources. Sep 10 12:03:15 node2 heartbeat: [2029]: info: Received shutdown notice from 'node1'. Sep 10 12:03:15 node2 heartbeat: [2029]: info: Resources being acquired from node1. Sep 10 12:03:15 node2 heartbeat: [4714]: info: acquire local HA resources (standby). ResourceManager(default)[4740]: 2017/09/10_12:03:15 info: Acquiring resource group: node2 IPaddr::10.37.2.241/24/eth0 /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.241)[4789]: 2017/09/10_12:03:15 INFO: Running OK Sep 10 12:03:15 node2 heartbeat: [4714]: info: local HA resource acquisition completed (standby). Sep 10 12:03:15 node2 heartbeat: [2029]: info: Standby resource acquisition done [foreign]. /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.241)[4795]: 2017/09/10_12:03:15 INFO: Running OK Sep 10 12:03:15 node2 heartbeat: [4715]: info: Local Resource acquisition completed. harc(default)[4947]: 2017/09/10_12:03:15 info: Running /etc/ha.d//rc.d/status status mach_down(default)[4964]: 2017/09/10_12:03:15 info: Taking over resource group IPaddr::10.37.2.240/24/eth0 ResourceManager(default)[4991]: 2017/09/10_12:03:15 info: Acquiring resource group: node1 IPaddr::10.37.2.240/24/eth0 drbddisk::data Filesystem::/dev/drbd0::/data::ext3 mysql /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.240)[5019]: 2017/09/10_12:03:15 INFO: Resource is stopped ResourceManager(default)[4991]: 2017/09/10_12:03:15 info: Running /etc/ha.d/resource.d/IPaddr 10.37.2.240/24/eth0 start IPaddr(IPaddr_10.37.2.240)[5142]: 2017/09/10_12:03:15 INFO: Adding inet address 10.37.2.240/24 with broadcast address 10.37.2.255 to device eth0 IPaddr(IPaddr_10.37.2.240)[5142]: 2017/09/10_12:03:15 INFO: Bringing device eth0 up IPaddr(IPaddr_10.37.2.240)[5142]: 2017/09/10_12:03:15 INFO: /usr/libexec/heartbeat/send_arp -i 200 -r 5 -p /var/run/resource-agents/send_arp-10.37.2.240 eth0 10.37.2.240 auto not_used not_used /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.240)[5116]: 2017/09/10_12:03:15 INFO: Success ResourceManager(default)[4991]: 2017/09/10_12:03:16 info: Running /etc/ha.d/resource.d/drbddisk data start /usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_/dev/drbd0)[5270]: 2017/09/10_12:03:16 INFO: Resource is stopped ResourceManager(default)[4991]: 2017/09/10_12:03:16 info: Running /etc/ha.d/resource.d/Filesystem /dev/drbd0 /data ext3 start Filesystem(Filesystem_/dev/drbd0)[5360]: 2017/09/10_12:03:16 INFO: Running start for /dev/drbd0 on /data /usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_/dev/drbd0)[5352]: 2017/09/10_12:03:16 INFO: Success ResourceManager(default)[4991]: 2017/09/10_12:03:16 info: Running /etc/ha.d/resource.d/mysql start ResourceManager(default)[4991]: 2017/09/10_12:03:17 ERROR: Return code 1 from /etc/ha.d/resource.d/mysql ResourceManager(default)[4991]: 2017/09/10_12:03:17 CRIT: Giving up resources due to failure of mysql ResourceManager(default)[4991]: 2017/09/10_12:03:17 info: Releasing resource group: node1 IPaddr::10.37.2.240/24/eth0 drbddisk::data Filesystem::/dev/drbd0::/data::ext3 mysql ResourceManager(default)[4991]: 2017/09/10_12:03:17 info: Running /etc/ha.d/resource.d/mysql stop ResourceManager(default)[4991]: 2017/09/10_12:03:17 info: Running /etc/ha.d/resource.d/Filesystem /dev/drbd0 /data ext3 stop Filesystem(Filesystem_/dev/drbd0)[5864]: 2017/09/10_12:03:17 INFO: Running stop for /dev/drbd0 on /data Filesystem(Filesystem_/dev/drbd0)[5864]: 2017/09/10_12:03:17 INFO: Trying to unmount /data Filesystem(Filesystem_/dev/drbd0)[5864]: 2017/09/10_12:03:17 INFO: unmounted /data successfully /usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_/dev/drbd0)[5856]: 2017/09/10_12:03:17 INFO: Success ResourceManager(default)[4991]: 2017/09/10_12:03:17 info: Running /etc/ha.d/resource.d/drbddisk data stop ResourceManager(default)[4991]: 2017/09/10_12:03:17 info: Running /etc/ha.d/resource.d/IPaddr 10.37.2.240/24/eth0 stop IPaddr(IPaddr_10.37.2.240)[6025]: 2017/09/10_12:03:17 INFO: IP status = ok, IP_CIP= /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.240)[5999]: 2017/09/10_12:03:17 INFO: Success mach_down(default)[4964]: 2017/09/10_12:03:17 info: /usr/share/heartbeat/mach_down: nice_failback: foreign resources acquired mach_down(default)[4964]: 2017/09/10_12:03:17 info: mach_down takeover complete for node node1. Sep 10 12:03:17 node2 heartbeat: [2029]: info: mach_down takeover complete. Sep 10 12:03:46 node2 heartbeat: [2029]: WARN: node 10.37.2.240: is dead Sep 10 12:03:46 node2 heartbeat: [2029]: info: Link 10.37.2.240:10.37.2.240 dead. harc(default)[6134]: 2017/09/10_12:03:46 info: Running /etc/ha.d//rc.d/status status Sep 10 12:03:47 node2 heartbeat: [2029]: WARN: node node1: is dead Sep 10 12:03:47 node2 heartbeat: [2029]: info: Dead node node1 gave up resources. Sep 10 12:03:47 node2 heartbeat: [2029]: info: Link node1:eth1 dead. hb_standby(default)[6171]: 2017/09/10_12:03:47 Going standby [foreign]. Sep 10 12:03:48 node2 heartbeat: [2029]: info: node2 wants to go standby [foreign] Sep 10 12:03:58 node2 heartbeat: [2029]: WARN: No reply to standby request. Standby request cancelled.

 

–解决 :
其中能够看到,最开始资源都正常,可是我注意到‘ERROR: Return code 1 from /etc/ha.d/resource.d/mysql’启动mysql报了个错致使后面把服务都杀掉了。
尝试在node2手动挂载/data目录,而后启动mysql报‘/home/mysql/app/bin/mysqld: File ‘/home/mysql/app/data/mysql-bin.index’ not found (Errcode: 13)’错误,怀疑drbd没有执行,而后在node1角色切换成备,在node2观察发如今很短一个时间内会mount /data目录,而后又被umount了,多是启动mysql失败而后资源接管失败,最后发现两个节点的数据目录(/data)所属组id不同,真是粗心害死人。

auto_failback on参数讲解:
auto_failback 若是设置为打开,若是发生故障切换,当主修复好了以后,会自动把mysql服务切换到主节点,可是有一个问题,mysql服务是切换过去了,若是资源没有切换到主节点是否是出问题了。
以上实现了mysql高可用,heartbeat控制vip(对外提供服务地址),数据文件(/data)和mysql服务切换,vip和mysql服务在node1,node2之间漂移,始终保证vip能够链接到mysql服务,数据文件经过drbd在node1,node2之间同步,始终保证两边数据一致,确保不会产生脑裂问题,从而保证服务高可用。

配置mysql主从同步

node1,node2在同一个时间点只能有一个提供服务,为了保证数据安全,把主节点数据同步到备节点。

从库
slave1
eth0 10.37.2.160
eth1 192.168.52.160

注意,因为主库两个节点有可能会发生切换,因此备库跟主库同步地址须要时主库对外提供服务器的vip即配置node1的vip(10.37.2.240)。

mysql主从同步

  1. 主库配置
    1.1 修改主库my.cnf
主库开启binlog,肯定 server-id惟一性。
server-id=1   #设置服务器id,为1表示主服务器,注意:若是原来的配置文件中已经有这一行,就不用再添加了。
log_bin=mysql-bin  #启动MySQ二进制日志系统,注意:若是原来的配置文件中已经有这一行,就不用再添加了。
binlog-do-db=osyunweidb  #须要同步的数据库名,若是有多个数据库,可重复此参数,每一个数据库一行;若是想同步整个库,这个参数可不写。
binlog-ignore-db=mysql   #不一样步mysql系统数据库;mysql数据库是系统配置信息,不建议同步。

 

1.2 主库添加同步用户及权限

grant replication slave on *.* to 'bobo'@'10.37.2.%' identified by 'ckf77856';
flush privileges;

 

1.3 主库备份

mysql> flush table with read lock;( MySql 5.1使用 flush tables with read lock;)
mysql> show master status;
[root@node1 ~]# mysqldump -uroot -pckf77856 -S /home/mysql/app/3306/mysql.sock -A -B -F --events --master-data=2 >/tmp/3306_master.sql;
注意:锁表以后备份数据库使用了‘-F’参数,会强制刷新binlog会致使位置点(postition)变化,因为锁表无dml操做,因此不用担忧会有数据未备份,建议不要加‘-F’。
添加“--master-data=2”参数在备份信息有记录binlog位置。
mysql> unlock tables;

 

2 从库配置

2.1 修改从库my.cnf

vi /etc/my.cnf   #编辑配置文件,在[mysqld]部分添加下面内容
server-id=2   #此参数不能与集群其余库重复,惟一值。
log-bin=mysql-bin  #启动MySQ二进制日志系统,注意:若是原来的配置文件中已经有这一行,就不用再添加了; 
replication-do-db=osyunweidb  #须要同步的数据库名,若是有多个数据库,可重复此参数,每一个数据库一行;若是想同步整个库,这个参数可不写。
replication -ignore-db=mysql   #不一样步mysql系统数据库;mysql数据库是系统配置信息,不建议同步。
replication-do-table=
replication-ignore-table=
replication-wild-do-table=''; 通配同步表
replication-wild-ignore-table=''

 

2.2 恢复从库

[root@web ~]# mysqld_safe --defaults-file=/home/mysql/app/3307/my.conf #启动
[root@web ~]# mysql -uroot -pabcd.1234 -S /home/mysql/app/3307/mysql.sock </tmp/3306_master.sql
[root@web ~]# mysql -ubobo -pckf77856 -h 192.168.21.169 -P3306 #远程登陆3306端口数据库

 

2.3 修改备库同步参数

mysql> change master to 
    -> master_host='10.37.2.240',     -> master_port=3306,     -> master_user='bobo',     -> master_password='ckf77856',     -> master_log_file='mysql3306-bin.000455', #能够不要     -> master_log_pos=107; #能够不要 Query OK, 0 rows affected (0.02 sec)

 

错误1:

mysql> change master to  master_host='10.37.2.240', master_port=3306, master_user='bobo', master_password='ckf77856';
ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MySQL error log
170909 18:33:51 [ERROR] Failed to open the relay log './rac1-relay-bin.000004' (relay_log_pos 250)
170909 18:33:51 [ERROR] Could not find target log during relay log initialization

 

以上可知,从库找不到主库传输过来的日志,检查从库relay-log.info查看日志,发现从库以前跟别的库同步过,删除以前的relay-log.info,从新建立。

2.4 备库开启同步

mysql> start slave;
mysql> show slave status\G;
mysql> show slave status\G
*************************** 1. row ***************************
 Slave_IO_State: Waiting for master to send event
 Master_Host: 10.37.2.240
 Master_User: bobo
 Master_Port: 3306
 Connect_Retry: 60
 Master_Log_File: mysql-bin.000002
 Read_Master_Log_Pos: 107
 Relay_Log_File: slave1-relay-bin.000011
 Relay_Log_Pos: 253
 Relay_Master_Log_File: mysql-bin.000002
 Slave_IO_Running: Yes
 Slave_SQL_Running: Yes
 Replicate_Do_DB: 
 Replicate_Ignore_DB: 
 Replicate_Do_Table: 
 Replicate_Ignore_Table: 
 Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
 Last_Errno: 0
 Last_Error: 
 Skip_Counter: 0
 Exec_Master_Log_Pos: 107
 Relay_Log_Space: 453
 Until_Condition: None
 Until_Log_File: 
 Until_Log_Pos: 0
 Master_SSL_Allowed: No
 Master_SSL_CA_File: 
 Master_SSL_CA_Path: 
 Master_SSL_Cert: 
 Master_SSL_Cipher: 
 Master_SSL_Key: 
 Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
 Last_IO_Errno: 0
 Last_IO_Error: 
 Last_SQL_Errno: 0
 Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
 Master_Server_Id: 1
1 row in set (0.00 sec)

 

 

至此主从同步完成。
能够测试同步结果,在主库建立一个表而后在备库查询看是否存在。

若是从库级联从库,须要打开binlog 和 log-slave-updates参数。
主库binlog文件和Position点跟从库的relay-log.info、master.info信息一致。
relay-log.info信息提供sql salve进程使用,master.info提供给io slave进程使用。

错误1:

mysql> start slave;
ERROR 1200 (HY000): The server is not configured as slave; fix in config file or with CHANGE MASTER TO

 

–解决:检查change_master是否正确,通常状况下主从同步,会形成主从的server-id也重复,主要改为不一致就能够。

[+拓展]
若是从库作级联(备库同步到另一台机器),须要设置从库,步骤以下:
1. 备库开启binlog
2. 备库设置log-slave-updates参数
3. 备库设置过时时间 expire_logs_days = 7
4. 同步备库数据主机设置 change master参数。

主从同步完成,这个时候测试切换主库,看备库是否还能正常同步数据。
node1是primary角色,如今要把node2切换成syandby角色,在node1执行:
[root@node1 ~]# /usr/share/heartbeat/hb_standby
Going standby [all].

查看node2资源
node2 ip信息

[root@node2 data]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:0c:29:d1:09:2b brd ff:ff:ff:ff:ff:ff
    inet 10.37.2.111/24 brd 10.37.2.255 scope global eth0
    inet 10.37.2.241/24 brd 10.37.2.255 scope global secondary eth0
    inet 10.37.2.240/24 brd 10.37.2.255 scope global secondary eth0
    inet6 fe80::20c:29ff:fed1:92b/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:0c:29:d1:09:35 brd ff:ff:ff:ff:ff:ff
    inet 192.168.52.111/24 brd 192.168.52.255 scope global eth1
    inet6 fe80::20c:29ff:fed1:935/64 scope link 
       valid_lft forever preferred_lft forever

 

 

node2 /data挂载信息

[root@node2 data]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_web-lv_root
                       35G  5.7G   28G  18% /
tmpfs                 2.0G     0  2.0G   0% /dev/shm
/dev/sda1             477M   32M  420M   8% /boot
/dev/drbd0            8.1G  176M  7.5G   3% /data

 

node2 drbd状态及角色

[root@node2 data]# cat /proc/drbd
version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@node2, 2017-08-30 11:32:34
 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
    ns:432 nr:584 dw:1016 dr:6225 al:12 bm:3 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0

[root@node2 data]# netstat -pan|grep 330
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      27899/mysqld        
tcp        0      0 10.37.2.240:3306            10.37.2.160:53472           ESTABLISHED 27899/mysqld

 

在node2节点对数据库操做,在备库查询node2数据是否传输到备库。
在node2对数据库操做

mysql> show databases; +---------------------+
| Database | +---------------------+
| information_schema | | #mysql50#lost+found | | mysql | | p1 | | performance_schema  |
| test | +---------------------+
6 rows in set (0.02 sec)

mysql> create database d111;
Query OK, 1 row affected (0.01 sec)

备库查看数据

mysql> show databases; +---------------------+
| Database | +---------------------+
| information_schema | | bobo | | d111 | | d3306 | | #mysql50#lost+found | | merg | | mysql | | p1 | | performance_schema  |
| pvs                 |
| test | +---------------------+
11 rows in set (0.00 sec)

 

注意:heartbeat检测对方心跳使用vip来传递信号。

相关文章
相关标签/搜索
本站公众号
   欢迎关注本站公众号,获取更多信息