Project needs to build RABBITMQ high-availability cluster, recently in the learning and building process, recorded here can communicate with everyone (here is just a record of their own building process after learning, many of the principles of things not in detail).
Build the Environment
CentOS7 64-bit
RabbitMQ 3.6.2
Keepalived 1.2.21
Host: 192.168.0.1 192.168.0.2 192.168.0.3 install RABBITMQ service on three nodes
Haproxy installed on 192.168.1.1 and 192.168.1.2 to provide RabbitMQ equalization externally
keepalived implementation of Haproxy, high availability (avoid single point of problem), 192.168.1.1 (master) 192.168.1.2 (prepared)
RABBITMQ Cluster Construction installation on a single machine
Install RABBITMQ server on the 192.168.0.1 192.168.0.2 192.168.0.3 node, respectively. 1.Install Erlang
# yum Install Erlang
To test whether Erlang is installed successfully, enter:
# Erl//Enter the Erl window to indicate a successful installation of 2.Install RabbitMQ Server
# wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.2/rabbitmq-server-3.6.2-1.noarch.rpm
# Yum Install rabbitmq-server-3.6.2-1.noarch.rpm 3. Start
#/etc/init.d/rabbitmq-server start 4. Boot start
# Chkconfig Rabbitmq-server on
To test whether the installation was successful:
# RABBITMQCTL Status//view RABBITMQ's running status information 5. Enable plug-in RABBITMQ management
# Rabbitmq-plugins Enable Rabbitmq_management
#/etc/init.d/rabbitmq-server Restart
Input http://ip:15672 can login to the management interface, the default account guest/guest can only use http://localhost:15672 login, in order to telnet, you need to add a new user:
# rabbitmqctl Add_user Admin 1234
#用户设置为administrator才能远程访问
$ sudo rabbitmqctl set_user_tags admin Administrator
$ sudo rabbitmqctl set_permissions-p/admin ". *" ". *"//This command enables user admin to have '/' configuration, write, read permissions for all resources in this virtual host to manage resources in it
View all users #rabbitmqctl list_users
mirror Cluster setup
Copy the contents of/var/lib/rabbitmq/.erlang.cookie on 192.168.0.1 to the/var/lib/rabbitmq/.erlang.cookie file on 158 and 159, That is, three servers must have the same cookie, and if not, the cluster cannot be built
192.168.0.2 and 192.168.0.3 nodes execute the command separately, join the cluster
# Rabbitmqctl Stop_app
# rabbitmqctl Join_cluster--ram RABBIT@H-NCDRDCS7
# Rabbitmqctl Start_app
Where--ram represents a memory node, if you want to be a disk node without adding--ram, in RABBITMQ cluster, you need at least one disk node
View the status of a cluster
# Rabbitmqctl Cluster_status
Set as mirror queue
# rabbitmqctl Set_policy ha-all "^ha\." ' {' Ha-mode ': ' All '} '/' means that the queue that starts with ha. will be copied to each node ["^" matches all]
haproxy Load Agent
Load Balancing with Haproxy
On the 192.168.1.1 and 192.168.1.2 Nodes
Installing Haproxy
# yum Install Haproxy
Add after Vi/etc/haproxy/haproxy.cfg:
Listen rabbitmq_local_cluster 0.0.0.0:5672
#Configuring TCP mode
Mode tcp
Option tcplog
#Simple polling
Balance roundrobin
#rabbitmqCluster Node Configuration
Server rabbit1 192.168.0.1:5672 check inter 5000 rise 2 fall 2
Server rabbit2 192.168.0.2:5672 check inter 5000 rise 2 fall 2
Server rabbit3 192.168.0.3:5672 check inter 5000 rise 2 fall 2
#Configuring haproxy web monitoring to view statistics
Listen private_monitoring :8100
Mode http
Option httplog
Stats enable
#Set the haproxy monitoring address to http://localhost:8100/stats
Stats uri /stats
Stats refresh 30s
#Add username and password authentication
Stats auth admin:1234
#start up
# haproxy -f haproxy.cfg
#Restart
# service haproxy restart Keepalived installation
Use keepalived to do the main and standby, avoid single point problems, achieve high availability
Install the latest version of keepalived on the 192.168.1.1 and 192.168.1.2 nodes
192.168.1.1 (main) modify keepalived.conf to: Primary configuration: rabbitmq+haproxy+keepalived to achieve high availability cluster construction
Vrrp_script Chk_haproxy {
script "pidof haproxy"
interval 2
}
vrrp_instance vi_1 {
interface ens192 state
MASTER priority
virtual_router_id
unicast_src_ip 192.168.1.1
unicast_peer {
192.168.1.2
}
Authentication {
auth_type PASS
auth_pass password
}
virtual_ipaddress {
192.168.1.10// Virtual IP, providing services externally
}
track_script {
chk_haproxy
}
notify_master/loadbtify_master.sh
}
192.168.1.2 (prepared) modify keepalived.conf to: Secondary configuration:
Vrrp_script Chk_haproxy {
script "pidof haproxy"
interval 2
}
vrrp_instance vi_1 {
interface ens192 state
BACKUP priority
virtual_router_id
unicast_src_ip 192.168.1.2
unicast_peer {
192.168.1.1
}
Authentication {
auth_type PASS
auth_pass password
}
virtual_ipaddress {
192.168.1.10
}
Track_script {
chk_haproxy
}
notify_master/loadbtify_master.sh
}
Start keepalived, 192.168.1.10 is the unified address provided externally.
Access to the RABBITMQ service is available through 192.168.1.10:5672.
References :
https://www.digitalocean.com/community/tutorials/ how-to-set-up-highly-available-haproxy-servers-with-keepalived-and-floating-ips-on-ubuntu-14-04#userconsent#
Http://www.rabbitmq.com/install-rpm.html
http://www.keepalived.org/download.html //keepalived Download address programmers are great, boring code that goes through their hands and turns into a colorful world.