配置drbd高可用集群

前期准备:

同步时间

(两个节点)

节点一(172.16.21.6)

[[email protected] heartbeat2]# ntpdate 172.16.0.1

31 Dec 20:59:25 ntpdate[6950]: adjust time server 172.16.0.1 offset 0.379319 sec

[[email protected] heartbeat2]#

?

最好几分钟同步一下

[[email protected] heartbeat2]# crontab -e

no crontab for root - using an empty one

?

*/3 * * * * /usr/sbin/ntpdate 172.16.0.1 &> /dev/null

?

~

~

?

?

节点二:(172.16.21.10)

?

[[email protected] heartbeat2]# ntpdate 172.16.0.1

31 Dec 21:00:50 ntpdate[4737]: adjust time server 172.16.0.1 offset 0.380532 sec

[[email protected] heartbeat2]#

最好每个几分钟同步一下

?

[[email protected] heartbeat2]# crontab -e

no crontab for root - using an empty one

?

*/3 * * * * /usr/sbin/ntpdate 172.16.0.1 &> /dev/null

?

~

~

在节点1 上生成密钥,使得两节点间检测心跳信息无须密码

[[email protected] .ssh]# ssh-keygen -P ‘‘

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

75:cc:d5:7e:f8:ae:d6:c7:7b:36:45:f6:22:a8:06:dc [email protected]

The key‘s randomart image is:

+--[ RSA 2048]----+

| .. |

| o . .|

| . + o |

| . . . =|

| . .S . +o|

| o E . . . +|

| . . . =.|

| o ..B|

| . ..+=|

+-----------------+

[[email protected] .ssh]#

在 节点1 的 /etc/hosts 下增加 " uname -n " 所显示两个节点的内容

172.16.21.6 node1.stu21.com node1(别名)

172.16.21.10 node2.stu21.com node2(别名)

?

[[email protected] ~]# ssh-copy-id -i .ssh/id_rsa.pub [email protected]

?

The authenticity of host ‘node2 (172.16.21.10)‘ can‘t be established.

RSA key fingerprint is 6a:5a:71:de:61:ca:29:01:c2:7d:8d:6f:06:27:2b:b2.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added ‘node2‘ (RSA) to the list of known hosts.

[email protected]‘s password:

Now try logging into the machine, with "ssh ‘[email protected]‘", and check in:

?

.ssh/authorized_keys

?

to make sure we haven‘t added extra keys that you weren‘t expecting.

?

[[email protected] ~]# cd .ssh/

[[email protected] .ssh]# ls

authorized_keys id_rsa id_rsa.pub known_hosts

?

[[email protected] .ssh]# ssh node2 ‘date‘;date

Wed Dec 31 21:38:29 CST 2014

Wed Dec 31 21:38:29 CST 2014

[[email protected] .ssh]#

?

?

[[email protected] ~]# scp /etc/hosts node2:/etc/hosts

hosts 100% 358 0.4KB/s 00:00

[[email protected] ~]#

?

?

在节点2 的终端上生成密钥一份给 节点2的机子上

?

[[email protected] ~]# ssh-keygen -t rsa -P ‘‘

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

fe:fe:67:a7:c2:da:23:a9:91:28:05:4b:06:ea:87:84 [email protected]

The key‘s randomart image is:

+--[ RSA 2048]----+

| . |

|.. . |

|E. + |

|o .o o |

| o .. . S |

| . . o . |

| . . + o |

| . oo.+ o .|

| .o++o=.o |

+-----------------+

[[email protected] ~]#

?

?

[[email protected] ~]# ssh-copy-id -i .ssh/id_rsa.pub [email protected]

?

The authenticity of host ‘node1 (172.16.21.6)‘ can‘t be established.

RSA key fingerprint is 6a:5a:71:de:61:ca:29:01:c2:7d:8d:6f:06:27:2b:b2.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added ‘node1,172.16.21.6‘ (RSA) to the list of known hosts.

[email protected]‘s password:

Permission denied, please try again.

[email protected]‘s password:

Now try logging into the machine, with "ssh ‘[email protected]‘", and check in:

?

.ssh/authorized_keys

?

to make sure we haven‘t added extra keys that you weren‘t expecting.

?

验证下是否能检测对方时间

[[email protected] ~]# ssh node1 ‘date‘ ; date

Wed Dec 31 21:50:55 CST 2014

Wed Dec 31 21:50:55 CST 2014

[[email protected] ~]#

?

?

?

前期准备结束。。。。。

?

?

[[email protected] ~]# lftp 172.16.0.1

lftp 172.16.0.1:~> cd pub/Sources/6.x86_64/drbd/

?

lftp 172.16.0.1:/pub/Sources/6.x86_64/drbd>

lftp 172.16.0.1:/pub/Sources/6.x86_64/drbd> ls

-rw-r--r-- 1 500 500 290076 Sep 15 2013 drbd-8.4.3-33.el6.x86_64.rpm

-rw-r--r-- 1 500 500 148728 Sep 15 2013 drbd-kmdl-2.6.32-358.el6-8.4.3-33.el6.x86_64.rpm

-rw-r--r-- 1 0 0 149004 Apr 17 2014 drbd-kmdl-2.6.32-431.11.2.el6.centos.plus-8.4.3-33.el6.x86_64.rpm

-rw-r--r-- 1 0 0 148716 Apr 17 2014 drbd-kmdl-2.6.32-431.el6-8.4.3-33.el6.x86_64.rpm

-rw-r--r-- 1 0 0 316878 Jan 02 03:38 drbd84-kmod-8.4.5-2.el6.elrepo.src.rpm

-rw-r--r-- 1 0 0 316737 Jan 02 04:08 drbd84-kmod-8.4.5-504.1.el6.src.rpm

-rw-r--r-- 1 0 0 738021 Aug 18 03:16 drbd84-utils-8.9.1-1.el6.elrepo.src.rpm

-rw-r--r-- 1 0 0 468732 Aug 18 03:14 drbd84-utils-8.9.1-1.el6.elrepo.x86_64.rpm

-rw-r--r-- 1 0 0 189208 Oct 28 14:35 kmod-drbd84-8.4.5-2.el6.elrepo.x86_64.rpm

-rw-r--r-- 1 0 0 188824 Jan 02 04:08 kmod-drbd84-8.4.5-504.1.el6.x86_64.rpm

lftp 172.16.0.1:/pub/Sources/6.x86_64/drbd> mget kmod-drbd84-8.4.5-504.1.el6.x86_64.rpm drbd84-utils-8.9.1-1.el6.elrepo.x86_64.rpm

?

?

?

?

[[email protected] ~]# ls

anaconda-ks.cfg install.log kmod-drbd84-8.4.5-504.1.el6.x86_64.rpm

drbd84-utils-8.9.1-1.el6.elrepo.x86_64.rpm install.log.syslog rpmbuild

[[email protected] ~]# rpm -ivh kmod-drbd84-8.4.5-504.1.el6.x86_64.rpm drbd84-utils-8.9.1-1.el6.elrepo.x86_64.rpm

warning: drbd84-utils-8.9.1-1.el6.elrepo.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID baadae52: NOKEY

Preparing... ########################################### [100%]

1:drbd84-utils ########################################### [ 50%]

2:kmod-drbd84 ########################################### [100%]

Working. This may take some time ...

Done.

[[email protected] ~]#

ps :上面的一个警告不会影响,不用担心

?

节点node1 装完,再配置节点node2,此处省略,跟上面步骤一样

?

两个节点分别准备一个磁盘分区:

????[[email protected] ~]# fdisk /dev/sda

?

WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to

switch off the mode (command ‘c‘) and change display units to

sectors (command ‘u‘).

?

Command (m for help): p

?

Disk /dev/sda: 128.8 GB, 128849018880 bytes

255 heads, 63 sectors/track, 15665 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: 0x00069751

?

Device Boot Start End Blocks Id System

/dev/sda1 * 1 26 204800 83 Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2 26 7859 62914560 8e Linux LVM

?

Command (m for help): n

Command action

e extended

p primary partition (1-4)

p

Partition number (1-4): 3

First cylinder (7859-15665, default 7859):

Using default value 7859

Last cylinder, +cylinders or +size{K,M,G} (7859-15665, default 15665): +2G

?

Command (m for help): w

The partition table has been altered!

?

Calling ioctl() to re-read partition table.

?

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table. The new table will be used at

the next reboot or after you run partprobe(8) or kpartx(8)

Syncing disks.

[[email protected] ~]# partx -a /dev/sda

BLKPG: Device or resource busy

error adding partition 1

BLKPG: Device or resource busy

error adding partition 2

[[email protected] ~]# partx -a /dev/sda

BLKPG: Device or resource busy

error adding partition 1

BLKPG: Device or resource busy

error adding partition 2

BLKPG: Device or resource busy

error adding partition 3

[[email protected] ~]# cat /proc/partitions

major minor #blocks name

?

8 0 125829120 sda

8 1 204800 sda1

8 2 62914560 sda2

8 3 2103516 sda3

253 0 20971520 dm-0

253 1 2097152 dm-1

253 2 10485760 dm-2

253 3 20971520 dm-3

[[email protected] ~]#

?

节点node2 也是按照上步骤来进行

?

?

接下来是启用drbd集群

[[email protected] ~]# cd /etc/drbd.d/

[[email protected] drbd.d]# ls

global_common.conf

[[email protected] drbd.d]# vim global_common.conf

下面参数段,按我这个来设置

?

?

?

????

?

?

[[email protected] drbd.d]# vim mystore.res

????resource mystore {

?

on node1.stu21.com {

device /dev/drbd0;

disk /dev/sda3;

address 172.16.21.1:7789;

meta-disk internal;

}

on node2.stu21.com {

device /dev/drbd0;

disk /dev/sda3;

address 172.16.21.2:7789;

meta-disk internal;

}

}

~

~

????????

?

同样节点node2 也是同样设置:

????????[[email protected] drbd.d]#

[[email protected] drbd.d]# scp * node2:/etc/drbd.d/

global_common.conf 100% 2108 2.1KB/s 00:00

mystore.res 100% 253 0.3KB/s 00:00

[[email protected] drbd.d]#

?

????

?

?

资源初始化(drbd设备)(两节点都要设置)

????节点1

????[[email protected] drbd.d]# drbdadm create-md mystore

initializing activity log

NOT initializing bitmap

Writing meta data...

New drbd meta data block successfully created.

[[email protected] drbd.d]#

????

?

别忘了节点2

????[[email protected] ~]# drbdadm create-md mystore

initializing activity log

