- 因为 OpenPG 是端到端加密,服务器看不到任何数据包,所以使用我们部署的服务器没有任何隐私和安全问题。而且当前服务器剩余容量充裕,建议直接使用我们部署的服务器。不过,写一篇文章给有私有化部署服务器需要的朋友仍然很有必要。
- 如果你的网络内不存在任何 EasyNAT 设备,自己部署服务器对提高私有网络速度很有必要。
服务器不需要数据库,仅转发数据或处理节点间的协调工作,所以部署起来还是比较简单的。
仅需要配置认证部分, NAT 遍历部分和其他一些参数。
一行命令运行服务器
pgmap -c /etc/pgmap.yml
关于配置文件配置项含义及如何配置,请往下看。
认证
所有的网络节点需要与服务器建立 WebSocket
连接,用于传输控制数据和转发私有网路数据包,只有通过认证的节点才可以正常建立连接。
服务器接收一个 JSONSecret 对象(一个 JSON 文件)用于认证,所以客户端需要携带这个 JSONSecret 才可以正常加入网络。
对于 JSONSecret 的生成目前有 2 种方式:
- OpenID Connect
- 使用 secret-key 生成
相关配置项:
pgmap.yml
secret_key: fb58d680-4af2-4a18-8e22-639609d114d4
secret_rotation_period: 12h
secret_validity_period: 48h
oidc_providers:
- name: google
issuer: https://accounts.google.com
client_id: client_id_placeholder
client_secret: client_secret_placeholder
redirect_url: https://openpg.in/oidc/authorize/google
scopes:
- profile
- email
- name: linuxdo
auth_url: https://connect.linux.do/oauth2/authorize
token_url: https://connect.linux.do/oauth2/token
user_info_url: https://connect.linux.do/api/user
client_id: client_id_placeholder
client_secret: client_secret_placeholder
redirect_url: https://openpg.in/oidc/authorize/linuxdo
scopes: []
- secret-key 是一个不被别人支持的秘密字符串。
- secret_rotation_period 配置多久应该轮转密钥。secret_validity_period 配置生成的密钥有效期多久。这个 2 个参数配合可以控制密钥有效期和轮转,更安全。
- 关于 OIDC 部分,支持标准的 OpenID Connect 提供者如 google,和仅支持 OAuth2.0 的提供者 如 linuxdo。
NAT 部分
客户端会从服务器拿到 STUN 服务器列表用于诊断公有网络的类型。
相关配置项:
pgmap.yml
stuns:
- stun.miwifi.com:3478
- stunserver2024.stunprotocol.org:3478
- 106.13.249.54:3478
- 106.12.251.193:3478
- 106.12.251.31:3478
- 106.12.251.52:3478
服务器配置越多,越可靠,但也不能太多,影响性能。一般是 3-10 个。
其他配置项
pgmap.yml
listen: 127.0.0.1:9987
rate_limiter:
limit: 200000
burst: 512000
- listen 配置 http 服务器监听地址。
- rate_limiter 配置服务器限速参数。limit 配置每秒允许的字节数,burst 配置突发字节数。
使用一个 7 层代理包装 https/wss
pgmap 本身监听一个 tcp 端口用于提供 http 和 ws 服务,没有 tls 安全层,所以最佳实践是前端使用支持 tls 的 7 层代理器(如 caddy, nginx)
容器化部署
dockerhub 已经存在一个 linux/amd64 架构的镜像了 https://hub.docker.com/r/rkonfj/openpg
可以这样运行 pgmap :
docker run -d --net host -v $PWD/pgmap.yml:/etc/pgmap.yml rkonfj/openpg pgmap -c /etc/pgmap.yml
最后
感谢你耐心看完,有过有任何不清楚的地方,请评论区告诉我。 也可以加入
Telegram 群组:https://t.me/+-S5L6ZCBxlxkMTRl
或
QQ 群组:1039776116