pacemaker+corosync+drbd-rabbitmq

rpm -ivh http://elrepo.org/linux/elrepo/el7/x86_64/RPMS/elrepo-release-7.0-2.el7.elrepo.noarch.rpm

rpm -ivh http://mirrors.sohu.com/fedora-epel/7/x86_64/e/epel-release-7-2.noarch.rpm





yum install rabbitmq-server -y




####prepare rabbitmq on both os-node node

echo 'MYRABBITMQCLUSTERABC' > /var/lib/rabbitmq/.erlang.cookie

chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie

chmod 400 /var/lib/rabbitmq/.erlang.cookie



cat >  /etc/rabbitmq/rabbitmq.config  << EOF

[{rabbit, [{loopback_users, []}, {tcp_listeners, [{"192.168.4.10", 5672}]}]}].

EOF



yum install  pacemaker corosync  resource-agents crmsh cluster-glue drbd84 kmod-drbd84 pcs -y 


cat >/etc/drbd.d/rabbitmq.res <<EOF

resource drbd-rabbitmq {

        device /dev/drbd0;

        meta-disk internal;

        on os-node1 {

                address 192.168.4.11:7789;

                disk /dev/vdb;

        }

        on os-node2 {

                address 192.168.4.12:7789;

                disk /dev/vdb;

        }

        syncer {

                rate 40M;

        }

        net {

                after-sb-0pri discard-zero-changes;

                after-sb-1pri discard-secondary;

        }

}


EOF


modprobe drbd

lsmod | grep drbd


###check drbd & bring resource up


drbdadm dump drbd-rabbitmq

drbdadm create-md drbd-rabbitmq

drbdadm up drbd-rabbitmq


###set os-node1 as primary

drbdadm -- --overwrite-data-of-peer primary drbd-rabbitmq


###format  rabbitmq disk and mount in os-node1


mkfs -t xfs /dev/drbd0

mkdir -p  /data/ms

mount /dev/drbd0 /data/ms ; mv /var/lib/rabbitmq /data/ms

umount /dev/drbd0


####set os-node1 as secondary after drbd synchronization finished

drbdadm secondary drbd-rabbitmq



########config pacemaker and corosync

########start pcsd, corosync, pacemaker service as default on both os-node node


systemctl enable pcsd.service

systemctl enable corosync.service

systemctl enable pacemaker.service

systemctl enable drbd.service

systemctl start pcsd.service


######set user hacluster password on both os-node node

[root@os-node1 ~]# passwd hacluster

Changing password for user hacluster.

New password: 

Retype new password: 

passwd: all authentication tokens updated successfully.


######config corosync 

[root@os-node1 ~]# pcs cluster auth os-node1 os-node2

Username: hacluster

Password: 

os-node1: Authorized

os-node2: Authorized


[root@os-node1 ~]# pcs cluster setup --name oscluster os-node1 os-node2

Shutting down pacemaker/corosync services...

Redirecting to /bin/systemctl stop  pacemaker.service

Redirecting to /bin/systemctl stop  corosync.service

Killing any remaining services...

Removing all cluster configuration files...

os-node1: Succeeded

os-node2: Succeeded

[root@os-node1 ~]# 


#######start cluster

pcs cluster start os-node1 os-node2


#######verify corosync installation on both ct node

corosync-cfgtool -s

pcs status corosync


#########configure cluster resources for rabbitmq

####global:

pcs property set no-quorum-policy=ignore

pcs property set stonith-enabled=false


#####rabbitmq:

pcs resource create drbd-rabbitmq ocf:linbit:drbd params drbd_resource="drbd-rabbitmq" op monitor interval="50s" role="Master" timeout="30s" op monitor interval="60s" role="Slave" timeout="30s"


pcs resource create fs-rabbitmq ocf:heartbeat:Filesystem params device="/dev/drbd0" directory="/data/ms" fstype="xfs" meta target-role="Started"


pcs resource create rabbitmq ocf:rabbitmq:rabbitmq-server params mnesia_base="/data/ms/rabbitmq" ip="192.168.4.10" nodename="rabbit@localhost" op monitor interval="20s" timeout="10s"


pcs resource create vip-rabbitmq ocf:heartbeat:IPaddr2 params ip="192.168.4.10" cidr_netmask="24"


pcs resource group add g-rabbitmq fs-rabbitmq vip-rabbitmq rabbitmq


pcs resource master ms-drbd-rabbitmq drbd-rabbitmq meta notify="true" master-max="1" master-node-max="1" clone-max="2" clone-node-max="1"


pcs constraint colocation add g-rabbitmq with master ms-drbd-rabbitmq


pcs constraint order promote ms-drbd-rabbitmq then start g-rabbitmq


####check cluster status and config 

pcs config show

pcs status


#####change password of rabbitmq guest user on master node

abbitmqctl -n rabbit@localhost change_password guest guest

rabbitmqctl set_permissions  guest ".*" ".*" ".*"

rabbitmqctl set_user_tags guest administrator




你可能感兴趣的:(rabbitmq,pacemaker)