天天看點

高可用叢集 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

繼續閱讀