heartbeat3.0.4-drbd8.9-Mysql5.6--双机互备高可用部署

   heartbeat 3.0.4-drbd 8.9-MySQL 5.6协同工作原理:首先,heartbeat作为高可用的控制角色,负责drbd存储服务目录的挂载(这里,drbd的启动个人理解是随主机启动自动

创新新互联,凭借十余年的成都网站设计、成都网站建设、外贸网站建设经验,本着真心·诚心服务的企业理念服务于成都中小企业设计网站有上1000+案例。做网站建设,选创新互联建站

启动的,其作用就是将主节点本地的一块盘与对端备节点的一块盘做数据同步、保证两端主机drbd相关的数据盘中数据完全一致),drbd的存储目录只在主节点挂载、接受读

写,而备机保持不可用;当heartbeat完成drbd存储目录挂载后,启动mysql数据库,同时heartbeat负责检测drbd存储、mysql服务的状态,当服务异常,通过超时机制将资源

在备机启动,从而达到mysql双机互备高可用的目的。

    前提条件:

    按照博文linux-ha heartbeat高可用的安装配置(http服务高可用)完成heartbeat的安装配置

    按照博文MySQL 5.6 for REHL 6.4编译安装完成mysql的安装配置

heartbeat安装参考日志:linux-ha heartbeat高可用-基于http服务的安装配置
mysql的编译安装参考日志:MySQL安装方式-MySQL编译安装
一、DRBD软件的安装配置
主机名称
mymongo1
arbiter
管理IP
eth0:192.168.199.131
eth0:192.168.199.134
DRBD管理名称
/data
/data
DRBD逻辑设备
/dev/drbd0
/dev/drbd0
DRBD对接IP
eth2:192.168.144.132
eth2:192.168.144.111
DRBD存储设备
/dev/sdb1
/dev/sdb1
DRBD META设备
/dev/sdb2 [0]
/dev/sdb2 [0]
虚拟IP
eth2:192.168.144.122
eth2:192.168.144.122





1、两台vmware linux 虚拟机arbiter和mymongo1(两台主机需要新添加虚拟硬盘sdb),基本信息
mymongo1
[root@mymongo1 ~]# hostname
mymongo1
[root@mymongo1 ~]# uname -a
Linux mymongo1 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@mymongo1 ~]# fdisk -l

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00061eae

Device Boot Start End Blocks Id System
/dev/sda1 * 1 39 307200 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 39 2350 18566144 83 Linux
/dev/sda3 2350 2611 2097152 82 Linux swap / Solaris
[root@mymongo1 ~]# cat /etc/redhat-release
CentOS release 6.8 (Final)
[root@mymongo1 ~]#

