Installation environment
Centos-7
Three virtual machines
192.168.8.150 (disk node)
192.168.8.45 (Memory Node)
192.168.8.40 (Memory Node)
1. Install Erlang
1. Erlang download address:
/releases/erlang/
2. Create a directory
[root@nogeek ]# mkdir -p /usr/local/tools/rabbitmq
[root@nogeek ]# cd /usr/local/tools/rabbitmq
3. Download the installation package
[root@nogeek ]# wget /releases/erlang/erlang-19.0.4-1.el6.x86_64.rpm
4. Installation
[root@nogeek ]# rpm -ivh erlang-19.0.4-1.el6.x86_64.rpm
2. Install RabbitMQ
1. RabbitMQ download address
/rabbitmq/rabbitmq-server-rpm/
2. Download the installation package
[root@nogeek ]# wget /rabbitmq/rabbitmq-server-rpm/rabbitmq-server-3.6.12-1.
[root@nogeek ]# rpm --import /
3. Installation
[root@nogeek ]# rpm -ivh rabbitmq-server-3.6.12-1.
Problem solving
1. Error: Dependency detection failed:
socat is rabbitmq-server-3.6.12-1. Need
Resolve the error:
[root@nogeek ]# wget –no-cache /repos/definitions/rhel// -O /etc//
[root@nogeek ]# yum makecache -y
[root@nogeek ]# yum install socat -y
2. If there is a problem with the yum source, it cannot be installed: replace the yum source of CentOS with the domestic Alibaba Cloud source.
File contains no section headers when using yum. Solution
/blog/2393165
[root@nogeek ]# rm -f /etc//*
[root@nogeek ]# wget -O /etc// /repo/
[root@nogeek ]# yum clean all
3. Cluster configuration
1. Hosts configuration
The hosts of all three machines are configured
[root@nogeek ]# vim /etc/hosts
192.168.8.150 rabbit1 (disk node)
192.168.8.45 rabbit2 (memory node)
192.168.8.40 rabbit3 (memory node)
2. Synchronization.
Keep three machines in sync
/var/lib/rabbitmq/.
Execute on the second machine 8.45:
[root@nogeek ]# scp . [email protected]:/var/lib/rabbitmq/
[root@nogeek ]# chown rabbitmq:rabbitmq .
On the third machine 8.40:
[root@nogeek ]# scp . [email protected]:/var/lib/rabbitmq/
[root@nogeek ]# chown rabbitmq:rabbitmq .
Restart the service
[root@nogeek ]# systemctl stop
[root@nogeek ]# systemctl start
or:
[root@nogeek ]# systemctl restart
Check service status:
[root@nogeek ]# systemctl status
If the startup error occurs:
Job for failed because the control process exited with error code. See "systemctl status " and "journalctl -xe" for details.
If the service cannot be stopped, you need to kill the port.
3. Join the cluster
First, open the cluster communication port:
[root@nogeek ]# firewall-cmd --permanent --add-port={5672/tcp,4369/tcp,25672/tcp}
[root@nogeek ]# firewall-cmd --reload
[root@nogeek ]# setsebool -P nis_enabled 1
On the second 45, the third machine, 40:
[root@nogeek ]# rabbitmqctl stop_app
[root@nogeek ]# rabbitmqctl reset
[root@nogeek ]# rabbitmqctl join_cluster rabbit@rabbit1 --ram
Create user: All three servers execute
[root@nogeek ]# firewall-cmd --permanent --add-port=15672/tcp
[root@nogeek ]# firewall-cmd –-reload
[root@nogeek ]# rabbitmqctl add_user admin admin
[root@nogeek ]# rabbitmqctl set_user_tags admin administrator
[root@nogeek ]# rabbitmqctl set_permissions -p / admin "." "." ".*"
4、
RabbitMQ mirror queue
You can refer to:
/saneri/p/
5. HAProxy + Keepalived High Availability Solution
1. HAProxy
Map port 5672 to port 5673 and port 15672 to port 15673.
1) Install HAProxy on two memory nodes
[root@nogeek ]# yum install haproxy
2) Edit the configuration file
[root@nogeek ]# vim /etc/haproxy/
The content is modified to:
Global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/
maxconn 4000
user haproxy
group haproxy
daemon
stats socket /var/lib/haproxy/stats
: : : : : : : : : : : : : : :
defaults
log global
option dontlognull
option redispatch
retries 3
timeout connect 10s
timeout client 1m
timeout server 1m
maxconn 3000
: : : : : : : : : : : : : : :
listen http_front
mode http
bind 0.0.0.0:1080 #listener port
stats refresh 30s #Statistics page automatically refresh time
stats uri /haproxy?stats #stats page url
stats realm Haproxy Manager #Statistics page password box prompt text
stats auth admin:123456 #Statistics page username and password settings
: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :
listen rabbitmq_admin
bind 0.0.0.0:15673
server node1 192.168.8.40:15672
server node2 192.168.8.45:15672
: : : : : : : : : : : : : : :
listen rabbitmq_cluster 0.0.0.0:5673
mode tcp
balance roundrobin
timeout client 3h
timeout server 3h
timeout connect 3h
server node1 192.168.8.40:5672 check inter 5s rise 2 fall 3
server node2 192.168.8.45:5672 check inter 5s rise 2 fall 3
3) Start HAProxy
[root@nogeek ]# haproxy -f /etc/haproxy/
2. Install Keepalived on two memory nodes
VIP is 192.168.8.201
1) Install Keepalived
[root@nogeek ]# yum -y install keepalived
2) Modify the configuration file
[root@nogeek ]# vim /etc/keepalived/
Change the content to (the physical network card and current host IP need to be modified):
global_defs {
notification_email {
acassen@
failover@
sysadmin@
}
notification_email_from @
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
# vrrp_strict # Comment out, otherwise the VIP will not be accessible
vrrp_garp_interval 0
vrrp_gna_interval 0
}
global_defs {
notification_email {
acassen@
failover@
sysadmin@
}
notification_email_from @
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
# vrrp_strict # Comment out, otherwise the VIP will not be accessible
vrrp_garp_interval 0
vrrp_gna_interval 0
}
# Detection tasks
vrrp_script check_haproxy {
# Detect HAProxy scripts
script "/etc/keepalived/script/check_haproxy.sh"
# Detection every two seconds
interval 2
# Weight
weight 2
}
# Virtual Group
vrrp_instance haproxy {
state MASTER # Here is the `main`, and the backup machine is `BACKUP` [to be modified here]
interface ens33 # physical network card, depending on the situation [recommended here]
mcast_src_ip 192.168.8.40 # Current host ip [To be modified here]
virtual_router_id 51 # Virtual routing id, the same needs to be included in the same group
priority 100 # The priority of the host is higher than that of the backup machine
advertise_int 1 # Heartbeat check frequency, unit: seconds
authentication { # Authentication, the group must be the same
auth_type PASS
auth_pass 1111
}
# Call the script
track_script {
check_haproxy
}
# Virtual ip, multiple line breaks
virtual_ipaddress {
192.168.8.201
}
}
3) Start keepalived
[root@nogeek ]# keepalived -D
Source:
WeChat official account: More than geeks