天天看点

高可用集群 pacemaker + apache + drbd

pacemaker + corosync +pcs +apache + drbd

实验环境:192.168.1.17 mini17 192.168.1.18 mini18

/etc/hosts 双机互信 selinux fw ntp 添加存储磁盘

1.创建集群 corosync

mini17 mini18 两台执行:

yum -y install pcs pacemaker corosync

systemctl start pcsd

systemctl enable pcsd

mini17 mini18 两台执行:

passwd hacluster

设置密码

任意节点:

[[email protected] ~]# pcs cluster auth mini17 mini18

Username: hacluster

Password:

mini17: Authorized

mini18: Authorized

#报错是/etc/hosts没解析主机

任意节点:

[[email protected] ~]# pcs cluster setup --start --name Web mini17 mini18 ##创建名为Web的集群

任意节点:

[[email protected] ~]# pcs cluster enable --all ##集群开机自启

mini17: Cluster Enabled

mini18: Cluster Enabled

任意节点:

[[email protected] ~]# pcs cluster status ##查看集群状态

Cluster Status:

Stack: corosync

Current DC: mini18 (version 1.1.15-11.el7-e174ec8) - partition with quorum

Last updated: Sun Feb 24 03:47:46 2019 Last change: Sun Feb 24 03:45:42 2019 by hacluster via crmd on mini18

2 nodes and 0 resources configured

PCSD Status:

mini17: Online

mini18: Online

任意节点:

# ps aux | grep pacemaker

任意节点:

[[email protected] ~]# corosync-cfgtool -s

Printing ring status.

Local node ID 1

RING ID 0

id = 192.168.1.17

status = ring 0 active with no faults

任意节点:

[[email protected] ~]# pcs status corosync

Membership information

----------------------

Nodeid Votes Name

1 1 mini17 (local)

2 1 mini18

任意节点:

[[email protected] ~]# pcs property set stonith-enabled=false

任意节点:

[[email protected] ~]# pcs property set no-quorum-policy=ignore

=============================corosync cluster ok ===========

可选测试:

任意节点:

[[email protected] ~]# pcs resource create test_vip ocf:heartbeat:IPaddr2 \

> ip=192.168.1.200 \

> cidr_netmask=24 \

> op monitor interval=30s

[[email protected] ~]# pcs status

Full list of resources:

test_vip (ocf::heartbeat:IPaddr2): Started mini17

模拟故障:

[[email protected] ~]# pcs cluster stop mini17

node1.uplook.com: Stopping Cluster (pacemaker)...

node1.uplook.com: Stopping Cluster (corosync)...

[[email protected] ~]# pcs status

Full list of resources:

test_vip (ocf::heartbeat:IPaddr2): Started mini18

恢复成员:

[[email protected] ~]# pcs cluster start mini17

删除资源

[[email protected] ~]# pcs resource delete test_vip

=========================================================

2.Apache 配置

mini17 mini18 两台执行:

yum -y install httpd wget

mini17 mini18 两台执行:

vi /etc/httpd/conf/httpd.conf

<Location /server-status>

SetHandler server-status

Order deny,allow

Deny from all

Allow from 127.0.0.1

</Location>

3.创建 Apache 资源

[[email protected] ~]# pcs resource create my_web apache \ ##创建Apache脚本资源名为my_web

> configfile="/etc/httpd/conf/httpd.conf" \

> statusurl="http://127.0.0.1/server-status" \

> --group apachegroup

4.创建IP资源

[[email protected] ~]# pcs resource create web_vip IPaddr2 \ ##创建IP资源,虚拟IP名为web_vip,地址 192.168.1.100

> ip=192.168.1.100 \

> cidr_netmask=24 \

> --group apachegroup

5.配置存储资源

mini17 mini18 两台执行:

pvcreate /dev/sdb

vgcreate web_vg /dev/sdb

lvcreate -n web_lv -L 19G /dev/web_vg

用网络yum安装或者包装DRBD服务

# tar axf drbd-centos7.tar.gz

# cd drbd7/

# yum -y install *.rpm

安装完成重启,否则配置完成无法加载模块

============

mini17执行:

vi /etc/drbd.d/global_common.conf

18 common {

19 protocol C; ##插入内容:使用DRBD的C同步协议

20 handlers {

21 # These are EXAMPLE handlers only.

49 disk {

50 on-io-error detach; ##插入内容:配置I/O错误处理策略为分离

51 # size on-io-error fencing disk-barrier disk-flushes

vi /etc/drbd.d/web.res

resource web { ##这里必须跟文件名一致

protocol C;

meta-disk internal;

device /dev/drbd0; ##指定DRBD设备名

syncer {

verify-alg sha1;

}

net {allow-two-primaries;

}

on mini17 { ##注意主机名,报错检查是否解析主机

disk /dev/web_vg/web_lv;

address 192.168.1.17:7789;

}

on mini18 { ##注意主机名,报错检查是否解析主机

disk /dev/web_vg/web_lv;

address 192.168.1.18:7789;

}

}

scp -r /etc/drbd.d/* mini18:/etc/drbd.d/

modprobe drbd ## 加载模块

lsmod | grep drbd ## 查询启动状态

drbdadm create-md web

drbdadm up web

drbdadm primary web --force ## 设置该机为主

cat /proc/drbd

============

mini18执行:

modprobe drbd

lsmod | grep drbd

drbdadm create-md web

drbdadm up web

cat /proc/drbd

============

mini17执行:

mkfs.ext4 /dev/drbd0

mount /dev/drbd0 /var/www/html/

cat <<-END >/var/www/html/index.html

<html>

<body>My Test Site - drbd</body>

</html>

END

umount /dev/drbd0

pcs cluster cib drbd_cfg

pcs -f drbd_cfg resource create webdata ocf:linbit:drbd drbd_resource=web op monitor interval=60s

pcs -f drbd_cfg resource master webdataclone webdata master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true

pcs -f drbd_cfg resource show

pcs cluster cib-push drbd_cfg

pcs status

pcs cluster cib fs_cfg

pcs -f fs_cfg resource create WebFS Filesystem device="/dev/drbd0" directory="/var/www/html" fstype="ext4"

pcs -f fs_cfg constraint colocation add WebFS webdataclone INFINITY with-rsc-role=Master

pcs -f fs_cfg constraint order promote webdataclone then start WebFS

pcs -f fs_cfg constraint colocation add my_web WebFS INFINITY

pcs -f fs_cfg constraint order WebFS then my_web

pcs -f fs_cfg constraint

pcs -f fs_cfg resource show

pcs cluster cib-push fs_cfg

pcs status

继续阅读