Linux之npc内网穿透开机后台自启动
1、下载配置Linux版本npc
网址:Releases · ehang-io/nps · GitHub
2、npc自启动配置
(1)建立启动脚本编写--start.sh
#!/bin/bash
cd /home/nps/
echo 'pwd'|sudo -S nohup ./npc >log.log 2>&1 &
可将start.sh与npc服务放一起
[root@arcgis nps]# pwd
/home/nps/
[root@arcgis nps]# ls
conf log.log npc start.sh
(2)配置npc.service文件
vim /usr/lib/systemd/system/npc.service
注意ExecStart
路径是你自己本地的
[Unit]
Description=npc
After=network.target
[Service]
Type=forking
ExecStart=/home/nps//start.sh
Restart=always
RestartSec=5
PrivateTmp=true
[Install]
WantedBy=multi-user.target
(3)启动并测试
systemctl daemon-reload
systemctl enable npc #设置开机启动
systemctl start npc #开启服务
systemctl status npc #查看状态
[root@arcgis nps]# systemctl status npc
● npc.service - npc
Loaded: loaded (/usr/lib/systemd/system/npc.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2022-08-12 17:43:25 CST; 7min ago
Main PID: 15513 (sudo)
CGroup: /system.slice/npc.service
‣ 15513 sudo -S nohup ./npc
Aug 12 17:43:25 arcgis systemd[1]: Starting npc...
Aug 12 17:43:25 arcgis systemd[1]: Started npc.
Aug 12 17:43:25 arcgis sudo[15513]: root : TTY=unknown ; PWD=/home/np...pc
Hint: Some lines were ellipsized, use -l to show in full.
最后可以reboot测试,查看是否开机自启
如果启动失败,可以查看一下start.sh
是否有可执行权限
[root@arcgis nps]# ll
total 9732
drwxr-xr-x 2 root root 68 Aug 4 19:15 conf
-rw-r--r-- 1 root root 17157 Aug 12 17:40 log.log
-rwxr-xr-x 1 haixin 121 9940992 Apr 8 2021 npc
-rw-r--r-- 1 root root 74 Aug 12 17:37 start.sh
没有的话要记得加
[root@arcgis nps]# chmod +x start.sh
[root@arcgis nps]# ll
total 9716
drwxr-xr-x 2 root root 68 Aug 4 19:15 conf
-rw-r--r-- 1 root root 455 Aug 12 17:43 log.log
-rwxr-xr-x 1 haixin 121 9940992 Apr 8 2021 npc
-rwxr-xr-x 1 root root 74 Aug 12 17:37 start.sh