1、方式一,参考链接

一.创建shell服务脚本

  1. 创建脚本nexus,并将脚本文件放在/etc/init.d 服务启动目录
  1. vim /etc/init.d/nexus

nexus脚本文件内容

  1. #!/bin/bash
  2. #chkconfig:2345 20 90
  3. #description:nexus
  4. #processname:nexus
  5. export JAVA_HOME=/usr/local/java/jdk1.8.0_221-amd64(自行替换为jdk安装目录)
  6. # 下面所有/usr/local/soft/nexus-3.18.1/nexus(自行替换为jdk安装目录)
  7. case $1 in
  8. start) su root /usr/local/soft/nexus-3.18.1/nexus/bin/nexus start;;
  9. stop) su root /usr/local/soft/nexus-3.18.1/nexus/bin/nexus stop;;
  10. status) su root /usr/local/soft/nexus-3.18.1/nexus/bin/nexus status;;
  11. restart) su root /usr/local/soft/nexus-3.18.1/nexus/bin/nexus restart;;
  12. dump ) su root /usr/local/soft/nexus-3.18.1/nexus/bin/nexus dump ;;
  13. console ) su root /usr/local/soft/nexus-3.18.1/nexus/bin/nexus console ;;
  14. *) echo "require console | start | stop | restart | status | dump " ;;
  15. esac

二.配置权限

  1. chmod +x $NEXUS_HOME/bin/nexus
  2. chmod +x $NEXUS_HOME/nexus

三. 让chkconfig 管理脚本

  1. #添加服务
  2. chkconfig --add nexus
  3. #开机自启动
  4. chkconfig nexus on

四.启动服务

  1. service nexus start

2.方式二,参考链接
创建开机启动脚本

  1. vim /etc/systemd/system/nexus.service

内容

  1. [Unit]
  2. Description=nexus service
  3. After=network.target
  4. [Service]
  5. Type=forking
  6. LimitNOFILE=65536
  7. ExecStart=/usr/local/nexus-3.11.0-01/bin/nexus start
  8. ExecStop=/usr/local/nexus-3.11.0-01/bin/nexus stop
  9. Restart=on-abort
  10. [Install]
  11. WantedBy=multi-user.target

设置开机启动

  1. systemctl enable nexus

启动

  1. systemctl start nexus