1.安装jdk;
rpm -ivh jdk-8u201-linux-x64.rpm
2.配置jdk路径
打开/etc/profile
增加以下内容:
export JAVA_HOME=/usr/java/jdk1.8.0_201
export JAVA_BIN=/usr/java/jdk1.8.0_201/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH
3.更新配置
source /etc/profile
4.编写启动 脚本
启动脚本:start.sh
#!/bin/sh
nohup java -jar /home/test/auto-test.jar >test.log 2>&1&
echo $! > /home/test/test.pid
停止脚本:stop.sh
#!/bin/sh
PID=$(cat /home/test/test.pid)
kill -9 $PID
授予脚本权限
chmod +x start.sh
chmod +x stop.sh
5.编写服务脚本
vim /usr/lib/systemd/system/autotest.service
#!/bin/sh
[Unit]
Description=antotest
After=network.target
[Service]
Type=forking
ExecStart=/home/test/start.sh
ExecStop=/home/test/stop.sh
PrivateTmp=true
[Install]
WantedBy=multi-user.target
6.设置服务启动
systemctl enable auto.service #开机自启
systemctl disable auto.service #关闭开机自启
systemctl start auto.service #手动开启
systemctl stop auto.service #手动关闭
systemctl status auto.service #查看状态