装完系统 然后
配置ssh登录:
yum install -y openssh-server
vi /etc/ssh/sshd_config
将 以下几行的注释取消:
Port 22
ListenAddress 0.0.0.0
ListenAddress ::
PermitRootLogin yes
PasswordAuthentication yes
:wq
systemctl enable sshd
systemctl start sshd
firewall-cmd --permanent --zone=public --add-port=22/tcp;
firewall-cmd --reload;
reboot;
这时候可以远程登录了;
然后可选更新内核:
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
yum --enablerepo=elrepo-kernel install kernel-lt -y
yum remove kernel-3.* kernel-tools-libs-3.* kernel-tools-3.*
rpm -e kernel-3.*
grub2-mkconfig -o /boot/grub2/grub.cfg
reboot;
这时候就内核就换成较新的了;
接下来yum安装erlang和rpm安装rabbitmq:
3.6.x版本:
yum clean all;
yum makecache;
yum install -y epel-release;
yum install -y erlang;
yum install -y socat;
yum install -y logrotate;
rpm -i http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.15/rabbitmq-server-3.6.15-1.el7.noarch.rpm;
到此3.6版本的基本安装完成;
3.7.x版本:
vi /etc/yum.repos.d/rabbitmq_erlang.repo
[rabbitmq-erlang]
name=rabbitmq-erlang
baseurl=https://dl.bintray.com/rabbitmq/rpm/erlang/20/el/7
gpgcheck=1
gpgkey=https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc
repo_gpgcheck=0
enabled=1
:wq
vi /etc/yum.repos.d/rabbitmq.repo
[bintray-rabbitmq-server]
name=bintray-rabbitmq-rpm
baseurl=https://dl.bintray.com/rabbitmq/rpm/rabbitmq-server/v3.7.x/el/7/
gpgcheck=0
repo_gpgcheck=0
enabled=1
:wq
yum clean all;
yum makecache;
yum install -y epel-release;
yum install rabbitmq-server-3.7.13 -y
到此3.7版本的基本安装完成;
打开插件:
rabbitmq-plugins enable rabbitmq_management;
启动服务:
systemctl enable rabbitmq-server
systemctl start rabbitmq-server
这时候 rabbitmq 基础环境就装好了 并且单机模式已经启动了
集群需要构建需要修改主机名:
先设立两台样例主机:
rabbit1 对应ip 192.168.1.18
rabbit3 对应ip 192.168.1.19
rabbit1上:
hostnamectl set-hostname rabbit1
rabbit3上:
hostnamectl set-hostname rabbit3
所有节点上都配置所有集群上的主机名与ip的对应:
vi /etc/hosts
在尾部增加:
rabbit1 192.168.1.18
rabbit3 192.168.1.18
wq:
处理erlang cookie文件(所有节点):
rm -rf /var/lib/rabbitmq/.erlang.cookie;echo "NICAYNNZGMAHW1LRVQQU" >> /var/lib/rabbitmq/.erlang.cookie;chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie;chmod 600 /var/lib/rabbitmq/.erlang.cookie;
rm -rf /root/.erlang.cookie; ln -s /var/lib/rabbitmq/.erlang.cookie /root/.erlang.cookie;chown root:root /root/.erlang.cookie;chmod 777 /root/.erlang.cookie;
chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie;chmod 600 /var/lib/rabbitmq/.erlang.cookie;
配置文件(该配置文件现实里似乎并不成功,所以我下面有另外的命令处理):
vi /etc/rabbitmq/rabbitmq.conf
loopback_users.guest = false
listeners.tcp.default = 5672
default_pass = 123abc
default_user = admin
default_vhost = my_vhost
hipe_compile = false
management.listener.port = 15672
management.listener.ssl = false
:wq
chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.conf;chmod 644 /etc/rabbitmq/rabbitmq.conf;
注意RABBITMQ_NODENAME这里我因为直接准备用主机的hostname所以没有设;
如果需要设:
vi /etc/rabbitmq/rabbitmq-env.conf
RABBITMQ_NODENAME=rabbit3(换成你自己具体的节点名)
:wq
开端口:(5671和15671默认并不用可以不开)
firewall-cmd --permanent --zone=public --add-port=4369/tcp;
firewall-cmd --permanent --zone=public --add-port=5671/tcp;
firewall-cmd --permanent --zone=public --add-port=5672/tcp;
firewall-cmd --permanent --zone=public --add-port=15671/tcp;
firewall-cmd --permanent --zone=public --add-port=15672/tcp;
firewall-cmd --permanent --zone=public --add-port=25672/tcp;
firewall-cmd --reload;
有的时候到这时候 还是不能正常登录可以 执行以下命令:
rabbitmqctl add_user admin 123abc
rabbitmqctl delete_user guest
rabbitmqctl add_vhost my_vhost
rabbitmqctl set_permissions -p my_vhost admin ConfP WriteP ReadP
搭建集群并且开启镜像:
在rabbit3节点上:
rabbitmqctl stop_app
rabbitmqctl join_cluster rabbit@rabbit1(反正是另一个节点的节点名@主机名)
rabbitmqctl start_app
rabbitmqctl set_policy -p my_vhost HA '^(?!amq.).*' '{"ha-mode":"all", "ha-sync-mode":"automatic"}'
2个节点集群 大功告成。