Cài đặt HA cho mail Zimbra với pacemaker + drbd
(node1-master/node-slave)
Bước 1: cài đặt hoàn thành mail zimbra trên cả 2 node. Sau đó stop dịch vụ mail zimbra.
Su zimbra
Zmcontrol stop
Chú ý: Đảm bảo rằng trước khi cài đặt drbd thì firewall đã mở các port sử dụng cho drbd (mặc định là
7788). nếu chưa mở port thì dùng command sau: ở đây dùng port 7789 cho nó “khác port ” :))
firewall-cmd --permanent --add-port=7789/tcp ; firewall-cmd --reload
Bước 2: thêm ổ cứng và định dạnh lvm để dễ dàng nâng cấp thêm dung lượng ổ cứng sau này:
Tạo 1 partition trên ổ cứng mới thêm vào bằng command:
fdisk /dev/sdb
Định dạng phân vùng vừa tạo là LVM:
pvcreate /dev/sdb1
vgcreate vgdrbd /dev/sdb1
lvcreate -n vol1 -l100%FREE vgdrbd
Chú ý cần thêm đoạn code dưới vào /etc/hosts và đặt lại tên trên cả 2 node là node1 và node2:
172.20.80.85
node1.laichau.gov.vn node1
172.20.80.91
node2.laichau.gov.vn node2
172.20.80.113 mail.laichau.gov.vn mail
Bước 2: cài DRBD:
- Thêm repo cho drbd on centos trên cả 2 node bằng command:
rpm --import />rpm -Uvh />yum clean all && yum -y update
- sau đó cài đặt drbd và load drbd:
yum -y install kmod-drbd84 drbd84-utils drbd84-utils-sysvinit
modprobe drbd
Chú ý: nếu cấu lệnh “modprobe drbd” không load module thì cần khởi động lại máy trên cả hai
node.
Bước 3: tạo resource trên cả hai node:
vi /etc/drbd.d/zimbradrbd.res
Sau đó ta thêm đoạn code này vào:
resource zimbradrbd {
protocol C;
disk {
# on I/O errors, detach device
on-io-error detach;
}
meta-disk internal;
device /dev/drbd1;
syncer {
verify-alg sha1;
rate 40M;
}
net {
allow-two-primaries;
}
on node1 {
device /dev/drbd0;
disk /dev/vgdrbd/vol1;
address 192.168.10.1:7789;
meta-disk internal;
}
on node2 {
device /dev/drbd0;
disk /dev/vgdrbd/vol1;
address 192.168.10.2:7789;
meta-disk internal;
}
}
Chú ý: chổ khai báo on node1 và on node2 thì tên node1 node2 phải giống tên trong file
/etc/hostsname.
Bước 4: kiểm tra băng thông traffic trong ổ cứng thêm vào trên cả 2 node:
dd if=/dev/zero bs=1M count=10 of=/dev/vdb
sync
Bước 5: tạo metadata.
drbdadm create-md zimbradrbd
Trên cả 2 node load lại module và up metadata vừa tạo:
modprobe drbd
drbdadm up zimbradrbd
Trên node chọn là primary chạy command sau:
drbdadm -- --overwrite-data-of-peer primary zimbradrbd
Trên cả 2 node chạy câu lệnh sau:
systemctl start drbd
systemctl enable drbd
systemctl status drbd
Dùng câu lệnh watch cat /pro/drbd hoặc script while true; do clear; cat /proc/drbd;
sleep 10;done để xem đồng bộ trên cả hai node
Kết quả đạt dc:
Trên node primary dùng cat /proc/drbd để kiểm tra:
Trên node secondary kiểm tra:
Bước 6: mount drbd và đồng bộ với thư mục /opt của mail Zimbra.
Format /dev/drbd0:
Trên node primary chạy command:
mkfs.ext4 /dev/drbd0
Để format được trên node secondary làm như sau:
- chuyển node primary thành secondary: drbdadm secondary zimbradrbd
- chuyển node secondary thành primary: drbdadm primary zimbradrbd
- format: mkfs.ext4 /dev/drbd0
- sau khi thực hiện format xong ta tiến hành node thành primary và secondary như ban đầu
theo thứ tự chuyển primary -> secondarym secondary -> primary
- sau đó dữ liệu sẽ tiến hành đồng bộ lại, chờ cho đến khi đồng bộ xong rồi thực hiện bước
tiếp theo.
Mount và động bộ dự liệu, cần đảm bảo zimbra đã stop ( nếu chưa chạy zmcontrol stop)
mount /dev/drbd0 /mnt
rsync -avP --exclude=data.mdb /opt/ /mnt
cp /opt/zimbra/data/ldap/mdb/db/data.mdb /mnt/zimbra/data/ldap/mdb/db/data.mdb
chown zimbra.zimbra /mnt/zimbra/data/ldap/mdb/db/data.mdb
umount /dev/drbd0
mv /opt /zimbra-backup
mkdir /opt
Trên node2 (secondary) xóa thư mục zimbra trong /opt:
rm -rf /opt/*
Bước 7: cài đặt pacemaker
trên cả 2 node
yum -y install pacemaker pcs corosync resource-agents pacemaker-cli
Set pasword cho user hacluster trên cả 2 node phải giống nhau.:
passwd hacluster
Bật pcs trên cả hai node:
systemctl start pcsd
systemctl status pcsd
Xác thực trên 2 node
pcs cluster auth node1 node2
Tạo cluster (trên node chọn là master trùng với node primary trong drbd) và bật các node lên:
pcs cluster setup --name cluster_zimbra node1 node2
pcs cluster start --all
pcs cluster enable --all
Kiểm tra trạng thái của clusters:
pcs status cluster
corosync-cmapctl | grep members
pcs status corosync
Verify the config state and disable stonith (node chọn làm master):
crm_verify -L -V
pcs property set stonith-enabled=false
And disable the quorum policy, as there are only two nodes (node chọn làm master):
pcs property set no-quorum-policy=ignore
pcs property
Bước 8: Tạo vitrula VIP resource (172.20.80.113) và kiểm tra.
pcs resource create virtual_ip ocf:heartbeat:IPaddr2 ip=172.20.80.113 cidr_netmask=32 nic=ens192 op monitor interval=30s
pcs status resources
Bật dịch vụ của pacemaker trên cả 2 node.
systemctl enable pcsd
systemctl enable corosync
systemctl enable pacemaker
BUGFIX: Due an existing bug with the corosync service, you'll need to include a 10 seconds delay in the
systemd script. Please perform this VERY VITAL STEP IN BOTH SERVERS:
vi /usr/lib/systemd/system/corosync.service
After "[service]" section, add the following line:
ExecStartPre=/usr/bin/sleep 10
So the file new content will be:
[Unit]
Description=Corosync Cluster Engine
ConditionKernelCommandLine=!nocluster
Requires=network-online.target
After=network-online.target
[Service]
ExecStartPre=/usr/bin/sleep 10
ExecStart=/usr/share/corosync/corosync start
ExecStop=/usr/share/corosync/corosync stop
Type=forking
# The following config is for corosync with enabled watchdog service.## When corosync watchdog service
is being enabled and using with# pacemaker.service, and if you want to exert the watchdog when a# corosync
process is terminated abnormally,# uncomment the line of the following Restart= and
RestartSec=.#Restart=on-failure# Specify a period longer than soft_margin as RestartSec.#RestartSec=70#
rewrite according to environment.#ExecStartPre=/sbin/modprobe softdog soft_margin=60
[Install]
WantedBy=multi-user.target
Reload lại dịch vụ:
systemctl daemon-reload
Chú ý: thực hiện trên cả hai node.
Bước 9: Tiến hành tạo resource trên node chính.
in both nodes, proceed to stop and disable the DRBD service, as it will be controlled by the
cluster service.
systemctl stop drbd
systemctl disable drbd
systemctl status drbd
Proceed to create the DRBD resource:
cd /
pcs cluster cib add_drbd
This create the file: /add_drbd
pcs -f add_drbd resource create zimbra_data ocf:linbit:drbd drbd_resource=zimbradrbd op monitor interval=60s
pcs -f add_drbd resource master zimbra_data_sync zimbra_data master-max=1 master-node-max=1 clone-max=2
clone-node-max=1 notify=true
proceed to fix the following file permission IN BOTH SERVERS or the DRBD resource will not
work: thực hiện trên cả hai node.
chmod 777 /var/lib/pacemaker/cores
Back on the primary node
run the following commands:
pcs cluster cib-push add_drbd
Bước 10: tạo resource start zimbra trên cả hai node.
vi /usr/lib/ocf/resource.d/heartbeat/zimbractl
Thêm nội dung sau vào:
#!/bin/sh
#
# Resource script for Zimbra
#
# Description:
Manages Zimbra as an OCF resource in
#
an high-availability setup.
#
# Author:
RRMP <>
# License:
GNU General Public License (GPL)
#
#
#
usage: $0 {start|stop|reload|monitor|validate-all|meta-data}
#
#
The "start" arg starts a Zimbra instance
#
#
The "stop" arg stops it.
#
# OCF parameters:
#
OCF_RESKEY_binary
#
OCF_RESKEY_config_dir
#
OCF_RESKEY_parameters
#
##########################################################################
# Initialization:
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
: ${OCF_RESKEY_binary="zmcontrol"}
: ${OCF_RESKEY_zimbra_dir="/opt/zimbra"}
: ${OCF_RESKEY_zimbra_user="zimbra"}
: ${OCF_RESKEY_zimbra_group="zimbra"}
USAGE="Usage: $0 {start|stop|reload|status|monitor|validate-all|meta-data}";
##########################################################################
usage() {
echo $USAGE >&2
}
meta_data() {
cat <
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="postfix">
<version>0.1</version>
<longdesc lang="en">
This script manages Zimbra as an OCF resource in a high-availability setup.
</longdesc>
<shortdesc lang="en">Manages a highly available Zimbra mail server instance</shortdesc>
<longdesc lang="en">
Short name to the Zimbra control script.
For example, "zmcontrol" of "/etc/init.d/zimbra".
</longdesc>
<shortdesc lang="en">
Short name to the Zimbra control script</shortdesc>
<content type="string" default="zmcontrol" />
</parameter>
<longdesc lang="en">
Full path to Zimbra directory.
For example, "/opt/zimbra".
</longdesc>
<shortdesc lang="en">
Full path to Zimbra directory</shortdesc>
<content type="string" default="/opt/zimbra" />
</parameter>
<longdesc lang="en">
Zimbra username.
For example, "zimbra".
</longdesc>
<shortdesc lang="en">Zimbra username</shortdesc>
<content type="string" default="zimbra" />
</parameter>
unique="1" required="0">
<longdesc lang="en">
Zimbra group.
For example, "zimbra".
</longdesc>
<shortdesc lang="en">Zimbra group</shortdesc>
<content type="string" default="zimbra" />
</parameter>
</parameters>
<actions>
timeout="360s" />
timeout="360s" />
timeout="360s" />
timeout="40s"
interval="60s" />
timeout="360s" />
timeout="5s" />
</actions>
</resource-agent>
END
}
case $1 in
meta-data)
meta_data
exit $OCF_SUCCESS
;;
usage|help)
usage
exit $OCF_SUCCESS
;;
start)
echo "Starting Zimbra Services"
echo "0" > /var/log/db-svc-started.log
rm -f /var/log/zimbra-svc-stopped.log
if [ -f /etc/init.d/zimbra ]
then
/etc/init.d/zimbra start
fi
ocf_log info "Zimbra started."
exit $OCF_SUCCESS
;;
stop)
echo "Stopping Zimbra Services"
rm -f /var/log/db-svc-started.log
echo "0" > /var/log/zimbra-svc-stopped.log
if [ -f /etc/init.d/zimbra ]
then
/etc/init.d/zimbra stop
/bin/killall -9 -u zimbra
fi
ocf_log info "Zimbra stopped."
exit $OCF_SUCCESS
;;
status|monitor)
echo "Zimbra Services Status"
if [ -f /var/log/zimbra-svc-started.log ]
then
exit $OCF_SUCCESS
else
exit $OCF_NOT_RUNNING
fi
;;
restart|reload)
echo "Zimbra Services Restart"
ocf_log info "Reloading Zimbra."
if [ -f /etc/init.d/zimbra ]
then
/etc/init.d/zimbra stop
/bin/killall -9 -u zimbra
/etc/init.d/zimbra start
fi
exit $OCF_SUCCESS
;;
validate-all)
echo "Validating Zimbra"
exit $OCF_SUCCESS
;;
*)
usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
Cấp quyền thực thi cho file vừa tạo.
chmod 755 /usr/lib/ocf/resource.d/heartbeat/zimbractl
In the primary node proceed to create the service in the cluster:
pcs resource create svczimbra ocf:heartbeat:zimbractl
Apply the proper constrains in order to link the VIP with the resource and set the preferent node1
pcs constraint colocation add svczimbra virtual_ip INFINITY
pcs constraint order virtual_ip then svczimbra
pcs constraint location svczimbra prefers node1
KIểm tra trạng thái đạt được
pcs status
Bước 11: tạo file system resource trên node master(node1)
cd /
pcs cluster cib add_fs
pcs -f add_fs resource create zimbra_fs Filesystem device="/dev/drbd0" directory="/opt" fstype="ext4"
pcs -f add_fs constraint colocation add zimbra_fs zimbra_data_sync INFINITY with-rsc-role=Master
pcs -f add_fs constraint order promote zimbra_data_sync then start zimbra_fs
pcs -f add_fs constraint colocation add svczimbra zimbra_fs INFINITY
pcs -f add_fs constraint order zimbra_fs then svczimbra
pcs cluster cib-push add_fs
Kiểm tra lại trạng thái cluster:
pcs status
Như vậy là đã cài đặt xong: bây giờ kiểm tra failover bằng câu lệnh:
pcs cluster stop node1
Lên node còn lại kiểm tra trạng của cluster:
pcs status
Như và là đã cài xong HA cho mail zimbra.
Xử lý lỗi split brain trong lúc cài đặt:
- bật drbd trên cả hai node : systemctl start drbd
- xác định node secondary:
drbd secondary all
drbd disconnect all
drbd --
-- discard-my-data connect all
- trên node primary:
drbd primary all
drbd disconnect all
drbd connect alletc/drbd.d
- thêm đoạn code sau vào vi /etc/drbd.d/zimbradrbd.res trên cả hai node.
net {
after-sb-0pri discard-zero-changes;
after-sb-1pri discard-secondary;
after-sb-2pri disconnect;
}
Link tham khảo: /> />7