1. Centos安装rabbitmq
1.1. 优化建议
对rabbitmq配置文件参数进行优化
1.2. 安装erlang
1.2.1. 安装依赖:
yum -y install gcc glibc-devel make ncurses-devel openssl-devel xmlto perl wget gtk2-devel binutils-devel
1.2.2. 下载安装包
erlang官网:https://www.erlang.org/downloads
由于下载的很慢,本地有一个已下载好的安装包,直接上传
wget http://erlang.org/download/otp_src_22.0.tar.gz
1.2.3. xftp上传安装包至/root目录下
1.2.4. 解压
tar -zxvf otp_src_22.0.tar.gz
1.2.5. 移动并进入目录
mv otp_src_22.0 /usr/local/
cd /usr/local/otp_src_22.0/
mkdir -p /usr/local/erlang
1.2.6. 配置安装路径
./configure --prefix=/usr/local/erlang
1.2.7. 安装
make
make install
ll /usr/local/erlang/bin #查看是否安装成功
1.2.8. 添加环境变量
echo 'export PATH=$PATH:/usr/local/erlang/bin' >> /etc/profile
使生效:
source /etc/profile
1.2.9. 检测环境变量是否可用
erl
输入 halt(). 退出
1.3. 安装rabbitmq
1.3.1. 下载rabbitmq
rabbitmq下载地址:
https://github.com/rabbitmq/rabbitmq-server/releases/tag/v3.7.15
1.3.2. Xftp上传安装包至服务器/root
1.3.3. 安装解压插件并解压
yum install -y xz
/bin/xz -d rabbitmq-server-generic-unix-3.7.15.tar.xz #第一次解压
tar -xvf rabbitmq-server-generic-unix-3.7.15.tar #第二次解压
tar -xvf rabbitmq-server-3.8.19.tar.xz
1.3.4. 移动
mv rabbitmq_server-3.7.15/ /usr/local/rabbitmq
1.3.5. 配置环境变量
echo 'export PATH=$PATH:/usr/local/rabbitmq/sbin' >> /etc/profile
使生效
source /etc/profile
1.3.6. 创建配置目录
mkdir /etc/rabbitmq
1.3.7. 相关启动命令
启动:
rabbitmq-server -detached
停止:
rabbitmqctl stop
状态:
rabbitmqctl status
1.3.8. Web管理
开启web插件:
rabbitmq-plugins enable rabbitmq_management
浏览器访问:http://ip:15672/
默认账号密码:guest guest(这个账号只允许本机访问)
1.3.9. 用户管理
查看所有用户:
rabbitmqctl list_users
添加一个用户:
rabbitmqctl add_user zhangbo 123456
rabbitmqctl add_user cepo1113 Rabbitmq#0902@Cepo
配置权限:
rabbitmqctl set_permissions -p "/" cepo1113 ".*" ".*" ".*"
查看用户权限:
rabbitmqctl list_user_permissions cepo1113
设置tag:
rabbitmqctl set_user_tags cepo1113 administrator
删除用户(安全起见,删除默认用户):
rabbitmqctl delete_user guest
添加普通用户
rabbitmqctl add_user test1 Rabbitmq#0902@Cepo
添加vhosts
rabbitmqctl add_vhost /test1
配置权限
rabbitmqctl set_permissions -p /test1 test1 '.*' '.*' '.*'
查看用户权限
rabbitmqctl list_permissions --vhost /test1
添加policy
rabbitmqctl set_policy --vhost /test1 --priority 1 --apply-to all test1 "^" '{"ha-mode":"all"}'
1.4. rabbitmq集群部署
1.4.1. 修改服务器hostname
vim /etc/hostname
第一台叫mq01,第二台叫mq02,第三台叫mq03
1.4.2. 修改dns文件
vim /etc/hosts
三台都需要做操作
10.20.1.2 mq01
10.20.1.3 mq02
10.20.1.3 mq03
添加 /etc/rabbitmq/rabbitmq-env.conf 文件
vim /etc/rabbitmq/rabbitmq-env.conf
三台分别是
NODENAME=rabbit@mq01
NODENAME=rabbit@mq02
NODENAME=rabbit@mq03
1.4.3. 杀死每个节点的mq
ps -ef | grep 5672
kill -9 pid
1.4.4. 查看.erlang.cookie
cd /root
ls -al
1.4.5. 将主节点的.erlang.cookie传输到其他节点
scp /root/.erlang.cookie root@10.20.1.3:/root/
scp /root/.erlang.cookie root@10.20.1.4:/root/
1.4.6. 开启rabbitmq服务
三台mq01,mq02,mq03都开启服务
rabbitmq-server -detached
1.4.7. 从节点执行命令
将 mq02 和 mq03 作为内存节点与 mq01 磁盘节点连接起来,在mq02 和 mq03 执行以下命令
rabbitmqctl stop_app #停掉rabbitmq应用
rabbitmqctl join_cluster rabbit@mq01 --ram #加入到磁盘节点
rabbitmqctl start_app #启动rabbitmq应用
rabbitmqctl cluster_status #查看集群状态
1.4.8. 设置自启动脚本
编辑脚本
vim /usr/local/rabbitmq/sbin/start_rabbitmq.sh
内容如下:
#!/bin/bash
export PATH=$PATH:/usr/local/erlang/bin
export HOME=/root/
/usr/local/rabbitmq/sbin/rabbitmq-server -detached
给脚本赋可执行权限
chmod +x /usr/local/rabbitmq/sbin/start_rabbitmq.sh
设置脚本自启动:
vim /etc/rc.d/rc.local
在最后边添加
/usr/local/rabbitmq/sbin/start_rabbitmq.sh
给rc.local赋权
chmod +x /etc/rc.d/rc.local
1.4.9. 检验服务是否自启动
三台服务器:reboot
1.4.10. 浏览器配置
访问http://ip:15672
使用zhangbo/123456用户登录
按照下述图片配置
1.4.11. 内存磁盘模式变更
rabbitmqctl stop_app
bbitmqctl change_cluster_node_type ram
rabbitmqctl change_cluster_node_type ram
rabbitmqctl start_app
rabbitmqctl cluster_status
2. 优化配置相关
优化配置命令相关:
ulimit -n 65535
-------------------------------------------------------------------------------------------
vim /etc/security/limits.conf
修改(添加内容)文件如下:
* soft noproc 10240
* hard noproc 10240
* soft nofile 65535
* hard nofile 65535
-------------------------------------------------------------------------------------------
vim /etc/sysctl.conf
内容如下:
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
vm.swappiness = 0
net.ipv4.neigh.default.gc_stale_time=120
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_announce=2
net.ipv4.conf.all.arp_announce=2
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_synack_retries = 2
kernel.sysrq=1
net.core.somaxconn = 60000
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 4096 16777216
net.ipv4.tcp_wmem = 4096 4096 16777216
net.ipv4.tcp_mem = 786432 2097152 3145728
net.core.netdev_max_backlog = 20000
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_max_orphans = 131072
vm.overcommit_memory = 1
net.core.somaxconn = 2048
使上述配置生效:
sysctl -p
---------------------------------------------------------------------------
vim /etc/default/grub
内容如下:
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
-------------------------------------------------------------------------------------
vim /etc/pam.d/login
内容如下:
#%PAM-1.0
auth [user_unknown=ignore success=ok ignore=ignore default=bad] pam_securetty.so
auth substack system-auth
auth include postlogin
account required pam_nologin.so
account include system-auth
password include system-auth
# pam_selinux.so close should be the first session rule
session required pam_selinux.so close
session required pam_loginuid.so
session optional pam_console.so
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session required pam_selinux.so open
session required pam_namespace.so
session optional pam_keyinit.so force revoke
session include system-auth
session include postlogin
-session optional pam_ck_connector.so
session required pam_limits.so
----------------------------------------------------------------------------------
ulimit -n
------------------------------------------------------------------------------------
ulimit -a
展示效果如下:
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 63443
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 65535
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 63443
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited