记录一下在centos7.x下面安装activeMQ消息中间件
在安装ActiveMQ之前必须保证服务器安装了java环境
安装java环境的地址:安装java环境
找到activeMQ的官网下载安装包
https://activemq.apache.org/components/classic/download/
java版本是java8+
从官网下载后(apache-activemq-5.16.5-bin.tar.gz)上传到centos的目录下(根据自己习惯选定目录或者按照要求选定目录)
/usr/local/
[root@myw~]# cd /usr/local
[root@myw local]# ls
apache-activemq-5.16.5-bin.tar.gz
[root@myw local]#
解压
[root@myw local]# tar -xvzf apache-activemq-5.16.5-bin.tar.gz
修改文件夹名字
[root@myw local]# mv apache-activemq-5.16.5 activemq
[root@myw local]# ls
activemq apache-activemq-5.16.5-bin.tar.gz
[root@myw local]#
[root@myw local]# cd activemq
[root@myw activemq]# ls
activemq-all-5.16.5.jar bin conf data docs examples lib LICENSE NOTICE README.txt webapps webapps-demo
[root@myw activemq]# cd bin
[root@myw bin]# ls
activemq activemq-diag activemq.jar env linux-x86-32 linux-x86-64 macosx wrapper.jar
[root@myw bin]# ./activemq start
INFO: Loading '/usr/local/activemq//bin/env'
INFO: Using java '/usr/local/jdk18/bin/java'
INFO: Starting - inspect logfiles specified in logging.properties and log4j.properties to get details
INFO: pidfile created : '/usr/local/activemq//data/activemq.pid' (pid '29548')
[root@myw bin]# netstat -lnp|grep java
tcp6 0 0 :::1883 :::* LISTEN 29548/java
tcp6 0 0 127.0.0.1:8161 :::* LISTEN 29548/java
tcp6 0 0 :::36453 :::* LISTEN 29548/java
tcp6 0 0 :::5672 :::* LISTEN 29548/java
tcp6 0 0 :::61613 :::* LISTEN 29548/java
tcp6 0 0 :::61614 :::* LISTEN 29548/java
tcp6 0 0 :::61616 :::* LISTEN 29548/java
[root@myw bin]#
在云服务器上启动之后,安全组规则和防火墙也放开8161端口之后,还需要更改一个配置才能实现浏览器访问界面(127.0.0.1改成0.0.0.0)
配置文件
conf/jetty.xml
原配置信息
<bean id="jettyPort" class="org.apache.activemq.web.WebConsolePort" init-method="start">
<!-- the default port number for the web console -->
<property name="host" value="127.0.0.1"/>
<property name="port" value="8161"/>
</bean>
修改后的配置信息
<bean id="jettyPort" class="org.apache.activemq.web.WebConsolePort" init-method="start">
<!-- the default port number for the web console -->
<property name="host" value="0.0.0.0"/>
<property name="port" value="8161"/>
</bean>
重启后浏览器访问具体的IP+端口
http://XXX.XXX.XXX.XXX:8161
http://XXX.XXX.XXX.XXX:8161/index.html
登录账号和密码都是admin
点击Manage ActiveMQ broker便可以进入
记录一下常用指令
启动服务
./activemq start
查看状态
./activemq status
停止服务
./activemq stop
重启服务
./activemq restart
[root@myw ~]# cd /usr/local/activemq/bin
[root@myw bin]# ./activemq start
INFO: Loading '/usr/local/activemq//bin/env'
INFO: Using java '/usr/local/jdk18/bin/java'
INFO: Process with pid '29873' is already running
[root@myw bin]# ./activemq status
INFO: Loading '/usr/local/activemq//bin/env'
INFO: Using java '/usr/local/jdk18/bin/java'
ActiveMQ is running (pid '29873')
[root@myw bin]# ./activemq restart
INFO: Loading '/usr/local/activemq//bin/env'
INFO: Using java '/usr/local/jdk18/bin/java'
INFO: Loading '/usr/local/activemq//bin/env'
INFO: Using java '/usr/local/jdk18/bin/java'
INFO: Waiting at least 30 seconds for regular process termination of pid '29873' :
Java Runtime: Oracle Corporation 1.8.0_144 /usr/local/jdk18/jre
Heap sizes: current=62976k free=61992k max=932352k
JVM args: -Xms64M -Xmx1G -Djava.util.logging.config.file=logging.properties -Djava.security.auth.login.config=/usr/local/activemq//conf/login.config -Dactivemq.classpath=/usr/local/activemq//conf:/usr/local/activemq//../lib/: -Dactivemq.home=/usr/local/activemq/ -Dactivemq.base=/usr/local/activemq/ -Dactivemq.conf=/usr/local/activemq//conf -Dactivemq.data=/usr/local/activemq//data
Extensions classpath:
[/usr/local/activemq/lib,/usr/local/activemq/lib/camel,/usr/local/activemq/lib/optional,/usr/local/activemq/lib/web,/usr/local/activemq/lib/extra]
ACTIVEMQ_HOME: /usr/local/activemq
ACTIVEMQ_BASE: /usr/local/activemq
ACTIVEMQ_CONF: /usr/local/activemq/conf
ACTIVEMQ_DATA: /usr/local/activemq/data
Connecting to pid: 29873
Stopping broker: localhost
.. FINISHED
INFO: Loading '/usr/local/activemq//bin/env'
INFO: Using java '/usr/local/jdk18/bin/java'
INFO: Starting - inspect logfiles specified in logging.properties and log4j.properties to get details
INFO: pidfile created : '/usr/local/activemq//data/activemq.pid' (pid '30248')
INFO: Loading '/usr/local/activemq//bin/env'
INFO: Using java '/usr/local/jdk18/bin/java'
ActiveMQ is running (pid '30248')
[root@myw bin]#
配置开机启动,我这里使用的方式是创建服务
在/usr/local/activemq/bin/目录下有一个env文件
原来文件内容有一个JAVA_HOME
# location of the pidfile
# ACTIVEMQ_PIDFILE="$ACTIVEMQ_DATA/activemq.pid"
# Location of the java installation
# Specify the location of your java installation using JAVA_HOME, or specify the
# path to the "java" binary using JAVACMD
# (set JAVACMD to "auto" for automatic detection)
#JAVA_HOME=""
JAVACMD="auto"
配置成java环境的地址(/usr/local/jdk18),我的环境是这样的
# Location of the java installation
# Specify the location of your java installation using JAVA_HOME, or specify the
# path to the "java" binary using JAVACMD
# (set JAVACMD to "auto" for automatic detection)
JAVA_HOME="/usr/local/jdk18"
JAVACMD="auto"
然后创建服务文件(activemq.service)
[Unit]
Description=nginx-black web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/activemq/bin/activemq start
ExecReload=/usr/local/activemq/bin/activemq restart
ExecStop=/usr/local/activemq/bin/activemq stop
[Install]
WantedBy=multi-user.target
准备好的文件activemq.service 放入/etc/systemd/system/里面后刷新加载
/usr/lib/systemd/system/
使用
[root@myw bin]# systemctl daemon-reload
[root@myw bin]# systemctl start activemq.service
[root@myw bin]# netstat -lnp|grep java
tcp6 0 0 :::1883 :::* LISTEN 31018/java
tcp6 0 0 :::8161 :::* LISTEN 31018/java
tcp6 0 0 :::33732 :::* LISTEN 31018/java
tcp6 0 0 :::5672 :::* LISTEN 31018/java
tcp6 0 0 :::61613 :::* LISTEN 31018/java
tcp6 0 0 :::61614 :::* LISTEN 31018/java
tcp6 0 0 :::61616 :::* LISTEN 31018/java
[root@myw bin]# systemctl stop activemq.service
[root@myw bin]# netstat -lnp|grep java
[root@myw bin]# systemctl restart activemq.service
[root@myw bin]# netstat -lnp|grep java
tcp6 0 0 :::1883 :::* LISTEN 31297/java
tcp6 0 0 :::5672 :::* LISTEN 31297/java
tcp6 0 0 :::61613 :::* LISTEN 31297/java
tcp6 0 0 :::61614 :::* LISTEN 31297/java
tcp6 0 0 :::40975 :::* LISTEN 31297/java
tcp6 0 0 :::61616 :::* LISTEN 31297/java
[root@myw bin]# systemctl enable activemq.service
Created symlink from /etc/systemd/system/multi-user.target.wants/activemq.service to /usr/lib/systemd/system/activemq.service.
[root@myw bin]#
// 重新加载
systemctl daemon-reload
// 启动
systemctl start activemq.service
// 重启
systemctl restart activemq.service
// 停止
systemctl stop activemq.service
// 查看启动状态
systemctl status activemq.service
// 加入开机启动
systemctl enable activemq.service
// 取消开机启动
systemctl disable activemq.service