nexus2设置开机自启

想把整套环境,所有的服务都在服务器上搭一遍,但是有时家里会跳闸,服务就会停掉,所以安装了一下开启自启。

脚本文件:

cat > /lib/systemd/system/nexus.service <<-EOF
[Unit]
Description=nexus
After=network.target
[Service]
Type=forking
Environment=RUN_AS_USER=root
Environment=PATH=/root/.tiup/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/lib/jvm/java-1.8.0-openjdk/bin:/wgr/maven/apache-maven-3.6.2/bin:/root/bin:/usr/lib/jvm/java-1.8.0-openjdk/bin:/wgr/maven/apache-maven-3.6.2/bin:/usr/lib/jvm/java-1.8.0-openjdk/bin:/wgr/maven/apache-maven-3.6.2/bin
ExecStart=/wgr/nexus-2.14.15-01/bin/nexus start
ExecReload=/wgr/nexus-2.14.15-01/bin/nexus restart
ExecStop=/wgr/nexus-2.14.15-01/bin/nexus stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF

进行测试:

[root@cicd bin]# systemctl start nexus
[root@cicd bin]# systemctl status nexus
● nexus.service - nexus
   Loaded: loaded (/usr/lib/systemd/system/nexus.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2020-07-21 04:58:10 EDT; 7s ago
  Process: 16095 ExecStart=/wgr/nexus-2.14.15-01/bin/nexus start (code=exited, status=0/SUCCESS)
 Main PID: 16135 (wrapper)
    Tasks: 25
   Memory: 189.7M
   CGroup: /system.slice/nexus.service
           ├─16135 /wgr/nexus-2.14.15-01/bin/../bin/jsw/linux-x86-64/wrapper /wgr/nexus-2.14.15-01/bin/../bin/jsw/conf/wrapper.conf wrapper.sysl...
           └─16137 java -Djava.io.tmpdir=./tmp -Djava.net.preferIPv4Stack=true -Dcom.sun.jndi.ldap.connect.pool.protocol=plain ssl -Xms256m -Xmx...

Jul 21 04:58:10 cicd systemd[1]: Starting nexus...
Jul 21 04:58:10 cicd nexus[16095]: ****************************************
Jul 21 04:58:10 cicd nexus[16095]: WARNING - NOT RECOMMENDED TO RUN AS ROOT
Jul 21 04:58:10 cicd nexus[16095]: ****************************************
Jul 21 04:58:10 cicd nexus[16095]: Starting Nexus OSS...
Jul 21 04:58:10 cicd nexus[16095]: Started Nexus OSS.
Jul 21 04:58:10 cicd systemd[1]: Started nexus.
[root@cicd bin]# systemctl stop nexus
[root@cicd bin]# systemctl status nexus
● nexus.service - nexus
   Loaded: loaded (/usr/lib/systemd/system/nexus.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

Jul 21 04:58:10 cicd systemd[1]: Started nexus.
Jul 21 04:58:25 cicd systemd[1]: Stopping nexus...
Jul 21 04:58:26 cicd nexus[16192]: ****************************************
Jul 21 04:58:26 cicd nexus[16192]: WARNING - NOT RECOMMENDED TO RUN AS ROOT
Jul 21 04:58:26 cicd nexus[16192]: ****************************************
Jul 21 04:58:26 cicd nexus[16192]: Stopping Nexus OSS...
Jul 21 04:58:32 cicd nexus[16192]: Waiting for Nexus OSS to exit...
Jul 21 04:58:38 cicd nexus[16192]: Waiting for Nexus OSS to exit...
Jul 21 04:58:44 cicd nexus[16192]: Stopped Nexus OSS.
Jul 21 04:58:44 cicd systemd[1]: Stopped nexus.
[root@cicd bin]# systemctl enable nexus
Created symlink from /etc/systemd/system/multi-user.target.wants/nexus.service to /usr/lib/systemd/system/nexus.service.
[root@cicd bin]# systemctl start nexus
[root@cicd bin]# systemctl status nexus
● nexus.service - nexus
   Loaded: loaded (/usr/lib/systemd/system/nexus.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2020-07-21 05:00:09 EDT; 42s ago
  Process: 16798 ExecStart=/wgr/nexus-2.14.15-01/bin/nexus start (code=exited, status=0/SUCCESS)
 Main PID: 16838 (wrapper)
    Tasks: 48
   Memory: 591.6M
   CGroup: /system.slice/nexus.service
           ├─16838 /wgr/nexus-2.14.15-01/bin/../bin/jsw/linux-x86-64/wrapper /wgr/nexus-2.14.15-01/bin/../bin/jsw/conf/wrapper.conf wrapper.sysl...
           └─16841 java -Djava.io.tmpdir=./tmp -Djava.net.preferIPv4Stack=true -Dcom.sun.jndi.ldap.connect.pool.protocol=plain ssl -Xms256m -Xmx...

Jul 21 05:00:08 cicd systemd[1]: Starting nexus...
Jul 21 05:00:08 cicd nexus[16798]: ****************************************
Jul 21 05:00:08 cicd nexus[16798]: WARNING - NOT RECOMMENDED TO RUN AS ROOT
Jul 21 05:00:08 cicd nexus[16798]: ****************************************
Jul 21 05:00:08 cicd nexus[16798]: Starting Nexus OSS...
Jul 21 05:00:09 cicd nexus[16798]: Started Nexus OSS.
Jul 21 05:00:09 cicd systemd[1]: Started nexus.
[root@cicd bin]# lsof -i:8081
COMMAND   PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
java    16841 root  460u  IPv4 12896197      0t0  TCP *:tproxy (LISTEN)
java    16841 root  479u  IPv4 12897633      0t0  TCP cicd:tproxy->192.168.1.249:54961 (ESTABLISHED)
java    16841 root  480u  IPv4 12897656      0t0  TCP cicd:tproxy->192.168.1.249:54962 (ESTABLISHED)
java    16841 root  481u  IPv4 12897657      0t0  TCP cicd:tproxy->192.168.1.249:54964 (ESTABLISHED)
java    16841 root  482u  IPv4 12897660      0t0  TCP cicd:tproxy->192.168.1.249:54966 (ESTABLISHED)
[root@cicd bin]#

posted @ 2020-07-21 17:11  天宇轩-王  阅读(383)  评论(0编辑  收藏  举报