NOT initializing bitmap

Writing meta data...

New drbd meta data block successfully created.

[[email protected] ~]#

?

启动brdb设备服务

节点1:

?

????[[email protected] drbd.d]# service drbd start

Starting DRBD resources: [

create res: mystore

prepare disk: mystore

adjust disk: mystore

adjust net: mystore

]

..........

***************************************************************

DRBD‘s startup script waits for the peer node(s) to appear.

- In case this node was already a degraded cluster before the

reboot the timeout is 0 seconds. [degr-wfc-timeout]

- If the peer was available before the reboot the timeout will

expire after 0 seconds. [wfc-timeout]

(These values are for resource ‘mystore‘; 0 sec -> wait forever)

To abort waiting enter ‘yes‘ [ 38]:

.

[[email protected] drbd.d]#

?

节点2:

????????[[email protected] ~]# service drbd start

Starting DRBD resources: [

create res: mystore

prepare disk: mystore

adjust disk: mystore

adjust net: mystore

]

.

[[email protected] ~]#

?

?

当前drbd同步状态的信息

????我在节点一

????????[[email protected] drbd.d]# watch -n 10 ‘cat /proc/drbd‘

????????

因为没有做主从同步,所以只有secondary(节点的测试也是这样的,我就不测了)

?

对于上一步骤,也可以用下面的命令来查看drbd的状态信息

????[[email protected] drbd.d]# drbd-overview

0:mystore/0 Connected Secondary/Secondary Inconsistent/Inconsistent

[[email protected] drbd.d]#

?

强行提升主从角色:步骤如下

节点1:

[[email protected] drbd.d]# drbdadm primary --force mystore

再次查看drbd状态信息,与之前开始不一样啦

[[email protected] drbd.d]# drbd-overview

0:mystore/0 SyncSource Primary/Secondary UpToDate/Inconsistent

????[=>..................] sync‘ed: 10.2% (1892468/2103412)K

节点2

[[email protected] ~]# drbd-overview

0:mystore/0 Connected Secondary/Primary UpToDate/UpToDate

[[email protected] ~]#

在尝试用下面的命令多次观察状态信息

[[email protected] drbd.d]# watch -n 100 ‘cat /proc/drbd‘

出现以上图片内容,说明同步结束(UpToDate/UpToDate)

?

?

?

?

接下来就是开始格式化,那么节点2会被同步初始化,用命令 blkid 查看

节点1:

[[email protected] drbd.d]# mke2fs -t ext4 /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

131648 inodes, 525853 blocks

26292 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=541065216

17 block groups

32768 blocks per group, 32768 fragments per group

7744 inodes per group

Superblock backups stored on blocks:

????32768, 98304, 163840, 229376, 294912

?

Writing inode tables: done

Creating journal (16384 blocks): done

Writing superblocks and filesystem accounting information: done

?

This filesystem will be automatically checked every 21 mounts or

180 days, whichever comes first. Use tune2fs -c or -i to override.

[[email protected] drbd.d]#

?

[[email protected] drbd.d]# mount /dev/drbd0 /mnt

[[email protected] drbd.d]# cd /mnt

[[email protected] mnt]# cp /etc/fstab /mnt

[[email protected] mnt]# ls

fstab lost+found

[[email protected] mnt]# vim fstab

[[email protected] mnt]# cd

实现节点1降级之前可不能有挂载

[[email protected] ~]# umount /mnt

[[email protected] ~]# drbdadm secondary mystore

[[email protected] ~]# drbd-overview

0:mystore/0 Connected Secondary/Secondary UpToDate/UpToDate

[[email protected] ~]#

那么节点2得升级

[[email protected] ~]#

[[email protected] ~]# drbdadm primary mystore

[[email protected] ~]# drbd-overview

0:mystore/0 Connected Primary/Secondary UpToDate/UpToDate

[[email protected] ~]#

?

不要格式化,因为已经同步好了

[[email protected] ~]# mount /dev/drbd0 /mnt

[[email protected] ~]# cd /mnt

[[email protected] mnt]# ls

fstab lost+found

下面的文件出现new,说明同步是好的

[[email protected] mnt]# cat fstab

#

# /etc/fstab

# Created by anaconda on Thu Jan 1 10:48:34 2015

#

# Accessible filesystems, by reference, are maintained under ‘/dev/disk‘

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

/dev/mapper/vg0-root / ext4 defaults 1 1

UUID=3d45455f-a8d5-4961-a79a-e61f9ab247df /boot ext4 defaults 1 2

/dev/mapper/vg0-usr /usr ext4 defaults 1 2

/dev/mapper/vg0-var /var ext4 defaults 1 2

/dev/mapper/vg0-swap swap swap defaults 0 0

tmpfs /dev/shm tmpfs defaults 0 0

devpts /dev/pts devpts gid=5,mode=620 0 0

sysfs /sys sysfs defaults 0 0

proc /proc proc defaults 0 0

newline

[[email protected] mnt]#

出现上面的错误信息,源于未卸载

[[email protected] ~]# umount /mnt

[[email protected] ~]# drbdadm secondary mystore

[[email protected] ~]# drbd-overview

0:mystore/0 Connected Secondary/Secondary UpToDate/UpToDate

如果以后我们希望通过高可用集群来管理,因为任何服务,配用高可用集群,那么我们得关掉这个服务。

