Systemd help document:
http://www.jinbuguo.com/systemd/systemd.exec.html
1. Install java
yum install java-1.8.0-openjdk* -y
2. Download the activeMQ binary installation package
官网地址: http://activemq.apache.org/
3. Unzip and install
tar -zxvf apache-activemq-5.15.12-bin.tar.gz
mv apache-activemq-5.15.12 /usr/local/
ln -s /usr/local/apache-activemq-5.15.12/ /usr/local/apache-activemq
4. Explain related catalog files and modifications
目录:
bin:服务启动相关的命令文件所在目录
conf:配置文件所在目录,任何配置文件修改后,都要重启ActiveMQ,否则不生效。
data:默认持久化文件所在目录(日志)
docs:里面放的是用户手册
examples:存放例子,包括配置文件,代码
lib:存放jar包
webapps:管理台的应用
activemq-all-5.15.12.jar:客户端连接包
conf目录下需要关注的文件:activemq.xml,jetty.xml,users.properties
activemq.xml:spring配置文件,配置的是activemq应用使用的默认对象组件,配置安全认证和持久化都在这个文件中。
jetty.xml:spring配置文件,activemq使用的是jetty提供http服务,该文件用于配置jetty服务器的默认对象组件。端口号等的配置在这个文件中。
groups.properties:用户组=用户1,用户2(多个用户中间用逗号隔开)
users.properties:用户名和密码修改的地方 格式为用户名=密码
jetty-realm.properties:定义可以访问Web的用户(console, demo, etc.)
查找java目录位置:whereis java
添加到activemq的env中.
JAVA_HOME="/usr/java/jdk1.8.0_191/bin/java"
JAVACMD="auto"
5. Create ActiveMQ systemd service
systemd reads configuration files from the directory /etc/systemd/system by default. However, most of the files stored in it are symbolic links, pointing to the directory /usr/lib/systemd/system/, and the real configuration files are placed in this directory.
vim activemq.service
添加如下内容:
[Unit] #启动顺序与依赖关系
Description=Apache ActiveMQ #当前服务的描述
After=network-online.target #表示如果network.target或sshd-keygen.service需要启动,那么sshd.service应该在它们后面启动.
[Service] #启动行为
Type=forking #启动类型
PIDFile=/usr/local/apache-activemq/data/activemq.pid #PID路径
ExecStart=/usr/local/apache-activemq/bin/activemq start #启动进程时执行的命令
ExecStop=/usr/local/apache-activemq/bin/activemq stop #停止服务时执行的命令
Restart=on-failure #重启方式
RestartSec=42s #systemd重启等待时间
User=root #用户
Group=root #组
tandardOutput=syslog #进程标准输出,表示日志服务,默认复制一份到journal
StandardError=syslog #和tandardOutput类似
SyslogIdentifier=activemq #日志标识符(activemq logs)
[Install]
WantedBy=multi-user.target
6. Reload and start, check the port
systemctl daemon-reload
systemctl enable activemq.service
systemctl start activemq.service
systemctl status activemq.service
[root@hopeking apache-activemq]# netstat -anput | grep 61616
tcp6 0 0 :::61616 :::* LISTEN 24705/java
[root@hopeking apache-activemq]# netstat -anput | grep 8161
tcp6 0 0 :::8161 :::* LISTEN 24705/java
Browser access: http://IP:8161/admin/
8161: WEB port
61616: communication port