目录
centos6
centos6中通过service管理程序,需要自定义脚本加入/etc/init.d这个目录中。
- 创建脚本activemq.sh
#! /bin/bash
#
# activemq Bring up/down activemq
#
# chkconfig: 112 63 37
# description: Activates/Deactivates all activemq interfaces configured to \
# start at boot time.
# Source function library.
. /etc/init.d/functions
start(){
/usr/local/activemq/bin/activemq start
}
stop(){
/usr/local/activemq/bin/activemq stop
}
case $1 in
start):
start
;;
stop):
stop
;;
restart):
stop
start
;;
*):
echo "using service activema start|stop|restart"
;;
esac
exit 0
- 将activemq.sh文件放入/etc/init.d目录中。
- 给activemq.sh赋予可执行权限:执行命令:chmod +x activemq.sh
- 一般情况下,根据需求只需要修改start和stop中的启动命令。
chmod +x activemq.sh
- 将脚本加入服务列表
chkconfig --add activemq
- 设置为开机自启动
chkconfig activemq on
- 查看加入是否成功
chkconfig --list activemq
- 通过service启动activemq
service activemq start
- 停止activemq
service activemq stop
- 重启
service activemq restart
centos7
centos7中采用Systemd来管理服务,与centos6有所区别。需要创建脚本放在/usr/lib/systemd/system/目录下。以下以配置activemq为例。
- 创建脚本
[Unit]
Description=ActiveMQ service
After=network.target
[Service]
Type=forking
ExecStart=/var/activemq/bin/activemq start
ExecStop=/var/activemq/bin/activemq stop
User=root
Group=root
Restart=always
RestartSec=9
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=activemq
根据系统实际安装目录修改一下两处
ExecStart=/var/activemq/bin/activemq start
ExecStop=/var/activemq/bin/activemq stop
- 设置activemq配置文件/var/activemq/bin/env中的JAVA_HOME
# 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/java/jdk1.8.0_181"
JAVACMD="auto"
- 通过systemctl管理activemq启停
* 启动activemq服务: ```systemctl start activemq```
* 查看服务状态: ```systemctl status activemq```
* 创建软件链接:``` ln -s /usr/lib/systemd/system/activemq.service /etc/systemd/system/multi-user.target.wants/activemq.service ```
* 开机自启: ```systemctl enable activemq```
* 检测是否开启成功(enable): ```systemctl list-unit-files |grep activemq ``` - 防火墙配置
添加并重启防火墙
```
firewall-cmd --zone=public --add-port=8161/tcp --permanent
firewall-cmd --zone=public --add-port=61616/tcp --permanent
systemctl restart firewalld.service
```
或者直接关闭防火墙: ```systemctl stop firewalld.service```
常用命令:
systemctl enable activemq.service #让某个服务开机启动(.service可以省略)
systemctl disable activemq.service #不让开机启动
systemctl status activemq.service #查看服务状态
systemctl start activemq.service #启动某个服务
systemctl stop activemq.service #停止某个服务
systemctl restart activemq.service #重启某个服务
systemctl is-enabled activemq#查看某个服务是否开机启动