[[email protected] ~]# service drbd stop

Stopping all DRBD resources: .

[[email protected] ~]# chkconfig drbd off

[[email protected] ~]#

?

还没有完成,既然节点2降级,那么节点1必须升级才行

[[email protected] ~]#

[[email protected] ~]# drbdadm primary mystore

[[email protected] ~]# drbd-overview

0:mystore/0 Connected Primary/Secondary UpToDate/UpToDate

[[email protected] ~]#

然后也得关掉服务,为配置高可用集群做准备

[[email protected] ~]# service drbd stop

Stopping all DRBD resources: .

[[email protected] ~]# chkconfig drbd off

[[email protected] ~]#

?

?

?

接下就是让drbd成为高可用集群的可用资源

?

节点1:

[[email protected] ~]# yum -y install corosync pacemaker

节点2:

[[email protected] ~]# yum -y install corosync pacemaker

?

?

如何配置主从资源?集群中的主机节点的切换而切换,再配置成高可用性的MYSQL的集群

模型:corosync + pacemaker +drbd + drbd

?

?

配置corosync

节点 1:

?

[[email protected] ~]# cd /etc/corosync/

[[email protected] corosync]# ls

corosync.conf.example corosync.conf.example.udpu service.d uidgid.d

[[email protected] corosync]# cp corosync.conf.example corosync.conf

[[email protected] corosync]#

?

[[email protected] corosync]# vim corosync.conf

?

?

?

?

?

?

关掉to_syslog:yes

?

?

?

?

保存退出

?

[[email protected] corosync]# corosync-keygen

Corosync Cluster Engine Authentication key generator.

Gathering 1024 bits for key from /dev/random.

Press keys on your keyboard to generate entropy.

Press keys on your keyboard to generate entropy (bits = 320).

Press keys on your keyboard to generate entropy (bits = 384).

Press keys on your keyboard to generate entropy (bits = 448).

Press keys on your keyboard to generate entropy (bits = 512).

Press keys on your keyboard to generate entropy (bits = 584).

Press keys on your keyboard to generate entropy (bits = 680).

Press keys on your keyboard to generate entropy (bits = 744).

Press keys on your keyboard to generate entropy (bits = 808).

Press keys on your keyboard to generate entropy (bits = 872).

Press keys on your keyboard to generate entropy (bits = 952).

Writing corosync key to /etc/corosync/authkey.

?

密钥生成随机数,如果熵池里边不够,我们可以再打开一个会话口,下载我们接下来要用的mariadb来填充熵池

[[email protected] ~]# lftp 172.16.0.1

lftp 172.16.0.1:~> cd pub/Sources/6.x86_64/ma

mariadb/ maven/

lftp 172.16.0.1:~> cd pub/Sources/6.x86_64/mariadb/

lftp 172.16.0.1:/pub/Sources/6.x86_64/mariadb> ls

-rw-r--r-- 1 500 500 295874759 Apr 08 2014 mariadb-10.0.10-linux-x86_64.tar.gz

-rw-r--r-- 1 500 500 222365728 Apr 08 2014 mariadb-5.5.36-linux-x86_64.tar.gz

-rw-r--r-- 1 0 0 222617820 Oct 08 17:03 mariadb-5.5.40-linux-x86_64.tar.gz

-rw-r--r-- 1 500 500 99278301 Sep 04 2013 mariadb-galera-5.5.32-linux-x86_64.tar.gz

drwxr-xr-x 2 0 0 4096 Apr 08 2014 mariadb10

lftp 172.16.0.1:/pub/Sources/6.x86_64/mariadb> get mariadb-5.5.40-linux-x86_64.tar.gz 222617820 bytes transferred in 25 seconds (8.60M/s)

lftp 172.16.0.1:/pub/Sources/6.x86_64/mariadb>

?

节点1:在此目录下生成了密钥 authkey

[[email protected] corosync]# ll

total 24

-r-------- 1 root root 128 Jan 3 08:56 authkey

-rw-r--r-- 1 root root 2700 Jan 2 23:28 corosync.conf

-rw-r--r-- 1 root root 2663 Oct 15 14:19 corosync.conf.example

-rw-r--r-- 1 root root 1073 Oct 15 14:19 corosync.conf.example.udpu

drwxr-xr-x 2 root root 4096 Oct 15 14:19 service.d

drwxr-xr-x 2 root root 4096 Oct 15 14:19 uidgid.d

[[email protected] corosync]#

?

同样节点2 也得同样上面步骤设置

[[email protected] corosync]# scp -rp authkey corosync.conf node2:/etc/corosync/

authkey 100% 128 0.1KB/s 00:00

corosync.conf 100% 2700 2.6KB/s 00:00

?

查看节点2 的 /etc/porosync 目录

[[email protected] corosync]# ll

total 24

-r-------- 1 root root 128 Jan 3 08:56 authkey

-rw-r--r-- 1 root root 2700 Jan 2 23:28 corosync.conf

-rw-r--r-- 1 root root 2663 Oct 15 14:19 corosync.conf.example

-rw-r--r-- 1 root root 1073 Oct 15 14:19 corosync.conf.example.udpu

drwxr-xr-x 2 root root 4096 Oct 15 14:19 service.d

drwxr-xr-x 2 root root 4096 Oct 15 14:19 uidgid.d

[[email protected] corosync]#

?

?

可以启动集群corosync

