1. 程式人生 > 其它 >3.1Rabbitmq安裝與解除安裝

3.1Rabbitmq安裝與解除安裝

技術標籤:rabbitmq

文章目錄

1.安裝rabbitmq所需要的依賴包

yum install build-essential openssl openssl-devel unixODBC unixODBC-devel make gcc gcc-c++ kernel-devel m4 ncurses-devel tk tc xz

2.安裝包

erlang-18.3-1.el7.centos.x86_64.rpm
rabbitmq-server-3.6.5-1.noarch.rpm
socat-1.7.3.2-1.1.el7.x86_64.rpm

3.執行命令

rpm -ivh erlang-18.3-1.el7.centos.x86_64.rpm
#第二步:安裝socat加解密軟體
rpm -ivh socat-1.7.3.2-1.1.el7.x86_64.rpm --force --nodeps
#第三步:最後安裝rabbitmq
rpm -ivh rabbitmq-server-3.6.5-1.noarch.rpm

4.修改使用者

注意修改vim /usr/lib/rabbitmq/lib/rabbitmq_server-3.6.5/ebin/rabbit.app檔案
修改:loopback_users 中的 <<“guest”>>,只保留guest(不修改只能通過localhost訪問)
在這裡插入圖片描述

5.修改 本機系統檔案

a:修改 vim /etc/rabbitmq/rabbitmq-env.conf

新增: NODENAME=rabbit

b:修改 vim /etc/hostname

在這裡插入圖片描述

c:修改本地 /etc/hosts檔案在這裡插入圖片描述

6.管控臺外掛

執行管控臺外掛
rabbitmq-plugins enable rabbitmq_management

7.命令

service rabbitmq-server start
service rabbitmq-server stop
service rabbitmq-server status

具體安裝文件:

https://www.cnblogs.com/sky-cheng/p/10709104.html

解除安裝文件:

https://www.cnblogs.com/kingsonfu/p/11023967.html

外掛地址:

https://www.rabbitmq.com/community-plugins.html

延時外掛地址:

https://dl.bintray.com/rabbitmq/community-plugins/3.6.x/rabbitmq_delayed_message_exchange/

延時外掛安裝:

解壓延時外掛:

unzip  rabbitmq_delayed_message_exchange-20171215-3.6.x.zip

把延時外掛拷貝到指定目錄下:

cp rabbitmq_delayed_message_exchange-20171215-3.6.x.ez /usr/lib/rabbitmq/lib/rabbitmq_server-3.7.5/plugins

啟動延時外掛:

rabbitmq-plugins enable rabbitmq_delayed_message_exchange

rabbitmq群搭建

8.將主節點的.erlang.cookie拷貝到從節點

scp /var/lib/rabbitmq/.erlang.cookie m2:/var/lib/rabbitmq/

9.重啟

service rabbitmq-server stop
service rabbitmq-server start

10.都執行 rabbitmqctl stop

11.都執行 rabbitmq-server -detached

12.在m2中執行

rabbitmqctl stop_app
rabbitmqctl join_cluster [email protected]
rabbitmqctl start_app

13.修改叢集名稱

rabbitmqctl set_cluster_name rabbitmq_cluster_zhuang

14.檢視叢集狀態

rabbitmqctl cluster_status

在這裡插入圖片描述

15.訪問任意地址的15672埠

在這裡插入圖片描述

16.剔除節點命令

rabbitmqctl forget_cluster_node  [email protected]節點名稱

HAProxy

HAProxy提供高可用性、負載均衡以及基於TCP和HTTP應用的代理,支援虛擬主機,它是免費、快速並且可靠的一種解決方案,包括Twitter,Reddit,StackOverflow,GitHub在內的多家知名網際網路公司在使用。HAProxy實現了一種事件驅動、單一程序模型,此模型支援非常大的併發連線數。

1.關閉selinux

setsebool -P haproxy_connect_any=1

2.安裝HAProxy

安裝
yum install haproxy
配置haproxy.cfg檔案 具體參照 如下配置HAProxy
vim /etc/haproxy/haproxy.cfg
啟動haproxy
systemctl start haproxy
檢視haproxy程序狀態
systemctl status haproxy.service
狀態如下說明 已經啟動成功 Active: active (running)
訪問如下地址對mq節點進行監控
http://伺服器IP:1080/haproxy_stats
程式碼中訪問mq叢集地址,則變為訪問haproxy地址:5672

3.配置HAProxy

#---------------------------------------------------------------------
# Example configuration for a possible web application.  See the
# full configuration options online.
#
#   http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
    # to have these messages end up in /var/log/haproxy.log you will
    # need to:
    #
    # 1) configure syslog to accept network log events.  This is done
    #    by adding the '-r' option to the SYSLOGD_OPTIONS in
    #    /etc/sysconfig/syslog
    #
    # 2) configure local2 events to go to the /var/log/haproxy.log
    #   file. A line like the following can be added to
    #   /etc/sysconfig/syslog
    #
    #    local2.*                       /var/log/haproxy.log
    #
    log         127.0.0.1 local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000


#對MQ叢集進行監聽
listen rabbitmq_cluster
	bind 0.0.0.0:5672
	option tcplog
	mode tcp 
	option  clitcpka
	timeout connect 1s 
	timeout client  10s
	timeout server  10s
	balance roundrobin
	server node1  192.168.10.101:5672 check inter 5s rise 2 fall 3  
    server node2  192.168.10.102:5672 check inter 5s rise 2 fall 3

#開啟haproxy監控服務	
listen http_front
	bind 0.0.0.0:1080
	stats refresh 30s
	stats uri /haproxy_stats
	stats auth admin:admin

4.haproxy.cfg配置詳解

listen rabbitmg cluster
bind 0.0.0.0:5672#通過5672對M1, M2進行對映
option tcplog #記錄tcp連線的狀態和時間
mode tcp#四層協議代理,即對TCP協議轉發
option clitcpka #開啟TCP的Keep Alive. (長連線模式)
timeout connect 1s #haproxy與mq建立連線的超時時間
timeout client 10s#客戶端與haproxy最大空閒時間。
timeout server 10s #伺服器與haproxy最大空閒時間
balance roundrobin #採用輪詢轉發訊息
#每5秒傳送一次心跳包,如連續兩次有響應則代表狀態良好。
#如連續三次沒有響應,則視為服務故障,該節點將被剔除。
server node1  192.168.10.101:5672 check inter 5s rise 2 fall 3  
server node2  192.168.10.102:5672 check inter 5s rise 2 fall 3
listen http front
#監聽埠 bind 0.0.0.0:1080
#統計頁面自動重新整理時間 stats refresh 30s
#統計頁面url stats uri /haproxy_stats
#指定HAproxy訪問使用者名稱和密碼設定
stats auth admin:admin