1.安装erlang
需要注意erlang的版本是否满足rabbitmq的需求
这里用到的版本是:Erlang 19.0.4 RabbitMQ 3.6.15
wget http://www.rabbitmq.com/releases/erlang/erlang-19.0.4-1.el7.centos.x86_64.rpm rpm -ivh erlang-19.0.4-1.el7.centos.x86_64.rpm
yum -y install erlang
wget http://www.rabbitmq.com/releases/erlang/erlang-19.0.4-1.el7.centos.x86_64.rpm rpm -ivh erlang-19.0.4-1.el7.centos.x86_64.rpm yum -y install erlang
1.1测试erlang是否安装
erl -version
erl -version
2.安装rabbitmq
wget https://www.rabbitmq.com/releases/rabbitmq-server/current/rabbitmq-server-3.6.15-1.el6.noarch.rpm yum install rabbitmq-server-3.6.15-1.el6.noarch.rpm
wget https://www.rabbitmq.com/releases/rabbitmq-server/current/rabbitmq-server-3.6.15-1.el6.noarch.rpm yum install rabbitmq-server-3.6.15-1.el6.noarch.rpm
2.1其他相关命令
启动:systemctl start rabbitmq-server 开机自动启动:systemctl enable rabbitmq-server 查看 rabbitmq-server 状态:rabbitmqctl status
启动:systemctl start rabbitmq-server 开机自动启动:systemctl enable rabbitmq-server 查看 rabbitmq-server 状态:rabbitmqctl status
2.2配置网页插件
首先创建目录,否则可能报错: mkdir /etc/rabbitmq 然后启用插件: rabbitmq-plugins enable rabbitmq_management
首先创建目录,否则可能报错: mkdir /etc/rabbitmq 然后启用插件: rabbitmq-plugins enable rabbitmq_management
2.3配置防火墙
配置linux 端口 15672 网页管理 5672 AMQP端口: firewall-cmd --permanent --add-port=15672/tcp firewall-cmd --permanent --add-port=5672/tcp systemctl restart firewalld.service
配置linux 端口 15672 网页管理 5672 AMQP端口: firewall-cmd –permanent –add-port=15672/tcp firewall-cmd –permanent –add-port=5672/tcp systemctl restart firewalld.service
现在你在浏览器中输入服务器IP:15672 就可以看到RabbitMQ的WEB管理页面了
2.4配置访问账号密码和权限
默认网页是不允许访问的,需要增加一个用户修改一下权限,代码如下: rabbitmqctl add_user rabbit 123456 //添加用户,后面两个参数分别是用户名和密码 rabbitmqctl set_permissions -p / rabbit ".*" ".*" ".*" //添加权限 rabbitmqctl set_user_tags rabbit administrator //修改用户角色 然后就可以远程访问了,然后可直接配置用户权限等信息。 登录:http://ip:15672 登录之后在admin里面把guest删除。
默认网页是不允许访问的,需要增加一个用户修改一下权限,代码如下: rabbitmqctl add_user rabbit 123456 //添加用户,后面两个参数分别是用户名和密码 rabbitmqctl set_permissions -p / rabbit ".*" ".*" ".*" //添加权限 rabbitmqctl set_user_tags rabbit administrator //修改用户角色 然后就可以远程访问了,然后可直接配置用户权限等信息。 登录:http://ip:15672 登录之后在admin里面把guest删除。
3.开始配置集群
3.1配置节点的host
vim /etc/hosts 192.168.161.200 slave1 192.168.161.201 slave2 192.168.161.202 slave3
vim /etc/hosts 192.168.161.200 slave1 192.168.161.201 slave2 192.168.161.202 slave3
集群中的所有节点均需要配置
3.1配置erlang的cookie,cookie要一致
官方在介绍集群的文档中提到过.erlang.cookie一般会存在这两个地址:第一个是$home/.erlang.cookie;第二个地方就是/var/lib/rabbitmq/.erlang.cookie。 如果我们使用解压缩方式安装部署的rabbitmq,那么这个文件会在${home}目录下,也就是$home/.erlang.cookie。 如果我们使用rpm等安装包方式进行安装的,那么这个文件会在/var/lib/rabbitmq目录下。
如果修改文件,rabbitmq不能启动,这个时候用这个命令修改一下cookie: chmod 400 .erlang.cookie
3.2查看集群信息,确定集群的名称
rabbitmqctl cluster_status Cluster status of node rabbit@slave2 [{nodes,[{disc,[rabbit@slave1,rabbit@slave2,rabbit@slave3]}]}, {running_nodes,[rabbit@slave3,rabbit@slave1,rabbit@slave2]}, {cluster_name,<<"rabbit@slave1">>}, {partitions,[]}, {alarms,[{rabbit@slave3,[]},{rabbit@slave1,[]},{rabbit@slave2,[]}]}] 查看cluster_name的值
rabbitmqctl cluster_status Cluster status of node rabbit@slave2 [{nodes,[{disc,[rabbit@slave1,rabbit@slave2,rabbit@slave3]}]}, {running_nodes,[rabbit@slave3,rabbit@slave1,rabbit@slave2]}, {cluster_name,<<"rabbit@slave1">>}, {partitions,[]}, {alarms,[{rabbit@slave3,[]},{rabbit@slave1,[]},{rabbit@slave2,[]}]}] 查看cluster_name的值
3.3加入集群
1.停止当前要加入到集群的节点的rabiitmq服务
rabbitmqctl stop_app
rabbitmqctl stop_app
2.加入集群
示例命令: rabbitmqctl join_cluster rabbit@slave1
示例命令: rabbitmqctl join_cluster rabbit@slave1
3.启动rabbitmq服务
rabbitmqctl start_app
rabbitmqctl start_app
4.可以用命令 rabbitmqctl cluster_status查看节点是否正确加入,也可以使用webUI查看
4 开始配置负载均衡
4.1 nginx的安装和启用stream模块的方法
4.2关键配置
user nginx; worker_processes 1; error_log /usr/local/nginx/logs/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /usr/local/nginx/conf/mime.types; default_type application/octet-stream; log_format main $remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"; access_log /usr/local/nginx/logs/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; upstream honeysuckle { ip_hash; server 192.168.161.202:31531; server 192.168.161.201:31531; server 192.168.161.200:31531; } server{ listen 80; location / { proxy_pass http://honeysuckle; } } upstream rabbitmqweb { ip_hash; server 192.168.161.202:15672; server 192.168.161.201:15672; server 192.168.161.200:15672; } server{ listen 15672; location / { proxy_pass http://rabbitmqweb; } } include /etc/nginx/conf.d/*.conf; } stream{ upstream rabbitmq{ server 192.168.161.200:5672 weight=1; server 192.168.161.201:5672 weight=1; server 192.168.161.202:5672 weight=1; } server{ listen 5672; proxy_pass rabbitmq; } }
user nginx; worker_processes 1; error_log /usr/local/nginx/logs/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /usr/local/nginx/conf/mime.types; default_type application/octet-stream; log_format main $remote_addr – $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"; access_log /usr/local/nginx/logs/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; upstream honeysuckle { ip_hash; server 192.168.161.202:31531; server 192.168.161.201:31531; server 192.168.161.200:31531; } server{ listen 80; location / { proxy_pass http://honeysuckle; } } upstream rabbitmqweb { ip_hash; server 192.168.161.202:15672; server 192.168.161.201:15672; server 192.168.161.200:15672; } server{ listen 15672; location / { proxy_pass http://rabbitmqweb; } } include /etc/nginx/conf.d/*.conf; } stream{ upstream rabbitmq{ server 192.168.161.200:5672 weight=1; server 192.168.161.201:5672 weight=1; server 192.168.161.202:5672 weight=1; } server{ listen 5672; proxy_pass rabbitmq; } }
4.3 测试是否生效
最直观的办法是使用rabbitMQ web查看连接是否可以命中(根据nginx配置的负载均衡策略)配置的节点
1.安装erlang 需要注意erlang的版本是否满足rabbitmq的需求 这里用到的版本是:Erlang 19.0.4 RabbitMQ 3.6.15 wget http://www.rabbitmq.com/releases/erlang/erlang-19.0.4-1.el7.centos.x86_64.rpm rpm -ivh erlang-19.0.4-1.el7.centos.x86_64.rpm yum -y install erlang 1.1测试erlang是否安装 erl -version 2.安装rabbitmq wget https://www.rabbitmq.com/releases/rabbitmq-server/current/rabbitmq-server-3.6.15-1.el6.noarch.rpm yum install rabbitmq-server-3.6.15-1.el6.noarch.rpm 2.1其他相关命令 启动:systemctl start rabbitmq-server 开机自动启动:systemctl enable rabbitmq-server 查看 rabbitmq-server 状态:rabbitmqctl status 2.2配置网页插件 首先创建目录,否则可能报错: mkdir /etc/rabbitmq 然后启用插件: rabbitmq-plugins enable rabbitmq_management 2.3配置防火墙 配置linux 端口 15672 网页管理 5672 AMQP端口: firewall-cmd –permanent –add-port=15672/tcp firewall-cmd –permanent –add-port=5672/tcp systemctl restart firewalld.service 现在你在浏览器中输入服务器IP:15672 就可以看到RabbitMQ的WEB管理页面了 2.4配置访问账号密码和权限 默认网页是不允许访问的,需要增加一个用户修改一下权限,代码如下: rabbitmqctl add_user rabbit 123456 //添加用户,后面两个参数分别是用户名和密码 rabbitmqctl set_permissions -p / rabbit ".*" ".*" ".*" //添加权限 rabbitmqctl set_user_tags rabbit administrator //修改用户角色 然后就可以远程访问了,然后可直接配置用户权限等信息。 登录:http://ip:15672 登录之后在admin里面把guest删除。 3.开始配置集群 3.1配置节点的host vim /etc/hosts 192.168.161.200 slave1 192.168.161.201 slave2 192.168.161.202 slave3 集群中的所有节点均需要配置 3.1配置erlang的cookie,cookie要一致 官方在介绍集群的文档中提到过.erlang.cookie一般会存在这两个地址:第一个是$home/.erlang.cookie;第二个地方就是/var/lib/rabbitmq/.erlang.cookie。 如果我们使用解压缩方式安装部署的rabbitmq,那么这个文件会在${home}目录下,也就是$home/.erlang.cookie。 如果我们使用rpm等安装包方式进行安装的,那么这个文件会在/var/lib/rabbitmq目录下。 如果修改文件,rabbitmq不能启动,这个时候用这个命令修改一下cookie: chmod 400 .erlang.cookie 3.2查看集群信息,确定集群的名称 rabbitmqctl cluster_status Cluster status of node rabbit@slave2 [{nodes,[{disc,[rabbit@slave1,rabbit@slave2,rabbit@slave3]}]}, {running_nodes,[rabbit@slave3,rabbit@slave1,rabbit@slave2]}, {cluster_name,<<"rabbit@slave1">>}, {partitions,[]}, {alarms,[{rabbit@slave3,[]},{rabbit@slave1,[]},{rabbit@slave2,[]}]}] 查看cluster_name的值 3.3加入集群 1.停止当前要加入到集群的节点的rabiitmq服务 rabbitmqctl stop_app 2.加入集群 示例命令: rabbitmqctl join_cluster rabbit@slave1 3.启动rabbitmq服务 rabbitmqctl start_app 4.可以用命令 rabbitmqctl cluster_status查看节点是否正确加入,也可以使用webUI查看 4 开始配置负载均衡 4.1 nginx的安装和启用stream模块的方法 4.2关键配置 user nginx; worker_processes 1; error_log /usr/local/nginx/logs/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /usr/local/nginx/conf/mime.types; default_type application/octet-stream; log_format main $remote_addr – $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"; access_log /usr/local/nginx/logs/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; upstream honeysuckle { ip_hash; server 192.168.161.202:31531; server 192.168.161.201:31531; server 192.168.161.200:31531; } server{ listen 80; location / { proxy_pass http://honeysuckle; } } upstream rabbitmqweb { ip_hash; server 192.168.161.202:15672; server 192.168.161.201:15672; server 192.168.161.200:15672; } server{ listen 15672; location / { proxy_pass http://rabbitmqweb; } } include /etc/nginx/conf.d/*.conf; } stream{ upstream rabbitmq{ server 192.168.161.200:5672 weight=1; server 192.168.161.201:5672 weight=1; server 192.168.161.202:5672 weight=1; } server{ listen 5672; proxy_pass rabbitmq; } } 4.3 测试是否生效 最直观的办法是使用rabbitMQ web查看连接是否可以命中(根据nginx配置的负载均衡策略)配置的节点
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/290393.html