节点1 :

[[email protected] corosync]# service corosync start

Starting Corosync Cluster Engine (corosync): [ OK ]

[[email protected] corosync]#

?

节点2:

[[email protected] corosync]# service corosync start

Starting Corosync Cluster Engine (corosync): [ OK ]

[[email protected] corosync]#

?

节点1:查看集群日记信息

[[email protected] corosync]# tail /var/log/cluster/corosync.log

?

节点2:

[[email protected] corosync]# tail /var/log/cluster/corosync.log

?

切记:上面corosync配置才能配置 corosync的yum源

节点1 :

[[email protected] yum.repos.d]# ls

centos6.6.repo CentOS-Debuginfo.repo CentOS-Media.repo

CentOS-Base.repo.bak CentOS-fasttrack.repo CentOS-Vault.repo

[[email protected] yum.repos.d]# vim corosync.repo

[[email protected] yum.repos.d]# cat corosync.repo

[corosync]

name=Corosync 2 from suse

baseurl=ftp://172.16.0.1/pub/Sources/6.x86_64/corosync

gpgcheck=0

enabled=1

?

[[email protected] yum.repos.d]#

?

节点2:

[[email protected] yum.repos.d]# scp corosync.repo node2:/etc/yum.repos.d/

corosync.repo

?

?

本地安装crmsh

节点1:

[[email protected] yum.repos.d]# yum install crmsh –y

?

?

节点2:

[[email protected] corosync]# yum install crmsh -y

?

查看当前crm状态

节点1:

[[email protected] yum.repos.d]# crm status

?

节点2:

[[email protected] corosync]# crm status

?

?

?

?

?

节点1:

[[email protected] corosync]# crm_verify -L –V

?

这里可能会报错,因此我们得关掉stonith

[[email protected] corosync]# crm

crm(live)# configure

crm(live)configure# property stonith-enabled=false

crm(live)configure# commit

crm(live)configure# property no-quorum-policy=ignore

crm(live)configure# commit

crm(live)configure# show

node node1.stu21.com

node node2.stu21.com

property cib-bootstrap-options:

????dc-version=1.1.11-97629de

????cluster-infrastructure="classic openais (with plugin)"

????expected-quorum-votes=2

????stonith-enabled=false

????no-quorum-policy=ignore

crm(live)configure# cd

crm(live)# ra

crm(live)ra# list ocf pacemaker

ClusterMon Dummy HealthCPU HealthSMART Stateful SysInfo SystemHealth

controld ping pingd remote

crm(live)ra# classes

lsb

ocf / heartbeat linbit pacemaker

service

stonith

crm(live)ra# list ocf linbit

drbd

?

crm(live)ra# cd

crm(live)# configure

crm(live)configure# primitive mydrbd ocf:linbit:drbd params drbd_resource="mystore" op monitor role=Slave interval=20s timeout=20s op monitor role=Master interval=10s timeout=20s op start timeout=240s op stop timeout=100s

crm(live)configure# verity

ERROR: configure.verity: No such command

出现错误是因为verify 错写成verity,那么就把mydrbd 删除,再重新设置

crm(live)configure# delete mydrbd

crm(live)configure# primitive mydrbd ocf:linbit:drbd params drbd_resource="mystore" op monitor role=Slave interval=20s timeout=20s op monitor role=Master interval=10s timeout=20s op start timeout=240s op stop timeout=100s

crm(live)configure# verify

crm(live)configure#

?

crm(live)configure# ms ms_mydrbd mydrbd meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"

crm(live)configure# show

node node1.stu21.com

node node2.stu21.com

primitive mydrbd ocf:linbit:drbd

????params drbd_resource=mystore

????op monitor role=Slave interval=20s timeout=20s

????op monitor role=Master interval=10s timeout=20s

????op start timeout=240s interval=0

????op stop timeout=100s interval=0

ms ms_mydrbd mydrbd

????meta master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true

property cib-bootstrap-options:

????dc-version=1.1.11-97629de

????cluster-infrastructure="classic openais (with plugin)"

????expected-quorum-votes=2

????stonith-enabled=false

????no-quorum-policy=ignore

crm(live)configure# verify

crm(live)configure# commit

crm(live)configure# cd

crm(live)# status

Last updated: Sat Jan 3 11:07:22 2015

Last change: Sat Jan 3 11:07:11 2015

Stack: classic openais (with plugin)

Current DC: node1.stu21.com - partition with quorum

Version: 1.1.11-97629de

2 Nodes configured, 2 expected votes

2 Resources configured

?

?

Online: [ node1.stu21.com node2.stu21.com ]

?

Master/Slave Set: ms_mydrbd [mydrbd]

Masters: [ node1.stu21.com ]

Slaves: [ node2.stu21.com ]

crm(live)#

?

在节点1 由上面看出我们设置的是主节点

?

那么检测节点2是否是从的

[[email protected] corosync]# cd

[[email protected] ~]# drbd-overview

0:mystore/0 Connected Secondary/Primary UpToDate/UpToDate

由上面看出,我们定义的节点1主,节点2从是正确的

?

假如我们把node1变成主从节点的备用节点,该如何设置?

此时在节点1上:

[[email protected] ~]# drbd-overview

0:mystore/0 Connected Primary/Secondary UpToDate/UpToDate

[[email protected] ~]# crm node standby

