CentOS7安装并配置ActiveMQ-Artemis环境包,MQTT环境搭建

嵇星海
2023-12-01

java环境搭建

1.查看云端目前支持安装的jdk版本

yum search java|grep jdk

2.选择版本后,安装(执行以下命令会自动安装jdk相关依赖

yum install -y java-1.8.0-openjdk

3.安装完成,验证是否安装成功

java -version

4.通过搜索java文件,查找jdk默认安装目录

find / -name 'java'

activeMQ

(默认用户名、密码:user、passwd)
安装包下载地址:
https://activemq.apache.org/components/artemis/download/
下载apache-artemis-2.19.0-bin.tar.gz
解压apache-artemis-2.19.0-bin.tar.gz

tar -zxvf apache-artemis-2.19.0-bin.tar.gz

进入目录

cd apache-artemis-2.19.0/bin

创建Broker实例

./artemis create mybroker

然后控制台会让我们填写默认用户名、密码、是否允许匿名登录
user passwd False

返回成功信息:
You can now start the broker by executing:
“/www/wwwroot/service/apache-artemis-2.19.0/bin/mybroker/bin/artemis” run
Or you can run the broker in the background using:
启动和停止实例
“/www/wwwroot/service/apache-artemis-2.19.0/bin/mybroker/bin/artemis-service” start
netstat -anpt
查看端口使用:

netstat -anpt

访问控制台
1)修改 mybroker/etc/Jolokia -access.xml,添加一条allow-origin的访问权限设置

<allow-origin>*://192.168.0.16*</allow-origin>

2)修改mybroker/etc/bootstrap.xml,localhost改为服务器的ip

<web bind="http://192.168.0.16:8161" path="web">
<app url="activemq-branding" war="activemq-branding.war"/>
<app url="artemis-plugin" war="artemis-plugin.war"/>
<app url="console" war="console.war"/>
</web>

3)重启一下broker实例

"/www/wwwroot/service/apache-artemis-2.19.0/bin/mybroker/bin/artemis-service" restart

最后访问:
http://192.168.0.16:8161/console 来使用控制台.
客户端通信:
ip:192.168.0.16
port:1883


1.设置开机自启动(centos7)

创建artemis.service文件,内容如下

[Unit]
Description=artemis mqtt
After=network.target

[Service]
Type=forking
ExecStart=/www/wwwroot/service/apache-artemis-2.19.0/bin/mybroker/bin/artemis-service restart
ExecReload=/www/wwwroot/service/apache-artemis-2.19.0/bin/mybroker/bin/artemis-service restart
ExecStop=/www/wwwroot/service/apache-artemis-2.19.0/bin/mybroker/bin/artemis-service stop

[Install]
WantedBy=multi-user.target

将文件放置到:/usr/lib/systemd/system中,并修改权限为754
设置开机自启动:

systemctl enable artemis.service

设置开机不启动:

systemctl disable artemis.service

检查服务状态:

systemctl status artemis.service

启动某服务:

systemctl start artemis.service
 类似资料: