1、方式一,参考链接
一.创建shell服务脚本
创建脚本nexus,并将脚本文件放在/etc/init.d 服务启动目录
vim /etc/init.d/nexus
nexus脚本文件内容
#!/bin/bash
#chkconfig:2345 20 90
#description:nexus
#processname:nexus
export JAVA_HOME=/usr/local/java/jdk1.8.0_221-amd64(自行替换为jdk安装目录)
# 下面所有/usr/local/soft/nexus-3.18.1/nexus(自行替换为jdk安装目录)
case $1 in
start) su root /usr/local/soft/nexus-3.18.1/nexus/bin/nexus start;;
stop) su root /usr/local/soft/nexus-3.18.1/nexus/bin/nexus stop;;
status) su root /usr/local/soft/nexus-3.18.1/nexus/bin/nexus status;;
restart) su root /usr/local/soft/nexus-3.18.1/nexus/bin/nexus restart;;
dump ) su root /usr/local/soft/nexus-3.18.1/nexus/bin/nexus dump ;;
console ) su root /usr/local/soft/nexus-3.18.1/nexus/bin/nexus console ;;
*) echo "require console | start | stop | restart | status | dump " ;;
esac
二.配置权限
chmod +x $NEXUS_HOME/bin/nexus
chmod +x $NEXUS_HOME/nexus
三. 让chkconfig 管理脚本
#添加服务
chkconfig --add nexus
#开机自启动
chkconfig nexus on
四.启动服务
service nexus start
2.方式二,参考链接
创建开机启动脚本
vim /etc/systemd/system/nexus.service
内容
[Unit]
Description=nexus service
After=network.target
[Service]
Type=forking
LimitNOFILE=65536
ExecStart=/usr/local/nexus-3.11.0-01/bin/nexus start
ExecStop=/usr/local/nexus-3.11.0-01/bin/nexus stop
Restart=on-abort
[Install]
WantedBy=multi-user.target
设置开机启动
systemctl enable nexus
启动
systemctl start nexus