mirror of https://github.com/ehang-io/nps
change md and register npc as a service
parent
31af2bb6db
commit
eab5708b33
|
@ -53,6 +53,8 @@ nps是一款轻量级、高性能、功能强大的**内网穿透**代理服务
|
||||||
- 点击web管理中客户端前的+号,复制启动命令
|
- 点击web管理中客户端前的+号,复制启动命令
|
||||||
- 执行启动命令,linux直接执行即可,windows将./npc换成npc.exe用cmd执行
|
- 执行启动命令,linux直接执行即可,windows将./npc换成npc.exe用cmd执行
|
||||||
|
|
||||||
|
如果需要注册到系统服务可查看[注册到系统服务](https://cnlh.github.io/nps/#/use?id=注册到系统服务)
|
||||||
|
|
||||||
### 配置
|
### 配置
|
||||||
- 客户端连接后,在web中配置对应穿透服务即可
|
- 客户端连接后,在web中配置对应穿透服务即可
|
||||||
- 更多高级用法见[完整文档](https://cnlh.github.io/nps/)
|
- 更多高级用法见[完整文档](https://cnlh.github.io/nps/)
|
||||||
|
|
|
@ -32,8 +32,7 @@ var (
|
||||||
target = flag.String("target", "", "p2p target")
|
target = flag.String("target", "", "p2p target")
|
||||||
localType = flag.String("local_type", "p2p", "p2p target")
|
localType = flag.String("local_type", "p2p", "p2p target")
|
||||||
logPath = flag.String("log_path", "", "npc log path")
|
logPath = flag.String("log_path", "", "npc log path")
|
||||||
debug = flag.Bool("debug", false, "npc debug")
|
debug = flag.Bool("debug", true, "npc debug")
|
||||||
srv = flag.String("service", "", "service option")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -69,10 +68,15 @@ func main() {
|
||||||
"After=network-online.target syslog.target"}
|
"After=network-online.target syslog.target"}
|
||||||
}
|
}
|
||||||
for _, v := range os.Args[1:] {
|
for _, v := range os.Args[1:] {
|
||||||
if !strings.Contains(v, "-service=") {
|
switch v {
|
||||||
|
case "install", "start", "stop", "uninstall", "restart":
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !strings.Contains(v, "-service=") && !strings.Contains(v, "-debug=") {
|
||||||
svcConfig.Arguments = append(svcConfig.Arguments, v)
|
svcConfig.Arguments = append(svcConfig.Arguments, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
svcConfig.Arguments = append(svcConfig.Arguments, "-debug=false")
|
||||||
prg := &npc{
|
prg := &npc{
|
||||||
exit: make(chan struct{}),
|
exit: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
@ -102,19 +106,17 @@ func main() {
|
||||||
}
|
}
|
||||||
fmt.Printf("nat type: %s \npublic address: %s\n", nat.String(), host.String())
|
fmt.Printf("nat type: %s \npublic address: %s\n", nat.String(), host.String())
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
case "install", "start", "stop", "uninstall", "restart":
|
||||||
|
if os.Args[1] == "install" {
|
||||||
|
install.InstallNpc()
|
||||||
|
}
|
||||||
|
err := service.Control(s, os.Args[1])
|
||||||
|
if err != nil {
|
||||||
|
logs.Error("Valid actions: %q\n", service.ControlAction, err.Error())
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if *srv != "" {
|
|
||||||
if *srv == "install" {
|
|
||||||
install.InstallNpc()
|
|
||||||
}
|
|
||||||
err := service.Control(s, *srv)
|
|
||||||
if err != nil {
|
|
||||||
logs.Error("Valid actions: %q\n", service.ControlAction, err.Error())
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
s.Run()
|
s.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
- 点击web管理中客户端前的+号,复制启动命令
|
- 点击web管理中客户端前的+号,复制启动命令
|
||||||
- 执行启动命令,linux直接执行即可,windows将./npc换成npc.exe用cmd执行
|
- 执行启动命令,linux直接执行即可,windows将./npc换成npc.exe用cmd执行
|
||||||
|
|
||||||
|
如果需要注册到系统服务可查看[注册到系统服务](/use?id=注册到系统服务)
|
||||||
|
|
||||||
## 配置
|
## 配置
|
||||||
- 客户端连接后,在web中配置对应穿透服务即可
|
- 客户端连接后,在web中配置对应穿透服务即可
|
||||||
- 可以查看[使用示例](/example)
|
- 可以查看[使用示例](/example)
|
||||||
|
|
53
docs/use.md
53
docs/use.md
|
@ -2,34 +2,43 @@
|
||||||
## 无配置文件模式
|
## 无配置文件模式
|
||||||
此模式的各种配置在服务端web管理中完成,客户端除运行一条命令外无需任何其他设置
|
此模式的各种配置在服务端web管理中完成,客户端除运行一条命令外无需任何其他设置
|
||||||
```
|
```
|
||||||
./npc -server=ip:port -vkey=web界面中显示的密钥
|
./npc -debug=true -server=ip:port -vkey=web界面中显示的密钥
|
||||||
```
|
```
|
||||||
|
## 注册到系统服务
|
||||||
|
对于linux、darwin
|
||||||
|
- 注册:`sudo ./npc install 其他参数(例如-server=xx -vkey=xx或者-config=xxx)`
|
||||||
|
- 启动:`sudo ./npc start`
|
||||||
|
- 停止:`sudo ./npc stop`
|
||||||
|
- 如果需要更换命令内容需要先卸载`./npc -service=uninstall`,再重新注册
|
||||||
|
|
||||||
|
对于windows,使用管理员身份运行cmd
|
||||||
|
|
||||||
|
- 注册:`npc.exe install 其他参数(例如-server=xx -vkey=xx或者-config=xxx)`
|
||||||
|
- 启动:`npc.exe start`
|
||||||
|
- 停止:`npc.exe stop`
|
||||||
|
- 如果需要更换命令内容需要先卸载`npc.exe -service=uninstall`,再重新注册
|
||||||
|
|
||||||
|
## 客户端更新
|
||||||
|
首先进入到对于的客户端二进制文件目录
|
||||||
|
|
||||||
|
请首先执行`sudo ./npc stop`或者`nps.exe stop`停止运行,然后
|
||||||
|
|
||||||
|
对于linux
|
||||||
|
```shell
|
||||||
|
sudo ./npc-update update
|
||||||
|
```
|
||||||
|
对于windows
|
||||||
|
```shell
|
||||||
|
npc-update.exe update
|
||||||
|
```
|
||||||
|
|
||||||
|
更新完成后,执行执行`sudo nps start`或者`nps.exe start`重新运行即可完成升级
|
||||||
|
|
||||||
## 配置文件模式
|
## 配置文件模式
|
||||||
此模式使用nps的公钥或者客户端私钥验证,各种配置在客户端完成,同时服务端web也可以进行管理
|
此模式使用nps的公钥或者客户端私钥验证,各种配置在客户端完成,同时服务端web也可以进行管理
|
||||||
```
|
```
|
||||||
./npc -config=npc配置文件路径
|
./npc -config=npc配置文件路径
|
||||||
```
|
```
|
||||||
可自行添加systemd service,例如:`npc.service`
|
|
||||||
```
|
|
||||||
[Unit]
|
|
||||||
Description=npc - convenient proxy server client
|
|
||||||
Documentation=https://github.com/cnlh/nps/
|
|
||||||
After=network-online.target remote-fs.target nss-lookup.target
|
|
||||||
Wants=network-online.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=simple
|
|
||||||
KillMode=process
|
|
||||||
Restart=always
|
|
||||||
RestartSec=15s
|
|
||||||
StandardOutput=append:/var/log/nps/npc.log
|
|
||||||
ExecStartPre=/bin/echo 'Starting npc'
|
|
||||||
ExecStopPost=/bin/echo 'Stopping npc'
|
|
||||||
ExecStart=/absolutely path to/npc -server=ip:port -vkey=web界面中显示的密钥
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
||||||
```
|
|
||||||
## 配置文件说明
|
## 配置文件说明
|
||||||
[示例配置文件](https://github.com/cnlh/nps/tree/master/conf/npc.conf)
|
[示例配置文件](https://github.com/cnlh/nps/tree/master/conf/npc.conf)
|
||||||
#### 全局配置
|
#### 全局配置
|
||||||
|
|
Loading…
Reference in New Issue