arbiter
[root@arbiter ~]# uname -a
Linux arbiter 2.6.32-358.el6.x86_64 #1 SMP Tue Jan 29 11:47:41 EST 2013 x86_64 x86_64 x86_64 GNU/Linux
[root@arbiter ~]# hostname
arbiter
[root@arbiter ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.4 (Santiago)
[root@arbiter ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00078b06

Device Boot Start End Blocks Id System
/dev/sda1 * 1 39 307200 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 39 549 4096000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 549 2611 16567296 83 Linux

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

[root@arbiter ~]#

2、2台虚拟机sdb虚拟盘的分区表调整
[root@arbiter ~]# parted /dev/sdb mklabel gpt
Information: You may need to update /etc/fstab.
[root@arbiter ~]#

[root@mymongo1 ~]# parted /dev/sdb mklabel gpt
Information: You may need to update /etc/fstab.
[root@mymongo1 ~]#

3、2台虚拟机sdb(共2个G)分区成2个分区,一个分区一个G
[root@mymongo1 ~]# parted /dev/sdb mkpart primary 0 1024
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? Ignore
Information: You may need to update /etc/fstab.
[root@mymongo1 ~]#
[root@mymongo1 ~]# parted /dev/sdb mkpart primary 1025 2146
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? Ignore
Information: You may need to update /etc/fstab.
[root@mymongo1 ~]# parted /dev/sdb p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 2147MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 17.4kB 1024MB 1024MB primary
2 1025MB 2146MB 1121MB primary
[root@mymongo1 ~]#

[root@arbiter ~]# parted /dev/sdb mkpart primary 0 1024
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? Ignore
Information: You may need to update /etc/fstab.
[root@arbiter ~]# parted /dev/sdb mkpart primary 1025 2146
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? Ignore
Information: You may need to update /etc/fstab.
[root@arbiter ~]# parted /dev/sdb p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 2147MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 17.4kB 1024MB 1024MB primary
2 1025MB 2146MB 1121MB primary
[root@arbiter ~]#

4、2台虚拟机安装drbd,通过网络yum安装,保证两台主机能够联网
[root@arbiter ~]# wget ftp.scientificlinux.org/linux/scientific/6.9/x86_64/os/Packages/elrepo-release-6-6.el6.elrepo.noarch.rpm
--2017-08-23 23:14:54-- http://ftp.scientificlinux.org/linux/scientific/6.9/x86_64/os/Packages/elrepo-release-6-6.el6.elrepo.noarch.rpm
Resolving ftp.scientificlinux.org... 131.225.105.11
Connecting to ftp.scientificlinux.org|131.225.105.11|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7464 (7.3K) [application/x-rpm]
Saving to: ?.lrepo-release-6-6.el6.elrepo.noarch.rpm?

100%[====================================================================================>] 7,464 --.-K/s in 0.01s

2017-08-23 23:14:56 (544 KB/s) - ?.lrepo-release-6-6.el6.elrepo.noarch.rpm?.saved [7464/7464]

[root@arbiter ~]# ls
anaconda-ks.cfg Documents heartbeat mysql-5.6.36 Public test
cmake-2.8.10.2 Downloads install.log mysql-5.6.36.tar rpms Videos
cmake-2.8.10.2.tar elrepo-release-6-6.el6.elrepo.noarch.rpm install.log.syslog Pictures select
Desktop epel-release-6-8.noarch.rpm Music pkg Templates
[root@arbiter ~]# rpm -ivh elrepo-release-6-6.el6.elrepo.noarch.rpm
warning: elrepo-release-6-6.el6.elrepo.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID 192a7d7d: NOKEY
Preparing... ########################################### [100%]
1:elrepo-release ########################################### [100%]
[root@arbiter ~]#
[root@arbiter ~]# ls
anaconda-ks.cfg Downloads install.log mysql-5.6.36.tar select
cmake-2.8.10.2 drbd84-utils-8.9.8-1.el6.elrepo.x86_64.rpm install.log.syslog Pictures Templates
cmake-2.8.10.2.tar elrepo-release-6-6.el6.elrepo.noarch.rpm kmod-drbd84-8.4.9-1.el6.elrepo.x86_64.rpm pkg test
Desktop epel-release-6-8.noarch.rpm Music Public Videos
Documents heartbeat mysql-5.6.36 rpms
[root@arbiter ~]# rpm -ivh drbd84-utils-8.9.8-1.el6.elrepo.x86_64.rpm
warning: drbd84-utils-8.9.8-1.el6.elrepo.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID baadae52: NOKEY
Preparing... ########################################### [100%]
1:drbd84-utils ########################################### [100%]
[root@arbiter ~]#
[root@arbiter yum.repos.d]# ls
elrepo.repo epel-testing.repo local.repo
[root@arbiter yum.repos.d]#
[root@arbiter yum.repos.d]# cat local.repo
[local]
name = local
baseurl=file:///mnt/
enabled = 1
gpgcheck = 0
gpgkey =file://mnt/RPM-GPG-KEY-CentOS-6
[root@arbiter yum.repos.d]#
[root@arbiter ~]# yum install -y kmod-drbd84-8.4.9-1.el6.elrepo.x86_64.rpm
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
elrepo | 2.9 kB 00:00
elrepo/primary_db | 692 kB 00:12
Setting up Install Process
Examining kmod-drbd84-8.4.9-1.el6.elrepo.x86_64.rpm: kmod-drbd84-8.4.9-1.el6.elrepo.x86_64
Marking kmod-drbd84-8.4.9-1.el6.elrepo.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package kmod-drbd84.x86_64 0:8.4.9-1.el6.elrepo will be installed
--> Processing Dependency: kernel(__dynamic_dev_dbg) = 0x4b1a6158 for package: kmod-drbd84-8.4.9-1.el6.elrepo.x86_64
--> Processing Dependency: kernel(dev_printk) = 0xabd7b07b for package: kmod-drbd84-8.4.9-1.el6.elrepo.x86_64
--> Finished Dependency Resolution
Error: Package: kmod-drbd84-8.4.9-1.el6.elrepo.x86_64 (/kmod-drbd84-8.4.9-1.el6.elrepo.x86_64)
Requires: kernel(__dynamic_dev_dbg) = 0x4b1a6158
Error: Package: kmod-drbd84-8.4.9-1.el6.elrepo.x86_64 (/kmod-drbd84-8.4.9-1.el6.elrepo.x86_64)
Requires: kernel(dev_printk) = 0xabd7b07b
You could try using --skip-broken to work around the problem
** Found 3 pre-existing rpmdb problem(s), 'yum check' output follows:
2:postfix-2.6.6-2.2.el6_1.x86_64 has missing requires of libmysqlclient.so.16()(64bit)
2:postfix-2.6.6-2.2.el6_1.x86_64 has missing requires of libmysqlclient.so.16(libmysqlclient_16)(64bit)
2:postfix-2.6.6-2.2.el6_1.x86_64 has missing requires of mysql-libs
[root@arbiter ~]# rpm -qa|grep kmod-drbd84
[root@arbiter ~]# yum install -y kmod-drbd84-8.4.9-1.el6.elrepo.x86_64.rpm
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
elrepo | 2.9 kB 00:00
elrepo/primary_db | 692 kB 00:10
local | 4.0 kB 00:00 ...
local/primary_db | 4.7 MB 00:00 ...
Setting up Install Process
Examining kmod-drbd84-8.4.9-1.el6.elrepo.x86_64.rpm: kmod-drbd84-8.4.9-1.el6.elrepo.x86_64
Marking kmod-drbd84-8.4.9-1.el6.elrepo.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package kmod-drbd84.x86_64 0:8.4.9-1.el6.elrepo will be installed
--> Processing Dependency: kernel(__dynamic_dev_dbg) = 0x4b1a6158 for package: kmod-drbd84-8.4.9-1.el6.elrepo.x86_64
--> Processing Dependency: kernel(dev_printk) = 0xabd7b07b for package: kmod-drbd84-8.4.9-1.el6.elrepo.x86_64
--> Running transaction check
---> Package kernel.x86_64 0:2.6.32-642.el6 will be installed
--> Processing Dependency: kernel-firmware >= 2.6.32-642.el6 for package: kernel-2.6.32-642.el6.x86_64
--> Processing Dependency: dracut-kernel >= 004-388.el6 for package: kernel-2.6.32-642.el6.x86_64
--> Running transaction check
---> Package dracut-kernel.noarch 0:004-303.el6 will be updated
---> Package dracut-kernel.noarch 0:004-409.el6 will be an update
--> Processing Dependency: dracut = 004-409.el6 for package: dracut-kernel-004-409.el6.noarch
---> Package kernel-firmware.noarch 0:2.6.32-358.el6 will be updated
---> Package kernel-firmware.noarch 0:2.6.32-642.el6 will be an update
--> Running transaction check
---> Package dracut.noarch 0:004-303.el6 will be updated
---> Package dracut.noarch 0:004-409.el6 will be an update
--> Processing Conflict: kernel-2.6.32-642.el6.x86_64 conflicts bfa-firmware < 3.2.21.1-2
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package bfa-firmware.noarch 0:3.0.3.1-1.el6 will be updated
---> Package bfa-firmware.noarch 0:3.2.23.0-2.el6 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================
Installing:
kmod-drbd84 x86_64 8.4.9-1.el6.elrepo /kmod-drbd84-8.4.9-1.el6.elrepo.x86_64 696 k
Updating:
bfa-firmware noarch 3.2.23.0-2.el6 local 3.2 M
Installing for dependencies:
kernel x86_64 2.6.32-642.el6 local 32 M
Updating for dependencies:
dracut noarch 004-409.el6 local 127 k
dracut-kernel noarch 004-409.el6 local 28 k
kernel-firmware noarch 2.6.32-642.el6 local 28 M

Transaction Summary
===============================================================================================================================================
Install 2 Package(s)
Upgrade 4 Package(s)

Total size: 64 M
Total download size: 63 M
Downloading Packages:
-----------------------------------------------------------------------------------------------------------------------------------------------
Total 93 MB/s | 63 MB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
** Found 3 pre-existing rpmdb problem(s), 'yum check' output follows:
2:postfix-2.6.6-2.2.el6_1.x86_64 has missing requires of libmysqlclient.so.16()(64bit)
2:postfix-2.6.6-2.2.el6_1.x86_64 has missing requires of libmysqlclient.so.16(libmysqlclient_16)(64bit)
2:postfix-2.6.6-2.2.el6_1.x86_64 has missing requires of mysql-libs
Updating : kernel-firmware-2.6.32-642.el6.noarch 1/10
Updating : dracut-004-409.el6.noarch 2/10
Updating : dracut-kernel-004-409.el6.noarch 3/10
Installing : kernel-2.6.32-642.el6.x86_64 4/10
Installing : kmod-drbd84-8.4.9-1.el6.elrepo.x86_64 5/10
Working. This may take some time ...
Done.
Updating : bfa-firmware-3.2.23.0-2.el6.noarch 6/10
Cleanup : dracut-kernel-004-303.el6.noarch 7/10
Cleanup : dracut-004-303.el6.noarch 8/10
Cleanup : kernel-firmware-2.6.32-358.el6.noarch 9/10
Cleanup : bfa-firmware-3.0.3.1-1.el6.noarch 10/10
Verifying : dracut-kernel-004-409.el6.noarch 1/10
Verifying : dracut-004-409.el6.noarch 2/10
Verifying : kmod-drbd84-8.4.9-1.el6.elrepo.x86_64 3/10
Verifying : bfa-firmware-3.2.23.0-2.el6.noarch 4/10
Verifying : kernel-firmware-2.6.32-642.el6.noarch 5/10
Verifying : kernel-2.6.32-642.el6.x86_64 6/10
Verifying : dracut-kernel-004-303.el6.noarch 7/10
Verifying : dracut-004-303.el6.noarch 8/10
Verifying : kernel-firmware-2.6.32-358.el6.noarch 9/10
Verifying : bfa-firmware-3.0.3.1-1.el6.noarch 10/10

Installed:
kmod-drbd84.x86_64 0:8.4.9-1.el6.elrepo

Dependency Installed:
kernel.x86_64 0:2.6.32-642.el6

Updated:
bfa-firmware.noarch 0:3.2.23.0-2.el6

Dependency Updated:
dracut.noarch 0:004-409.el6 dracut-kernel.noarch 0:004-409.el6 kernel-firmware.noarch 0:2.6.32-642.el6

Complete!
[root@arbiter ~]#

[root@mymongo1 drbd]# wget ftp.scientificlinux.org/linux/scientific/6.9/x86_64/os/Packages/elrepo-release-6-6.el6.elrepo.noarch.rpm
--2017-08-23 23:15:15-- http://ftp.scientificlinux.org/linux/scientific/6.9/x86_64/os/Packages/elrepo-release-6-6.el6.elrepo.noarch.rpm
Resolving ftp.scientificlinux.org... 131.225.105.11
Connecting to ftp.scientificlinux.org|131.225.105.11|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7464 (7.3K) [application/x-rpm]
Saving to: ?.lrepo-release-6-6.el6.elrepo.noarch.rpm?

100%[==========================================================================>] 7,464 --.-K/s in 0s

2017-08-23 23:15:16 (223 MB/s) - ?.lrepo-release-6-6.el6.elrepo.noarch.rpm?.saved [7464/7464]
--mymongo1节点drbd的安装
[root@mymongo1 drbd]# ls
elrepo-release-6-6.el6.elrepo.noarch.rpm
[root@mymongo1 drbd]# rpm -ivh elrepo-release-6-6.el6.elrepo.noarch.rpm
warning: elrepo-release-6-6.el6.elrepo.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID 192a7d7d: NOKEY
Preparing... ########################################### [100%]
1:elrepo-release ########################################### [100%]
[root@mymongo1 drbd]#
[root@mymongo1 drbd]# rpm -ivh elrepo-release-6-6.el6.elrepo.noarch.rpm
warning: elrepo-release-6-6.el6.elrepo.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID 192a7d7d: NOKEY
Preparing... ########################################### [100%]
1:elrepo-release ########################################### [100%]
[root@mymongo1 drbd]# yum install drbd kmod-drbd84 -y
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
epel/metalink | 4.6 kB 00:00
* base: mirrors.cn99.com
* elrepo: mirrors.tuna.tsinghua.edu.cn
* epel: mirror.premi.st
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
base | 3.7 kB 00:00
elrepo | 2.9 kB 00:00
elrepo/primary_db | 692 kB 00:27
epel | 4.3 kB 00:00
epel/primary_db | 5.9 MB 03:04
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
http://mirrors.tuna.tsinghua.edu.cn/centos/6.9/updates/x86_64/repodata/2b0cc62da054bcf7c883b783de2de48c2372b9e502074246f7e0b046336f123d-primary.sqlite.bz2: [Errno 12] Timeout on http://mirrors.tuna.tsinghua.edu.cn/centos/6.9/updates/x86_64/repodata/2b0cc62da054bcf7c883b783de2de48c2372b9e502074246f7e0b046336f123d-primary.sqlite.bz2: (28, 'Operation too slow. Less than 1 bytes/sec transfered the last 30 seconds')
Trying other mirror.
updates/primary_db | 3.1 MB 00:00
Resolving Dependencies
--> Running transaction check
---> Package drbd84-utils.x86_64 0:8.9.8-1.el6.elrepo will be installed
---> Package kmod-drbd84.x86_64 0:8.4.9-1.el6.elrepo will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================
Package Arch Version Repository Size
===================================================================================================================================
Installing:
drbd84-utils x86_64 8.9.8-1.el6.elrepo elrepo 392 k
kmod-drbd84 x86_64 8.4.9-1.el6.elrepo elrepo 198 k

Transaction Summary
===================================================================================================================================
Install 2 Package(s)

Total download size: 590 k
Installed size: 1.7 M
Downloading Packages:
(1/2): drbd84-utils-8.9.8-1.el6.elrepo.x86_64.rpm | 392 kB 00:11
(2/2): kmod-drbd84-8.4.9-1.el6.elrepo.x86_64.rpm | 198 kB 00:18
-----------------------------------------------------------------------------------------------------------------------------------
Total 19 kB/s | 590 kB 00:31
warning: rpmts_HdrFromFdno: Header V4 DSA/SHA1 Signature, key ID baadae52: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
Importing GPG key 0xBAADAE52:
Userid : elrepo.org (RPM Signing Key for elrepo.org)
Package: elrepo-release-6-6.el6.elrepo.noarch (installed)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
** Found 3 pre-existing rpmdb problem(s), 'yum check' output follows:
2:postfix-2.6.6-6.el6_7.1.x86_64 has missing requires of libmysqlclient.so.16()(64bit)
2:postfix-2.6.6-6.el6_7.1.x86_64 has missing requires of libmysqlclient.so.16(libmysqlclient_16)(64bit)
2:postfix-2.6.6-6.el6_7.1.x86_64 has missing requires of mysql-libs
Installing : drbd84-utils-8.9.8-1.el6.elrepo.x86_64 1/2
Installing : kmod-drbd84-8.4.9-1.el6.elrepo.x86_64 2/2
Working. This may take some time ...
Done.
Verifying : drbd84-utils-8.9.8-1.el6.elrepo.x86_64 1/2
Verifying : kmod-drbd84-8.4.9-1.el6.elrepo.x86_64 2/2

Installed:
drbd84-utils.x86_64 0:8.9.8-1.el6.elrepo kmod-drbd84.x86_64 0:8.4.9-1.el6.elrepo

Complete!
[root@mymongo1 drbd]#

[root@arbiter ~]# rpm -qa|grep drbd
kmod-drbd84-8.4.9-1.el6.elrepo.x86_64
drbd84-utils-8.9.8-1.el6.elrepo.x86_64
[root@arbiter ~]#
[root@mymongo1 ~]# rpm -qa|grep drbd
drbd84-utils-8.9.8-1.el6.elrepo.x86_64
kmod-drbd84-8.4.9-1.el6.elrepo.x86_64
[root@mymongo1 ~]#

5、将drbd加入内核并设置drbd开机自启动
[root@arbiter ~]# lsmod |grep drbd
[root@arbiter ~]# modprobe drbd
[root@arbiter ~]# lsmod |grep drbd
drbd 374888 0
libcrc32c 1246 1 drbd
[root@arbiter ~]# echo "modprobe drbd>/dev/null 2>&1">/etc/sysconfig/modules/drbd.modules
[root@arbiter ~]#

[root@mymongo1 ~]# lsmod |grep drbd
[root@mymongo1 ~]# modprobe drbd
[root@mymongo1 ~]# lsmod |grep drbd
drbd 374888 0
libcrc32c 1246 1 drbd
[root@mymongo1 ~]# echo "modprobe drbd>/dev/null 2>&1">/etc/sysconfig/modules/drbd.modules
[root@mymongo1 ~]#

6、编辑2个节点的drbd控制文件
[root@mymongo1 ~]# drbdadm create-md data
initializing activity log
NOT initializing bitmap
Writing meta data...
New drbd meta data block successfully created.
[root@mymongo1 ~]# cat /etc/drbd.conf
global{
#minor-count 64;
#dialog-refresh 5; #5 seconds
#disable-ip-verification;
usage-count no;
}

common{
protocol C;
disk {
on-io-error detach;
no-disk-flushes;
no-md-flushes;
}
net {
sndbuf-size 512k;
#timout 60; #60 seconds
#connect-int 10; #10 seconds
#ping-int 10; #10seconds
#ping-timeout 5; #500 ms
max-buffers 8000;
unplug-watermark 1024;
max-epoch-size 8000;
#ko-count 4;
#allow-two-primaries;
cram-hmac-alg "sha1";
shared-secret "hdhwXes23sYEhart8t";
after-sb-0pri disconnect;
after-sb-1pri disconnect;
after-sb-2pri disconnect;
rr-conflict disconnect;
#data-integrity-alg "md5";
#no-tcp-cork;
}
syncer{
rate 330M;
al-extents 517;
}
}
resource data{
on arbiter {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.144.111:7788;
meta-disk /dev/sdb2 [0];
}
on mymongo1 {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.144.132:7788;
meta-disk /dev/sdb2 [0];
}
}

[root@mymongo1 ~]#
[root@mymongo1 ~]# scp /etc/drbd.conf arbiter:/etc/
root@arbiter's password:
drbd.conf 100% 994 1.0KB/s 00:00
[root@mymongo1 ~]#

7、初始化两个节点drbd源数据
[root@mymongo1 ~]# drbdadm create-md data
initializing activity log
NOT initializing bitmap
Writing meta data...
New drbd meta data block successfully created.
[root@mymongo1 ~]#
[root@arbiter ~]# drbdadm create-md data
initializing activity log
NOT initializing bitmap
Writing meta data...
New drbd meta data block successfully created.
[root@arbiter ~]#

8、启动并查看drbd
[root@mymongo1 ~]# drbdadm up data
[root@mymongo1 ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:WFConnection ro:Secondary/Unknown ds:Inconsistent/DUnknown C r----s
ns:0 nr:0 dw:0 dr:0 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:999984
[root@mymongo1 ~]#
[root@arbiter ~]# drbdadm up data
[root@arbiter ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r-----
ns:0 nr:0 dw:0 dr:0 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:999984
[root@arbiter ~]#

[root@mymongo1 ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r-----
ns:0 nr:0 dw:0 dr:0 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:999984
[root@mymongo1 ~]#

9、设置drbd角色,这里设置mymongo1为主节点
[root@mymongo1 ~]# drbdadm -- --overwrite-data-of-peer primary data
[root@mymongo1 ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r---n-
ns:334220 nr:0 dw:0 dr:339075 al:8 bm:0 lo:0 pe:2 ua:5 ap:0 ep:1 wo:d oos:667184
[=====>..............] sync'ed: 33.9% (667184/999984)K
finish: 0:00:06 speed: 110,932 (110,932) K/sec
[root@mymongo1 ~]#
[root@arbiter ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:SyncTarget ro:Secondary/Primary ds:Inconsistent/UpToDate C r-----
ns:0 nr:896000 dw:894976 dr:0 al:8 bm:0 lo:2 pe:5 ua:1 ap:0 ep:1 wo:d oos:105008
[================>...] sync'ed: 89.8% (105008/999984)K
finish: 0:00:00 speed: 99,440 (99,440) want: 102,400 K/sec
[root@arbiter ~]#

完成同步
[root@arbiter ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----
ns:0 nr:999983 dw:999983 dr:0 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@arbiter ~]#
[root@mymongo1 ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:999983 nr:0 dw:0 dr:1000662 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@mymongo1 ~]#

10、2端机器创建相同的挂载点
[root@mymongo1 /]# mkdir data
[root@mymongo1 /]#

[root@arbiter /]# mkdir data
[root@arbiter /]#

11、格式化drbd0设备(只在主节点)
[root@mymongo1 /]# mkfs.ext4 -b 4096 /dev/drbd0
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
62592 inodes, 249995 blocks
12499 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=260046848
8 block groups
32768 blocks per group, 32768 fragments per group
7824 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@mymongo1 /]#
[root@mymongo1 /]# mount /dev/drbd0 /data
[root@mymongo1 /]# pwd
/
[root@mymongo1 /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 18G 6.6G 9.9G 40% /
tmpfs 935M 72K 935M 1% /dev/shm
/dev/sda1 283M 39M 229M 15% /boot
/dev/drbd0 946M 1.3M 896M 1% /data
[root@mymongo1 /]#

12、测试2端的数据同步
[root@mymongo1 ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:1032457 nr:0 dw:32474 dr:1001355 al:19 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@mymongo1 ~]#
[root@arbiter ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----
ns:0 nr:1032457 dw:1032457 dr:0 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@arbiter ~]#

测试
[root@mymongo1 ~]# cp glib-2.22.5.tar /data/
[root@mymongo1 ~]#
[root@mymongo1 ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:1032457 nr:0 dw:32474 dr:1001355 al:19 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@mymongo1 ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:1032457 nr:0 dw:32474 dr:1001363 al:19 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@mymongo1 ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:1032457 nr:0 dw:32474 dr:1001363 al:19 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@mymongo1 ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:1032485 nr:0 dw:32502 dr:1001363 al:19 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@mymongo1 ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:1072313 nr:0 dw:72330 dr:1001371 al:22 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@mymongo1 ~]#
[root@mymongo1 ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:1072325 nr:0 dw:72342 dr:1001371 al:22 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@mymongo1 ~]#

[root@arbiter ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----
ns:0 nr:1032457 dw:1032457 dr:0 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@arbiter ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----
ns:0 nr:1032485 dw:1032485 dr:0 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@arbiter ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----
ns:0 nr:1032485 dw:1032485 dr:0 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@arbiter ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----
ns:0 nr:1072325 dw:1072325dr:0 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@arbiter ~]#

备节点查看
[root@arbiter ~]# drbdadm down data
[root@arbiter ~]# mount /dev/sdb1 /mnt
[root@arbiter ~]# cd /mnt
[root@arbiter mnt]# ll
total 39816
-rw-r--r--. 1 root root 40755200 Aug 24 01:53 glib-2.22.5.tar
drwx------ 2 root root 16384 Aug 24 01:50 lost+found
[root@arbiter mnt]#

备节点恢复
[root@arbiter ~]# drbdadm up data
[root@arbiter ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----
ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@arbiter ~]#

二、heartbeat接管drbd服务资源
1、修改heartbeat的haresource配置文件,2个节点相同
[root@mymongo1 ~]# cat /etc/ha.d/haresources
arbiter IPaddr::192.168.144.121/24/eth2 httpd

mymongo1 IPaddr::192.168.144.122/24/eth2 drbddisk::data Filesystem::/dev/drbd0::/data::ext4

#mysql master
#arbiter IPaddr::192.168.144.11/24/eth2 mysqld

#mysql salve
#mymongo1 IPaddr::192.168.144.12/24/eth2
[root@mymongo1 ~]#
2、重启heartbeat服务
[root@mymongo1 ~]# /etc/init.d/heartbeat stop
Stopping High-Availability services: Done.

[root@mymongo1 ~]# /etc/init.d/heartbeat start
Starting High-Availability services: INFO: Resource is stopped
INFO: Resource is stopped
Done.
--查看heartbeat的vip
[root@mymongo1 ~]# ip add|grep 192.168.144.122
inet 192.168.144.122/24 brd 192.168.144.255 scope global secondary eth2
[root@mymongo1 ~]#
--查看drbd状态
[root@mymongo1 ~]# ip add|grep 192.168.144.122
inet 192.168.144.122/24 brd 192.168.144.255 scope global secondary eth2
[root@mymongo1 ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:1072437 nr:8 dw:72462 dr:1002067 al:22 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@mymongo1 ~]#
--查看drbd是否自动挂载
[root@mymongo1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 18G 6.6G 9.9G 40% /
tmpfs 935M 72K 935M 1% /dev/shm
/dev/sda1 283M 39M 229M 15% /boot
/dev/drbd0 946M 1.3M 896M 1% /data
[root@mymongo1 ~]#

arbiter节点处理
[root@arbiter ~]# /etc/init.d/heartbeat stop
Stopping High-Availability services: Done.
[root@arbiter ~]# /etc/init.d/heartbeat start
Starting High-Availability services: INFO: Resource is stopped
INFO: Resource is stopped
Done.
[root@arbiter ~]# ip add|grep 192.168.144.122
[root@arbiter ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----
ns:8 nr:112 dw:120 dr:696 al:1 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@arbiter ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 16G 8.3G 6.4G 57% /
tmpfs 935M 72K 935M 1% /dev/shm
/dev/sda1 283M 59M 210M 22% /boot
[root@arbiter ~]#

3、heartbeat接管drbd资源的测试
--停止mymongo1的heartbeat模拟故障
[root@mymongo1 ~]# /etc/init.d/heartbeat stop
Stopping High-Availability services: Done.

[root@mymongo1 ~]#
--查看备节点drbd服务目录的接管
[root@arbiter ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----
ns:8 nr:112 dw:120 dr:696 al:1 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@arbiter ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 16G 8.3G 6.4G 57% /
tmpfs 935M 72K 935M 1% /dev/shm
/dev/sda1 283M 59M 210M 22% /boot
[root@arbiter ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:12 nr:116 dw:128 dr:1392 al:1 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@arbiter ~]# ip add|grep 192.168.144.122
inet 192.168.144.122/24 brd 192.168.144.255 scope global secondary eth2
[root@arbiter ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 16G 8.3G 6.4G 57% /
tmpfs 935M 72K 935M 1% /dev/shm
/dev/sda1 283M 59M 210M 22% /boot
/dev/drbd0 946M 1.3M 896M 1% /data
[root@arbiter ~]#
--查看主节点drbd服务目录资源的释放
[root@mymongo1 ~]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----
ns:1072441 nr:12 dw:72470 dr:1002067 al:22 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@mymongo1 ~]#
[root@mymongo1 ~]# ip add|grep 192.168.144.122
[root@mymongo1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 18G 6.6G 9.9G 40% /
tmpfs 935M 72K 935M 1% /dev/shm
/dev/sda1 283M 39M 229M 15% /boot
[root@mymongo1 ~]#
--从实验看当主节点出故障后,heartbeat能够自动接管drbd资源
--调整drbd、heartbeat不开机自动启动,防止生产中数据破坏或数据不一致,首先人工处理
注意2节点最好对drbd、heartbeat不要自动启动
[root@arbiter ~]# chkconfig heartbeat off
[root@arbiter ~]# chkconfig drbd off

[root@mymongo1 ~]# chkconfig heartbeat off
[root@mymongo1 ~]# chkconfig drbd off

--drbd重新连接数据
drbdadm connect data

heartbeat接管drbdadm的配置完成

三、在drbd的主节点(当前是mymongo1)初始化mysql数据库
1、在drbd数据分区中安装mysql数据库
修改/data/mysql5.6的权限宿主
[root@mymongo1 scripts]# chown -R mysql:mysql /data/mysql5.6/
[root@mymongo1 scripts]# chmod 775 /data/mysql5.6/
[root@mymongo1 scripts]#cd /application/mysql-5.6.36
[root@mymongo1 scripts]# pwd
/application/mysql/scripts
[root@mymongo1 scripts]# ./mysql_install_db --basedir=/application/mysql/ --datadir=/data/mysql5.6/data --user=mysql
2、修改mysql启动控制文件
[root@mymongo1 scripts]# cat /etc/my.cnf
[client]
port = 3306
socket =/data/mysql5.6/tmp/mysql.sock

[mysql]
no-auto-rehash

[mysqld]
datadir=/data/mysql5.6/data
socket=/data/mysql5.6/tmp/mysql.sock
user=mysql
port=3306
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-bin=/data/mysql5.6/mysql-bin
open_files_limit =1024
back_log = 600
max_connections = 800
max_connect_errors = 3000
#table_cache = 614
external-locking =FALSE
thread_stack =192k
#transaction_isolation=READ-COMMITTED
tmp_table_size =2M
max_heap_table_size=2M
long_query_time=1
pid-file =/data/mysql5.6/run/mysqld/mysql_mysqld.pid
relay-log =/data/mysql5.6/relay-bin
relay-log-info-file = /data/mysql5.6/relay-log.info
binlog_cache_size =1M
max_binlog_cache_size=1M
max_binlog_size=2M
expire_logs_days=7
key_buffer_size=16M
read_buffer_size =1M
read_rnd_buffer_size=1M
bulk_insert_buffer_size=1M
lower_case_table_names=1
skip-name-resolve
slave-skip-errors=1031,1062
replicate-ignore-db=mysql
server-id=1
innodb_additional_mem_pool_size=4M

[mysqld_safe]
log-error=/data/mysql5.6/log/mysql.log
pid-file=/data/mysql5.6/run/mysqld/mysqld.pid
[root@mymongo1 scripts]#

3、安装数据库
[root@mymongo1 scripts]# ./mysql_install_db --basedir=/application/mysql --datadir=/data/mysql5.6/data --user=mysql
Installing MySQL system tables...2017-08-24 23:14:36 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-08-24 23:14:36 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-08-24 23:14:36 0 [Note] /application/mysql/bin/mysqld (mysqld 5.6.36-log) starting as process 26813 ...
2017-08-24 23:14:36 7fbd0d5fd720 InnoDB: Warning: Using innodb_additional_mem_pool_size is DEPRECATED. This option may be removed in future releases, together with the option innodb_use_sys_malloc and with the InnoDB's internal memory allocator.
2017-08-24 23:14:36 26813 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-08-24 23:14:36 26813 [Note] InnoDB: The InnoDB memory heap is disabled
2017-08-24 23:14:36 26813 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-08-24 23:14:36 26813 [Note] InnoDB: Memory barrier is not used
2017-08-24 23:14:36 26813 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-08-24 23:14:36 26813 [Note] InnoDB: Using CPU crc32 instructions
2017-08-24 23:14:36 26813 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-08-24 23:14:36 26813 [Note] InnoDB: Completed initialization of buffer pool
2017-08-24 23:14:36 26813 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2017-08-24 23:14:36 26813 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2017-08-24 23:14:36 26813 [Note] InnoDB: Database physically writes the file full: wait...
2017-08-24 23:14:36 26813 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2017-08-24 23:14:36 26813 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2017-08-24 23:14:36 26813 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2017-08-24 23:14:36 26813 [Warning] InnoDB: New log files created, LSN=45781
2017-08-24 23:14:36 26813 [Note] InnoDB: Doublewrite buffer not found: creating new
2017-08-24 23:14:36 26813 [Note] InnoDB: Doublewrite buffer created
2017-08-24 23:14:36 26813 [Note] InnoDB: 128 rollback segment(s) are active.
2017-08-24 23:14:36 26813 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-08-24 23:14:36 26813 [Note] InnoDB: Foreign key constraint system tables created
2017-08-24 23:14:36 26813 [Note] InnoDB: Creating tablespace and datafile system tables.
2017-08-24 23:14:36 26813 [Note] InnoDB: Tablespace and datafile system tables created.
2017-08-24 23:14:36 26813 [Note] InnoDB: Waiting for purge to start
2017-08-24 23:14:36 26813 [Note] InnoDB: 5.6.36 started; log sequence number 0
2017-08-24 23:14:37 26813 [Note] Binlog end
2017-08-24 23:14:37 26813 [Note] InnoDB: FTS optimize thread exiting.
2017-08-24 23:14:37 26813 [Note] InnoDB: Starting shutdown...
2017-08-24 23:14:38 26813 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK

Filling help tables...2017-08-24 23:14:38 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-08-24 23:14:38 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-08-24 23:14:38 0 [Note] /application/mysql/bin/mysqld (mysqld 5.6.36-log) starting as process 26835 ...
2017-08-24 23:14:38 7f5a5b3cd720 InnoDB: Warning: Using innodb_additional_mem_pool_size is DEPRECATED. This option may be removed in future releases, together with the option innodb_use_sys_malloc and with the InnoDB's internal memory allocator.
2017-08-24 23:14:38 26835 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-08-24 23:14:38 26835 [Note] InnoDB: The InnoDB memory heap is disabled
2017-08-24 23:14:38 26835 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-08-24 23:14:38 26835 [Note] InnoDB: Memory barrier is not used
2017-08-24 23:14:38 26835 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-08-24 23:14:38 26835 [Note] InnoDB: Using CPU crc32 instructions
2017-08-24 23:14:38 26835 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-08-24 23:14:38 26835 [Note] InnoDB: Completed initialization of buffer pool
2017-08-24 23:14:38 26835 [Note] InnoDB: Highest supported file format is Barracuda.
2017-08-24 23:14:38 26835 [Note] InnoDB: 128 rollback segment(s) are active.
2017-08-24 23:14:38 26835 [Note] InnoDB: Waiting for purge to start
2017-08-24 23:14:38 26835 [Note] InnoDB: 5.6.36 started; log sequence number 1625977
2017-08-24 23:14:38 26835 [Note] Binlog end
2017-08-24 23:14:38 26835 [Note] InnoDB: FTS optimize thread exiting.
2017-08-24 23:14:38 26835 [Note] InnoDB: Starting shutdown...
2017-08-24 23:14:39 26835 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/application/mysql/bin/mysqladmin -u root password 'new-password'
/application/mysql/bin/mysqladmin -u root -h 192.168.144.132 password 'new-password'

Alternatively you can run:

/application/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

cd . ; /application/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

WARNING: Found existing config file /application/mysql/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /application/mysql/my-new.cnf,
please compare it with your file and take the changes you need.

WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server
[root@mymongo1 scripts]#

4、启动数据库
[root@mymongo1 log]# mkdir -p /data/mysql5.6/run/mysqld
[root@mymongo1 log]# chown -R mysql:mysql /data/mysql5.6/run/mysqld
[root@mymongo1 scripts]# mkdir /data/mysql5.6/tmp -p
[root@mymongo1 log]# chmod 755 /data/mysql5.6/run/mysqld
[root@mymongo1 scripts]# chown -R mysql:mysql /data/mysql5.6/tmp
[root@mymongo1 scripts]# mkdir -p /data/mysql5.6/log/
[root@mymongo1 scripts]# chown mysql:mysql /data/mysql5.6/log/
[root@mymongo1 scripts]# chmod 775 /data/mysql5.6/log/ -R
[root@mymongo1 scripts]# touch /data/mysql5.6/log/mysql.log
[root@mymongo1 log]# chown mysql:mysql /data/mysql5.6/log/mysql.log
[root@mymongo1 scripts]# ps -ef|grep mysql
root 26877 20324 0 23:18 pts/2 00:00:00 grep mysql
[root@mymongo1 scripts]# cd ..
[root@mymongo1 log]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[root@mymongo1 log]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.36-log Source distribution

Copyright (c) 2000, 2017, 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> quit
Bye
[root@mymongo1 log]#
--主节点停止mysql,到备节点启动mysql
[root@arbiter ~]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
[root@arbiter ~]# ps -ef|grep mysql
root 5344 1 0 01:13 pts/2 00:00:00 /bin/sh /application/mysql-5.6/bin/mysqld_safe --datadir=/data/mysql5.6/data --pid-file=/data/mysql5.6/run/mysqld/mysql_mysqld.pid
mysql 5860 5344 8 01:13 pts/2 00:00:01 /application/mysql-5.6/bin/mysqld --basedir=/application/mysql-5.6 --datadir=/data/mysql5.6/data --plugin-dir=/application/mysql-5.6/lib/plugin --user=mysql --log-error=/data/mysql5.6/log/mysql.log --open-files-limit=1024 --pid-file=/data/mysql5.6/run/mysqld/mysql_mysqld.pid --socket=/data/mysql5.6/tmp/mysql.sock --port=3306
root 5893 4987 0 01:13 pts/2 00:00:00 grep mysql
[root@arbiter ~]# netstat -antup|grep 33
tcp 0 0 :::3306 :::* LISTEN 5860/mysqld
tcp 0 0 :::11733 :::* LISTEN 1983/rpc.statd
[root@arbiter ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.36-log Source distribution

Copyright (c) 2000, 2017, 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> quit
Bye
[root@arbiter ~]#

5、修改2个节点的heartbeat的资源配置文件haresources
[root@mymongo1 ~]# cat /etc/ha.d/haresources
arbiter IPaddr::192.168.144.121/24/eth2 httpd

mymongo1 IPaddr::192.168.144.122/24/eth2 drbddisk::data Filesystem::/dev/drbd0::/data::ext4 mysqld

#mysql master
#arbiter IPaddr::192.168.144.11/24/eth2 mysqld

#mysql salve
#mymongo1 IPaddr::192.168.144
文章题目:heartbeat3.0.4-drbd8.9-Mysql5.6--双机互备高可用部署
标题链接:http://csdahua.cn/article/pecspd.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流