CentOS7下将jar包注册成系统服务

准备工作

  • wget安装: yum install wget
  • JDK安装及配置:
    • 下载jdk安装包: wget http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jdk-8u161-linux-i586.rpm?AuthParam=1520234485_3d07d60224bb534eec62b4055d57ac72
    • 安装jdk: yum localinstall jdk-8u161-linux-i586.rpm, 安装目录为:/usr/java/jdk1.8.0_161
    • JAVA环境变量配置:
      • vi /root/.bash_profile
      • 新增export JAVA_HOME=/usr/java/jdk1.8.0_161
      • 使.bash_profile生效: source .bash_profile

注册Service

  • 上传jar
  • 进入/etc/systemd/system文件夹,新增auth-server.service文件:
[Unit]
Description=auth-server
After=syslog.target

[Service]
ExecStart=/usr/bin/java -jar /root/auth-server-201801230812.jar
Restart=always
RestartSec=1

[Install]
WantedBy=multi-user.target
  • systemctl enable auth-server.service
  • systemctl start auth-server
  • systemctl stop auth-server, systemctl status auth-server

你可能感兴趣的:(linux)