一、centos 6.X rabbitmq安装
1、安装erlang
添加yum源
/etc/yum.repos.d/rabbitmq-erlang.repo
[rabbitmq-erlang]
name=rabbitmq-erlang
baseurl=https://dl.bintray.com/rabbitmq/rpm/erlang/20/el/6
gpgcheck=1
gpgkey=https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
repo_gpgcheck=0
enabled=1
安装
yum install erlang.x86_64 -y
2、安装依赖包
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
yum install socat.x86_64 -y
3、安装rabbitmq
下载rpm包
rpm -ihv rabbitmq-server-3.6.12-1.el6.noarch.rpm
service rabbitmq-server start
4、安装图像管理插件
rabbitmq-plugins enable rabbitmq_management
建立用户
rabbitmqctl add_user rabbit rabbit
rabbitmqctl set_user_tags rabbit administrator
集群
1、修改/etc/hosts
192.168.6.152 rabbitmq2
192.168.6.151 rabbitmq1
2、将两个服务器的 /var/lib/rabbitmq/.erlang.cookie 内容改成一样的
scp命令
3、启动
使用 -detached运行各节点
rabbitmq-server -detached
查看各节点的状态
rabbitmqctl cluster_status
4、加入集群节点,在rabbitmq2服务器上
rabbitmqctl stop_app
加入内存节点
rabbitmqctl join_cluster --ram rabbit@rabbitmq1 //默认死磁盘节点,不要加--ram
rabbitmqctl start_app
lvs+keepalive负载均衡。
在rabbitmq1/rabbitmq2两个节点配置
vi /opt/initlvs.sh
#!/bin/bash
#
# Script to start LVS DR real server.
# description: LVS DR real server
#
. /etc/rc.d/init.d/functions
VIP=192.168.6.149
host=`/bin/hostname`
case "$1" in
start)
# Start LVS-DR real server on this machine.
/sbin/ifconfig lo down
/sbin/ifconfig lo up
echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev lo:0
;;
stop)
# Stop LVS-DR real server loopback device(s).
/sbin/ifconfig lo:0 down
echo 0 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 0 > /proc/sys/net/ipv4/conf/lo/arp_announce
echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
;;
status)
# Status of LVS-DR real server.
islothere=`/sbin/ifconfig lo:0 | grep $VIP`
isrothere=`netstat -rn | grep "lo:0" | grep $VIP`
if [ ! "$islothere" -o ! "isrothere" ];then
# Either the route or the lo:0 device
# not found.
echo "LVS-DR real server Stopped."
else
echo "LVS-DR real server Running."
fi
;;
*)
# Invalid entry.
echo "$0: Usage: $0 {start|status|stop}"
exit 1
;;
esac
sh /opt/initlvs.sh start
2、lvs服务器上配置
安装ipvsadm
yum install ipvsadm.x86_64
yum install -y keepalived.x86_64
echo "1">/proc/sys/net/ipv4/ip_forward
[root@lvsA ~]# vi /etc/sysconfig/ipvsadm
-A -t 192.168.6.149:5672 -s rr -p 50
-a -t 192.168.6.149:5672 -r 192.168.6.151:5672 -g -w 1
-a -t 192.168.6.149:5672 -r 192.168.6.152:5672 -g -w 1
-A -t 192.168.6.149:15672 -s rr -p 50
-a -t 192.168.6.149:15672 -r 192.168.6.151:15672 -g -w 1
-a -t 192.168.6.149:15672 -r 192.168.6.152:15672 -g -w 1
service ipvsadm restart
vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 200
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass frxs2017
}
virtual_ipaddress {
192.168.6.149
}
}
virtual_server 192.168.6.149 5672 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 192.168.6.151 5672 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 5672
}
}
real_server 192.168.6.152 5672 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 5672
}
}
}
virtual_server 192.168.6.149 15672 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 192.168.6.151 15672 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 15672
}
}
real_server 192.168.6.152 15672 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 15672
}
}
}
services keepalived restart