Keepalive+Atlas+DRBD+Heartbeat+mysql配置系列(一):安装DRBD

post by rocdk890 / 2019-3-28 0:01 Thursday linux技术
最近在虚拟机里用centos7搭建了一套Keepalive+Atlas+DRBD+Heartbeat+mysql环境,用来进行测试使用,本系列是我在搭建完后来进行编写的,可能会有点遗漏,大家将就看,我尽量做到详细.
系统:centos 7.x(64位)
环境ip:
node1(主节点)IP: 10.0.2.5  主机名:dbm5
node2(从节点)IP: 10.0.2.7  主机名:dbm7
虚拟IP地址(VIP): 10.0.2.10
点击查看原图
1.安装准备
systemctl stop firewalld
systemctl disable firewalld
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
vi /etc/hosts
10.0.2.5 dbm5
10.0.2.7 dbm7

#改完后重启系统
init 6

2.磁盘规划,(dbm5和dbm7都要执行)
因为是虚拟机,把200G里的150G都给了/home,但我习惯了/data,故要进行更改.
umount /home

[root@dbm5 ~]# vi /etc/fstab
把/dev/mapper/centos-home /home                   xfs     defaults        1 2
注释了,如下:
#/dev/mapper/centos-home /home                   xfs     defaults        1 2

[root@dbm5 ~]# lvremove /dev/mapper/centos-home
Do you really want to remove active logical volume home? [y/n]: y
  Logical volume "home" successfully removed

[root@dbm5 ~]# pvs
  PV         VG     Fmt  Attr PSize   PFree
  /dev/sda2  centos lvm2 a--  199.51g 143.62g
可以看到还有143.62G.

[root@dbm5 ~]# lvcreate -n db -L +143.6G centos
  Rounding up size to full physical extent 143.60 GiB
WARNING: xfs signature detected on /dev/centos/db at offset 0. Wipe it? [y/n] y
  Wiping xfs signature on /dev/centos/db.
  Logical volume "db" created

[root@dbm5 ~]# pvs
  PV         VG     Fmt  Attr PSize   PFree
  /dev/sda2  centos lvm2 a--  199.51g 16.00m
[root@dbm5 ~]# mkdir /data

ps:不管是普通分区,还是lv,drbd需要的是干净的分区,不要格式化.

3.时间同步(dbm5和dbm7都要执行)
yum -y install rdate
rdate -s time-b.nist.gov

4.安装drbd (dbm5和dbm7都要执行)
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
yum install -y kmod-drbd84 drbd84-utils
systemctl enable drbd
modprobe drbd

[root@dbm5 ~]# lsmod |grep drbd
drbd                  397041  4
libcrc32c              12644  2 xfs,drbd

4.配置drbd
vi /etc/drbd.d/global_common.conf
global {
        usage-count no;  #是否提供DRBD进行分析


vi /etc/drbd.d/db.res
resource drbd0{
protocol C;

startup { wfc-timeout 0; degr-wfc-timeout 120;}
disk { on-io-error detach;}
net{
timeout 60;
connect-int 10;
ping-int 10;
max-buffers 2048;
max-epoch-size 2048;
}
syncer { rate 1000M;}

on dbm5 {
device /dev/drbd0;
disk /dev/centos/db;
address 10.0.2.5:7788;
meta-disk internal;
}
on dbm7 {
device /dev/drbd0;
disk /dev/centos/db;
address 10.0.2.7:7788;
meta-disk internal;
}
}

ps:
请修改上面配置中的主机名、IP、和disk为自己的具体配置.

5.创建DRBD设备并激活drbd0资源
[root@dbm5 ~]# mknod /dev/drbd0 b 147 0
[root@dbm5 ~]# drbdadm create-md drbd0
等待片刻,显示success表示drbd块创建成功
md_offset 1036290879488
al_offset 1036290846720
bm_offset 1036259221504
Found some data
 ==> This might destroy existing data! <==
Do you want to proceed?
[need to type 'yes' to confirm] yes
initializing activity log
initializing bitmap (30884 KB) to all zero
Writing meta data...
New drbd meta data block successfully created.
success

再执行一次:
[root@dbm5 ~]# drbdadm create-md drbd0
成功激活drbd0
You want me to create a v08 style flexible-size internal meta data block.
There appears to be a v08 flexible-size internal meta data block
already in place on /dev/centos/db at byte offset 1036290879488
Do you really want to overwrite the existing meta-data?
[need to type 'yes' to confirm] yes
md_offset 1036290879488
al_offset 1036290846720
bm_offset 1036259221504
Found some data
 ==> This might destroy existing data! <==
Do you want to proceed?
[need to type 'yes' to confirm] yes
initializing activity log
initializing bitmap (30884 KB) to all zero
Writing meta data...
New drbd meta data block successfully created.

两边都启动drbd:
drbdadm up drbd

查看drbd状态:
cat /proc/drbd
version: 8.4.11-1 (api:1/proto:86-101)
GIT-hash: 66145a308421e9c124ec391a7848ac20203bb03c build by mockbuild@, 2018-11-03 01:26:55
 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:f oos:0

ps:因为还没有决定要以哪边资料为主,所以 ds:Inconsistent,两边都是 Secondary

把dbm5升为主:
[root@dbm5 ~]# drbdadm primary drbd0 --force

查看同步状态:
[root@dbm5 ~]# cat /proc/drbd 
version: 8.4.11-1 (api:1/proto:86-101)
GIT-hash: 66145a308421e9c124ec391a7848ac20203bb03c build by mockbuild@, 2018-04-26 12:10:42
 0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r-----
    ns:286720 nr:0 dw:0 dr:288816 al:8 bm:0 lo:0 pe:1 ua:0 ap:0 ep:1 wo:f oos:1011686200
    [>....................] sync'ed:  0.1% (987972/988252)M
    finish: 6:52:41 speed: 40,812 (40,812) K/sec

只格式化dbm5的磁盘:
[root@dbm5 ~]# mkfs.xfs /dev/drbd0

ps:
备用节点会进行DRBD设备格式化的同步,所以千万不要再在备用节点去进行DRBD设备的格式化

把mysql data指定到/data里:
vim /etc/my.cnf
datadir=/data/mysql

在dbm5上挂载/dev/drbd0到/data
mount /dev/drbd0 /data

6.DRBD测试
drbdadm primary drbd0   #升级为primary
drbdadm secondary drbd0 #降级为secondary

没问题的话,就可以搭建Heartbeat来进行自动控制了.
夜空- 本站版权
1、本站所有主题由该文章作者发表,该文章作者与夜空享有文章相关版权
2、其他单位或个人使用、转载或引用本文时必须同时征得该文章作者和夜空的同意
3、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责
4、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
5、原文链接:blog.slogra.com/post-756.html

标签: 配置 mysql 安装 挂载 drbd fdisk 格式化