Linux (版本centos 6.x)安装 RabbitMQ
1. 首先下载erlang。原因在于RabbitMQ服务端代码是使用并发式语言erlang编写的。
**先安装一下依赖:** yum -y install unixODBC unixODBC-devel wxBase wxGTK SDL wxGTK-gl yum -y install install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl openssl-devel xmlto zip unzip yum -y install gtk2-devel binutils-devel
2. 下载 安装 otp_src_19.3.tar.gz
wget http://erlang.org/download/otp_src_19.3.tar.gz 解压otp_src_19.3.tar.gz: tar -xvzf otp_src_19.3.tar.gz cd otp_src_19.3 配置cd otp_src_19.3: ./configure --enable-smp-support --enable-threads --enable-sctp --enable-kernel-poll --enable-hipe --with-ssl
参数说明:
--prefix 指定安装目录 --enable-smp-support启用对称多处理支持(Symmetric Multi-Processing对称多处理结构的简称) --enable-threads启用异步线程支持 --enable-sctp启用流控制协议支持(Stream Control Transmission Protocol,流控制传输协议) --enable-kernel-poll启用Linux内核poll --enable-hipe启用高性能Erlang(High Performance Erlang)参考资料:http://www.cnblogs.com/me-sa/archive/2012/10/09/erlang_hipe.html --with-ssl使用SSL包
执行命安装
make && make install
检测erlang 是否安装正常
find / -name erlang /usr/local/erlang /usr/local/erlang/lib/erlang /usr/local/erlang/lib/erlang/lib/jinterface-1.6.1/java_src/com/ericsson/otp/erlang /usr/local/lib/erlang /usr/local/lib/erlang/lib/jinterface-1.7.1/java_src/com/ericsson/otp/erlang /usr/erlang /usr/erlang/otp_src_19.3/lib/jinterface/priv/com/ericsson/otp/erlang /usr/erlang/otp_src_19.3/lib/jinterface/java_src/com/ericsson/otp/erlang find / -name erl /usr/local/bin/erl /usr/local/erlang/bin/erl /usr/local/erlang/lib/erlang/bin/erl /usr/local/erlang/lib/erlang/erts-7.3/bin/erl /usr/local/lib/erlang/erts-8.3/bin/erl /usr/local/lib/erlang/bin/erl /usr/erlang/otp_src_19.3/bin/erl /usr/erlang/otp_src_19.3/bootstrap/bin/erl /usr/erlang/otp_src_19.3/erts/etc/win32/msys_tools/erl /usr/erlang/otp_src_19.3/erts/etc/win32/cygwin_tools/erl
查看是否安装成功
[root@chenwangmin /]# erl Erlang/OTP 19 [erts-8.3] [source] [64-bit] [async-threads:10] [hipe] [kernel-poll:false] Eshell V8.3 (abort with ^G) 1> 提示如上命令说明已经安装成功。
3. 下载 安装 rabbitMQ
下载rabbitmq-server-generic-unix-3.6.9.tar.xz
wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.9/rabbitmq-server-generic-unix-3.6.9.tar.xz
解压
xz -d rabbitmq-server-generic-unix-3.6.9.tar.xz tar -xvf rabbitmq-server-generic-unix-3.6.9.tar
配置环境变量
JAVA_HOME=/usr/java/jdk1.8.0_77 ERL_HOME=/usr/local/lib/erlang //配置这个 RABBITMQ_HOME=/usr/rabbitmq/rabbitmq_server-3.6.9 //配置这个 CLASSPATH=$JAVA_HOME/lib/ PATH=$PATH:$JAVA_HOME/bin:$ERL_HOME/bin:$RABBITMQ_HOME/sbin //配置这个 export PATH JAVA_HOME CLASSPATH ERL_HOME RABBITMQ_HOME //配置这个 **启动RabbitMQ Server** [root@chenwangmin /]# rabbitmq-server start ## ## ## ## RabbitMQ 3.7.4. Copyright (C) 2007-2018 Pivotal Software,Inc. ########## Licensed under the MPL. See http://www.rabbitmq.com/ ###### ## ########## Logs: /var/log/rabbitmq/rabbit@chenwangmin.log /var/log/rabbitmq/rabbit@chenwangmin_upgrade.log Starting broker... completed with 3 plugins. 提示此信息启动成功!
[root@chenwangmin sbin]# rabbitmqctl add_user admin 12345 Creating user "admin" ...
设置用户权限为administrator
[root@chenwangmin sbin]# rabbitmqctl set_user_tags admin administrator Setting tags for user "admin" to [administrator] ... [root@chenwangmin sbin]#
查看插件信息
[root@chenwangmin sbin]# rabbitmq-plugins list Configured: E = explicitly enabled; e = implicitly enabled | Status: [Failed to contact rabbit@chenwangmin - status not shown] |/ [ ] rabbitmq_amqp1_0 3.7.4 [ ] rabbitmq_auth_backend_cache 3.7.4 [ ] rabbitmq_auth_backend_http 3.7.4 [ ] rabbitmq_auth_backend_ldap 3.7.4 [ ] rabbitmq_auth_mechanism_ssl 3.7.4 [ ] rabbitmq_consistent_hash_exchange 3.7.4 [ ] rabbitmq_event_exchange 3.7.4 [ ] rabbitmq_federation 3.7.4 [ ] rabbitmq_federation_management 3.7.4 [ ] rabbitmq_jms_topic_exchange 3.7.4 .................... .................... [root@chenwangmin sbin]#
启用插件 ,使用rabbitmq管理界面
[root@chenwangmin sbin]# rabbitmq-plugins enable rabbitmq_management The following plugins have been configured: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch Applying plugin configuration to rabbit@chenwangmin... Plugin configuration unchanged.
查看运行状态
[root@chenwangmin sbin]# rabbitmqctl status Status of node rabbit@chenwangmin ... [{pid,50625},{running_applications,[{rabbitmq_management,"RabbitMQ Management Console","3.7.4"},{rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher",{rabbitmq_management_agent,"RabbitMQ Management Agent",{rabbit,"RabbitMQ",{os_mon,"CPO CXC 138 46","2.4.2"},{cowboy,"Small,fast,modern HTTP server.","2.2.2"},{amqp_client,"RabbitMQ AMQP Client",{rabbit_common,"Modules shared by rabbitmq-server and rabbitmq-erlang-client",{ranch_proxy_protocol,"Ranch Proxy Protocol Transport","1.4.4"},{ranch,"Socket acceptor pool for TCP protocols.","1.4.0"},.................... ....................
重启服务
service iptables restart
查看页面
如果登陆http://IP:15672/ 还不能看到管理界面。可能事防火墙问题。 需要对防火墙进行处理: 找到iptables配置路径: [root@Rabbitmq sbin]# find / -name iptables /etc/sysconfig/iptables
[root@Rabbitmq sbin]# vi /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 27017 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 28017 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 15672 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 5672 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 25672 -j ACCEPT
重启服务:
service iptables restart
4 问题总结
-bash: wget: command not found的两种解决方法?
1、rpm 安装 rpm 下载源地址:http://mirrors.163.com/centos/6.2/os/x86_64/Packages/ 下载wget的RPM包:http://mirrors.163.com/centos/6.2/os/x86_64/Packages/wget-1.12-1.4.el6.x86_64.rpm rpm ivh wget-1.12-1.4.el6.x86_64.rpm 安装即可。 如果客户端用的是SecureCRT,linux下没装rzsz 包时,rz无法上传文件怎么办?我想到的是安装另一个SSH客户端:SSH Secure Shell。然后传到服务器上安装,这个比较费劲,所以推荐用第二种方法,不过如果yum包也没有安装的话,那就只能用这种方法了。 2、yum安装 yum -y install wget
如果没有xz解压软件?
安装xz解压软件: yum -y install xz
5. 常用命令
1). 服务器启动与关闭 启动: rabbitmq-server –detached 关闭:rabbitmqctl stop 若单机有多个实例,则在rabbitmqctlh后加–n 指定名称 2). 插件管理 开启某个插件:rabbitmq-pluginsenable xxx 关闭某个插件:rabbitmq-pluginsdisablexxx 注意:重启服务器后生效。 3).virtual_host管理 新建virtual_host: rabbitmqctladd_vhost xxx 撤销virtual_host:rabbitmqctl delete_vhost xxx 4). 用户管理 新建用户:rabbitmqctl add_user xxxpwd 删除用户: rabbitmqctl delete_user xxx 改密码: rabbimqctlchange_password {username} {newpassword} 设置用户角色:rabbitmqctlset_user_tags {username} {tag ...} Tag可以为 administrator,monitoring,management 5). 权限管理 权限设置:set_permissions [-pvhostpath] {user} {conf} {write} {read} Vhostpath Vhost路径 user 用户名 Conf 一个正则表达式match哪些配置资源能够被该用户访问。 Write 一个正则表达式match哪些配置资源能够被该用户读。 Read 一个正则表达式match哪些配置资源能够被该用户访问。 6). 获取服务器状态信息 服务器状态:rabbitmqctl status
系统命令
卸载 #rpm -qa|grep rabbitmq rabbitmq-server-3.6.1-1.noarch #rpm -e --nodeps rabbitmq-server-3.6.1-1.noarch #rpm -qa|grep erlang esl-erlang-18.3-1.x86_64 #rpm -e --nodeps esl-erlang-18.3-1.x86_64
服务
#service rabbitmq-server start --后台方式运行 #service rabbitmq-server stop --停止运行 #service rabbitmq-server status --查看状态