Featured image of post 如何在vyos上启用api服务

如何在vyos上启用api服务

如何在VyOS上启用api服务

最近,我写了些shell脚本来自动探测网络状态,并通过脚本来更改vyos的设置,但是如果意外断电或者强制重启会导致VyOS的配置文件丢失,非常的麻烦和不稳定。 如何解决这个问题呢?为什么不实施VyOS的API呢?

在VyOS本机上启用api服务

socket模式启用api服务

1
set service https api socket 

curl测试

1
curl --unix-socket /run/api.sock -X POST -Fkey=qwerty -Fdata='{"op": "showConfig", "path": []}' http://localhost/retrieve

使用let‘s encryption的ssl启动VyOS API 服务

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/vbash
source /opt/vyatta/etc/functions/script-template
configure

# 定义变量
ID="my_id"
APIKEY="12345"
APIPORT="1234"
VHOST="myvps"
FULL_FQDN="xxx.xxx.xxx"
LISTEN_ADDRESS="xxx.xxx.xxx.xxx"
EMAIL="my@emal.com"

set service https api key id $ID key $APIKEY
set service https certificates certbot domain-name $FULL_FQDN
set service https certificates certbot email $EMAIL
set service https api strict
set service https virtual-host $VHOST listen-address $LISTEN_ADDRESS
set service https virtual-host $VHOST listen-port $APIPORT
set service https virtual-host $VHOST server-name $FULL_FQDN
commit
save
exit
Licensed under CC BY-NC-SA 4.0
最后更新于 Nov 08, 2024 12:49 UTC
Built with Hugo
主题 StackJimmy 设计