RabbitMQ安裝流程及cluster簡單叢集搭建
阿新 • • 發佈:2019-01-09
兩臺機器需要安裝版本相同的erlang和RabbitMQ
1.安裝配置yum
cd /etc/yum.repos.d/ 會看到很多repo檔案
vim CentOS-Base.repo 將此檔案內容修改為下圖內容
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
2.安裝erlang
1)新增Erlang Solutions key 支援
rpm --import http://binaries.erlang-solutions.com/debian/erlang_solutions.asc
wget http://binaries.erlang-solutions.com/rpm/centos/erlang_solutions.repomv erlang_solutions.repo /etc/yum.repos.d/ 將solutions key 移動到該目錄
2)由於安裝erlang需要大量的依賴,(CentOS的原始庫缺少某些依賴)先引入第三方庫rpmfusion
先引入該第三方庫所需的依賴:
yum install epel-release
3)開始安裝rpmfusion:
rpm -ivh https://download1.rpmfusion.org/free/el/updates/6/i386/rpmfusion-free-release-6-1.noarch.rpm
4)開始安裝erlang
yum install erlang
3.安裝RabbitMQ
1)安裝RabbitMQ之前需要安裝socat
yum install socat
2)安裝RabbitMQ
wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.5/rabbitmq-server-3.6.5-1.noarch.rpm
4.安裝完後開啟服務
1.啟動服務:
rabbitmq-server --detached
2.檢視狀態:
Rabbitmqctl status
3.檢查埠5672是否開啟
/sbin/iptables -I INPUT -p tcp --dport 5672 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables restart
/etc/init.d/iptables status
4.啟用維護外掛
rabbitmq-plugins enable rabbitmq_management
5.由於RabbitMQ預設的guest帳號只能通過localhost訪問,如果想進行遠端訪問,就需要建立一個新賬號
rabbitmqctl add_user chanpay chanpay 第一個chanpay是帳號,第二個是密碼
設定角色
rabbitmqctl set_user_tags chanpay administrator (monitoring policymaker management)
設定使用者許可權
rabbitmqctl set_permissions -p ”/”chanpay '.*' '.*' '.*'
補充:開啟使用者遠端訪問
Vim /etc/rabbitmq/rabbitmq.config
去掉loopback_user 前面的百分號和後面的逗號
5.叢集安裝
1)同步Erlang Cookie
檢視某臺機器的cookie
cat /var/lib/rabbitmq/.erlang.cookie
關閉其他機器上的rabbitMQ,將cookie複製到該機器
rabbitmqctl stop
echo cookie > /var/lib/rabbitmq/.erlang.cookie
Cookie同步之後啟動rabbitMQ
rabbitmq-server -detached
如果提示PID FILE不能寫入,可以關閉應用,直接以服務的方式啟動
啟動服務:
service rabbitmq-server start
2)加入叢集
將其中一個節點另一個節點作為Disk型別節點
rabbitmqctl stop_app
rabbitmqctl join_cluster [email protected]_(機器名稱)
rabbitmqctl start_app
檢視叢集狀態
rabbitmqctl cluster_status
設定映象佇列策略
Rabbitmqctl set_policy ha-all “^” ‘{“ha-mode”:”all”}’
6.安裝並配置HaProxy
yum install haproxy
vim /etc/haproxy/haproxy.cfg
1.安裝配置yum
cd /etc/yum.repos.d/ 會看到很多repo檔案
vim CentOS-Base.repo 將此檔案內容修改為下圖內容
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
2.安裝erlang
1)新增Erlang Solutions key 支援
rpm --import http://binaries.erlang-solutions.com/debian/erlang_solutions.asc
wget http://binaries.erlang-solutions.com/rpm/centos/erlang_solutions.repomv erlang_solutions.repo /etc/yum.repos.d/ 將solutions key 移動到該目錄
2)由於安裝erlang需要大量的依賴,(CentOS的原始庫缺少某些依賴)先引入第三方庫rpmfusion
先引入該第三方庫所需的依賴:
yum install epel-release
3)開始安裝rpmfusion:
rpm -ivh https://download1.rpmfusion.org/free/el/updates/6/i386/rpmfusion-free-release-6-1.noarch.rpm
4)開始安裝erlang
yum install erlang
3.安裝RabbitMQ
1)安裝RabbitMQ之前需要安裝socat
yum install socat
2)安裝RabbitMQ
wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.5/rabbitmq-server-3.6.5-1.noarch.rpm
4.安裝完後開啟服務
1.啟動服務:
rabbitmq-server --detached
2.檢視狀態:
Rabbitmqctl status
3.檢查埠5672是否開啟
/sbin/iptables -I INPUT -p tcp --dport 5672 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables restart
/etc/init.d/iptables status
4.啟用維護外掛
rabbitmq-plugins enable rabbitmq_management
5.由於RabbitMQ預設的guest帳號只能通過localhost訪問,如果想進行遠端訪問,就需要建立一個新賬號
rabbitmqctl add_user chanpay chanpay 第一個chanpay是帳號,第二個是密碼
設定角色
rabbitmqctl set_user_tags chanpay administrator (monitoring policymaker management)
設定使用者許可權
rabbitmqctl set_permissions -p ”/”chanpay '.*' '.*' '.*'
補充:開啟使用者遠端訪問
Vim /etc/rabbitmq/rabbitmq.config
去掉loopback_user 前面的百分號和後面的逗號
5.叢集安裝
1)同步Erlang Cookie
檢視某臺機器的cookie
cat /var/lib/rabbitmq/.erlang.cookie
關閉其他機器上的rabbitMQ,將cookie複製到該機器
rabbitmqctl stop
echo cookie > /var/lib/rabbitmq/.erlang.cookie
Cookie同步之後啟動rabbitMQ
rabbitmq-server -detached
如果提示PID FILE不能寫入,可以關閉應用,直接以服務的方式啟動
啟動服務:
service rabbitmq-server start
2)加入叢集
將其中一個節點另一個節點作為Disk型別節點
rabbitmqctl stop_app
rabbitmqctl join_cluster
rabbitmqctl start_app
檢視叢集狀態
rabbitmqctl cluster_status
設定映象佇列策略
Rabbitmqctl set_policy ha-all “^” ‘{“ha-mode”:”all”}’
6.安裝並配置HaProxy
yum install haproxy
vim /etc/haproxy/haproxy.cfg