[[email protected] ~]# drbd-overview

0:mystore/0 Unconfigured . .

[[email protected] ~]# crm status

Node node1.stu21.com: standby

Online: [ node2.stu21.com ]

?

Master/Slave Set: ms_mydrbd [mydrbd]

Masters: [ node2.stu21.com ]

Stopped: [ node1.stu21.com ]

?

由上面看出node1已经停啦,node2变成主的

验证节点2是否是主的,看看我们的猜想是否正确

[[email protected] ~]# drbd-overview

0:mystore/0 WFConnection Primary/Unknown UpToDate/DUnknown

[[email protected] ~]#

????出现Unknown是因为节点没有上线,我们可以在节点1上设置,让它重新上线

????步骤是在节点1上执行 [[email protected] ~]# crm node online

在节点2上,再次查看

????????[[email protected] ~]# drbd-overview

0:mystore/0 Connected Primary/Secondary UpToDate/UpToDate

[[email protected] ~]#

?

在节点1上:

[[email protected] ~]# crm status

Online: [ node1.stu21.com node2.stu21.com ]

?

Master/Slave Set: ms_mydrbd [mydrbd]

Masters: [ node2.stu21.com ]

Slaves: [ node1.stu21.com ]

由上面操作发现主从互换啦

?

?

我还可以把上面复原回来,让主的还是节点1 ,从的是节点2

只需在节点2上执行:

[[email protected] ~]# crm node standby

[[email protected] ~]# crm status

????Node node2.stu21.com: standby

Online: [ node1.stu21.com ]

?

Master/Slave Set: ms_mydrbd [mydrbd]

Masters: [ node1.stu21.com ]

Stopped: [ node2.stu21.com ]

?

?

[[email protected] ~]# crm node online

[[email protected] ~]# crm status

Online: [ node1.stu21.com node2.stu21.com ]

?

Master/Slave Set: ms_mydrbd [mydrbd]

Masters: [ node1.stu21.com ]

Slaves: [ node2.stu21.com ]

?

创建文件系统

怎么定义一个filesystem啦?

打开crm

[[email protected] ~]# mkdir /mydata

[[email protected] ~]# crm

crm(live)# configure

crm(live)configure# primitive myfs ocf:heartbeat:Filesystem params device=/dev/drbd0 directory=/mydata fstype="ext4" op monitor interval=20s timeout=40s op start timeout=60s op stop timeout=60s

crm(live)configure# verify

?

crm(live)configure# colocation myfs_with_ms_mydrbd_master inf: myfs ms_mydrbd:Master

crm(live)configure# order ms_mydrbd_master_before_myfs inf: ms_mydrbd:promote myfs:start

crm(live)configure# verify

crm(live)configure# commit

crm(live)configure# cd

crm(live)# status

?


myfs工作在节点1,而节点1又是主节点

?

?

?

下面我是在两节点上测试两节点的高可用性

?

节点1:

[[email protected] ~]# cd /mydata/

[[email protected] mydata]# ls

fstab lost+found

[[email protected] mydata]# rm fstab

rm: remove regular file `fstab‘? y

[[email protected] mydata]# ls

lost+found

[[email protected] mydata]#

删除的fstab,那么节点2同时也会删除的

?

我们把当前主节点(node1)变成备用节点

[[email protected] ~]# crm node standby

[[email protected] ~]# crm status


此时的myfs已经挂载到到节点2(node2),节点1未上线,且节点2(node2)成主节点

此时在节点1上,切换到 /mydata 查看会发现什么也没有,同时查看挂载点

#mount 不能找到 /dev/drbd0 on /mydata type ext4 (rw)

#cd /mydata

#ls

相反在节点2上:

????????????[[email protected] ~]# cd /mydata/

[[email protected] mydata]# ls

lost+found

?

[[email protected] mydata]# mount


?

?

????????????

?

节点1(node1):

[[email protected] ~]# crm node online

[[email protected] ~]# crm status


此时节点1(又重新上线啦)

?

?

?

节点2:

由于上面,节点2(node2)是主,我们把它变成备用节点

[[email protected] ~]# crm node standby

[[email protected] ~]# crm status


?

让节点2 从新上线

[[email protected] ~]# crm node online

[[email protected] ~]# crm status


?

?

两个节点测试完毕

?

接下来配置MYSQL高可用集群

先配置节点1:(确保主节点在node1)


?

[[email protected] ~]# groupadd -r -g 306 mysql

[[email protected] ~]# useradd -r -g 306 -u 306 mysql

[[email protected] ~]# tar xf mariadb-5.5.40-linux-x86_64.tar.gz -C /usr/local/

[[email protected] ~]# cd /usr/local

[[email protected] local]# ls

bin etc games include lib lib64 libexec mariadb-5.5.40-linux-x86_64 sbin share src

[[email protected] local]# ln mariadb-5.5.40-linux-x86_64 mysql -sv

`mysql‘ -> `mariadb-5.5.40-linux-x86_64‘

[[email protected] local]# ls

bin etc games include lib lib64 libexec mariadb-5.5.40-linux-x86_64 mysql sbin share src

[[email protected] local]#


?

?

节点2(node2):

????????参照节点1,步骤完全一样

?

继续节点1(node1):

[[email protected] local]# mkdir /mydata/data

[[email protected] local]# chown -R mysql:mysql /mydata/data/

[[email protected] local]# cd mysql/

[[email protected] mysql]# ll

total 220

drwxr-xr-x 2 root root 4096 Jan 3 14:02 bin

-rw-r--r-- 1 500 500 17987 Oct 8 21:19 COPYING

-rw-r--r-- 1 500 500 26545 Oct 8 21:19 COPYING.LESSER

drwxr-xr-x 3 root root 4096 Jan 3 14:02 data

-rw-r--r-- 1 500 500 8245 Oct 8 21:19 EXCEPTIONS-CLIENT

drwxr-xr-x 3 root root 4096 Jan 3 14:02 include

-rw-r--r-- 1 500 500 8694 Oct 8 21:19 INSTALL-BINARY

drwxr-xr-x 3 root root 4096 Jan 3 14:02 lib

drwxr-xr-x 4 root root 4096 Jan 3 14:02 man

drwxr-xr-x 11 root root 4096 Jan 3 14:02 mysql-test

-rw-r--r-- 1 500 500 108813 Oct 8 21:19 README

drwxr-xr-x 2 root root 4096 Jan 3 14:02 scripts

drwxr-xr-x 27 root root 4096 Jan 3 14:02 share

drwxr-xr-x 4 root root 4096 Jan 3 14:02 sql-bench

drwxr-xr-x 3 root root 4096 Jan 3 14:02 support-files

[[email protected] mysql]# pwd

/usr/local/mysql

?

[[email protected] mysql]# chown -R root:mysql ./*

[[email protected] mysql]# ll

total 220

drwxr-xr-x 2 root mysql 4096 Jan 3 14:02 bin

-rw-r--r-- 1 root mysql 17987 Oct 8 21:19 COPYING

-rw-r--r-- 1 root mysql 26545 Oct 8 21:19 COPYING.LESSER

drwxr-xr-x 3 root mysql 4096 Jan 3 14:02 data

-rw-r--r-- 1 root mysql 8245 Oct 8 21:19 EXCEPTIONS-CLIENT

drwxr-xr-x 3 root mysql 4096 Jan 3 14:02 include

-rw-r--r-- 1 root mysql 8694 Oct 8 21:19 INSTALL-BINARY

drwxr-xr-x 3 root mysql 4096 Jan 3 14:02 lib

drwxr-xr-x 4 root mysql 4096 Jan 3 14:02 man

drwxr-xr-x 11 root mysql 4096 Jan 3 14:02 mysql-test

-rw-r--r-- 1 root mysql 108813 Oct 8 21:19 README

drwxr-xr-x 2 root mysql 4096 Jan 3 14:02 scripts

drwxr-xr-x 27 root mysql 4096 Jan 3 14:02 share

drwxr-xr-x 4 root mysql 4096 Jan 3 14:02 sql-bench

drwxr-xr-x 3 root mysql 4096 Jan 3 14:02 support-files

[[email protected] mysql]#

?

接下来执行MYSQL的初始化

[[email protected] mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data/

验证下,看文件有没有

[[email protected] mysql]# ls /mydata/data/

aria_log.00000001 aria_log_control mysql performance_schema test

?

?

?

[[email protected] mysql]# mkdir /etc/mysql

[[email protected] mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf

[[email protected] mysql]# vim /etc/mysql/my.cnf

?

datadir = /mydata/data

innodb_file_per_table = on

skip_name_resolve = on


?

对于上面节点1 的操作,节点2(node2)按照原样步骤进行配置

?

?

节点1:

添加MYSQL开机启动启动脚本

[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld

[[email protected] mysql]# chkconfig --add mysqld

[[email protected] mysql]# chkconfig mysqld off

[[email protected] mysql]#

?

[[email protected] mysql]# service mysqld start

Starting MySQL.... [ OK ]

[[email protected] mysql]# /usr/local/mysql/bin/mysql

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 2

Server version: 5.5.40-MariaDB-log MariaDB Server

?

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

?

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

?

MariaDB [(none)]> create database testdb;

Query OK, 1 row affected (0.00 sec)

?

MariaDB [(none)]> exit

Bye


?

[[email protected] mysql]# cd

[[email protected] ~]# service mysqld stop

Shutting down MySQL.

?

-------------------------------------------------------------------(从下面就开始出错,由于节点2上的数据库不要初始化)

?

接下来是对节点2(node2)的设置:

同样的重复上面节点1的步骤,加入启动脚本

不同处只需要增加如下

MariaDB [(none)]> grant all on *.* to ‘root‘@‘172.16.%.%‘ identified by ‘mageedu‘;

Query OK, 0 rows affected (0.00 sec)

?

MariaDB [(none)]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

?

MariaDB [(none)]> \q

#定义数据库集群的VIP

[[email protected] ~]# crm

crm(live)# configure

crm(live)configure# primitive myip ocf:heartbeat:IPaddr params ip="172.16.21.150" op monitor interval=10s timeout=20s

crm(live)configure# verify

crm(live)configure#

#定义数据库集群的服务资源mysqld

crm(live)configure# primitive myserver lsb:mysqld op monitor interval=20s timeout=20s

crm(live)configure# verify

?

?

#将资源加入资源组,进行结合资源在一起

?

crm(live)configure# group myservice myip ms_mydrbd:Master myfs myserver

ERROR: myservice refers to missing object ms_mydrbd:Master

INFO: resource references in colocation:myfs_with_ms_mydrbd_master updated

INFO: resource references in order:ms_mydrbd_master_before_myfs updated

crm(live)configure# verify

?

上面的错误不影响,继续执行下面的步骤

#定义资源顺序约束,启动好myfs资源后再启动myserver资源:

?

crm(live)configure# order myfs_before_myserver inf: myfs:start myserver:start

crm(live)configure# verify

crm(live)configure# commit

#所有都定义完成后就提交!可能mysql服务启动有点慢,等一下即可!

crm(live)configure# cd

crm(live)# status

crm(live)# status

????????????

????????????????Online: [ node13.stu21.com node14.stu21.com ]

?

???? ????????????Master/Slave Set: ms_mydrbd [mydrbd]

???????? Masters: [ node14.stu21.com ]

???????? Slaves: [ node13.stu21.com ]

???????????? Resource Group: myservice

???????????? myip (ocf::heartbeat:IPaddr): Started node14.stu21.com

???????????? myfs (ocf::heartbeat:Filesystem): Started node14.stu21.com

???????? myserver (lsb:mysqld): Started node14.stu21.com

?

?

?

?

?

时间: 2024-10-04 03:45:18

配置drbd高可用集群的相关文章

Linux高可用集群方案之配置heartbeat v2基于crm+hb_gui接口,配置ipvs高可用集群

  基于crm+hb_gui接口配置ipvs高可用集群    基于crm+hb_gui+ldirectored接口配置ipvs高可用集群 

配置MySQL高可用集群MHA

配置MySQL高可用集群+++++++++++++++++++主机角色 :客户端 client50数据库服务器 mysql51 到 mysql55管理主机 mgm56VIP地址 192.168.4.100拓扑结构: client50 | mysql51主 | | | | | |mysql52 mysql53 mysql54 mysql55 mgm56从 从 从 从 管理集群备用主 备用主+++++++++++++++++++++++++++++++++++++++++++++++++++++++

图形界面配置heartbeat高可用集群

修改ha.cf配置文件,启用crm功能,表示资源配置交给crm管理 [[email protected] ~]# vim /etc/ha.d/ha.cf crm on 使用自带的ha_propagate脚本同步配置文件 [[email protected] ~]# /usr/lib/heartbeat/ha_propagate 安装heartbeat-gui包 [[email protected] heartbeat2]# rpm -ivhheartbeat-gui-2.1.4-12.el6.x

corosync+drbd实现mariadb高可用集群

配置前的准备 (1)节点间时间必须同步:使用ntp协议实现: [[email protected] ~]# ntpdate 172.16.0.1       #172.16.0.1是我这里的时间服务器 [[email protected] ~]# ntpdate 172.16.0.1 (2) 节点间需要通过主机名互相通信,必须解析主机至IP地址: (a)建议名称解析功能使用hosts文件来实现: (b)通信中使用的名字与节点名字必须保持一致:"uname -n"命令,或"ho

Linux高可用集群方案之配置heartbeat v2基于crm+hb_gui接口,配置http+msyql+nfs高可用集群

  基于crm+hb_gui接口配置http+mysql+nfs高可用集群    基于crm+hb_gui接口配置ipvs高可用集群    基于crm+hb_gui+ldirectored接口配置ipvs高可用集群 

Linux高可用集群方案之配置heartbeat v2基于haresources配置文件的httpd高可用集群

本章主要配置heartbeat v2基于haresources配置文件的httpd高可用集群.  ll  本文导航    · 前期准备   · 安装heartbeat v2   · node1.node2主机安装httpd   · shared-nfs主机安装nfs   · 配置httpd高可用集群   · 客户端访问测试  ll  要求  完全掌握heartbeat v2基于haresources配置文件的httpd高可用服务.   前期准备  1.heartbeat服务主机规划 主机 接口

简单的高可用集群实验

前言: 上文介绍了高可用集群的基本概念,下面让我们来试试用两台提供web服务的虚拟机来实现一个小小的高可用集群吧- 首先,配置一个高可用集群的前提有: 1.至少两个节点: 2.共享存储(为了提供的页面一致,需要在后端用某些机制来实现.这里我们就做个简单的实验,后端存储先不考虑.先让这两个节点各自提供一个不同的页面,方便我们知道哪台在提供服务): 3.STONIN(共享存储时为了避免争用资源,指挥特定的设备,如电源交换机等避免共享存储的崩溃,所以一般的集群都得需要这个否则它会不工作的哦~~这里我们

高可用集群

高可用集群是指以减少服务中断时间为目的的服务器集群技术.它通过保护用户的业务程序对外不间断提供的服务,把因软件/硬件/人为造成的故障对业务的影响降低到最小程度.高可用集群的应用系统有多样化发展趋势,用途也越来越多样化,同时带来了配置及可操作性方面的复杂性,因此选择好的高可用软件至关重要. 实验环境:真机:172.25.254.29                    server4:172.25.29.4                    server5:172.25.29.5      

CentOS 7下搭建高可用集群

一 .安装集群软件 必须软件pcs,pacemaker,corosync,fence-agents-all,如果需要配置相关服务,也要安装对应的软件. 二.配置防火墙1.禁止防火墙和selinux# systemctl disable firewalld# systemctl stop firewalld2.设置防火墙规则# firewall-cmd --permanent --add-service=high-availability# firewall-cmd --add-service=h