2.7 KiB
2.7 KiB
server-config-cli
一个用于初始化服务器环境的 Node.js CLI,覆盖 zsh、openssh-server 和 frp client 配置。frp 支持通过命令追加端口穿透配置。
安装和本地使用
npm link
server-config --help
也可以不 link,直接在项目目录执行:
node bin/server-config.js --help
建议先用 --dry-run 看要执行的命令:
server-config zsh install --dry-run
server-config ssh install --dry-run
server-config frp install --token "$FRP_TOKEN" --dry-run
zsh
server-config zsh install
会执行:
apt update && apt upgrade- 安装
zsh git curl - 切换当前用户 shell 到
/bin/zsh - 安装 oh-my-zsh
- 安装
zsh-autosuggestions和zsh-syntax-highlighting - 更新
~/.zshrc的插件列表为git zsh-autosuggestions zsh-syntax-highlighting
安装完成后重新登录 shell,或手动执行:
source ~/.zshrc
ssh
server-config ssh install
会安装 openssh-server,并执行 systemctl enable --now ssh。
frp
不要把 frp token 写死到仓库。使用环境变量或命令参数传入:
export FRP_TOKEN="your-token"
server-config frp install --token "$FRP_TOKEN"
默认配置:
server_addr = "81.70.134.9"server_port = 15443tls_enable = falsetcp_mux = truelog_file = "/var/log/frpc.log"log_level = "info"log_max_days = 7- frp 版本:
0.58.1 - 安装目录:
/opt/frp/frp_0.58.1_linux_amd64 - systemd 服务:
frpc
只初始化配置文件:
server-config frp init --token "$FRP_TOKEN"
如果配置文件已经存在,默认不会覆盖。需要覆盖时加:
server-config frp init --token "$FRP_TOKEN" --force
增加端口穿透
SSH 示例,本机 ssh 监听 22,远端暴露 17227:
server-config frp add ssh --local-port 22 --remote-port 17227 --restart
MySQL 示例:
server-config frp add mysql --local-port 3306 --remote-port 33061 --restart
如果本地服务不在 127.0.0.1,可以指定:
server-config frp add web --local-ip 0.0.0.0 --local-port 8080 --remote-port 18080 --restart
查看当前代理:
server-config frp list
删除代理:
server-config frp remove mysql --restart
重启 frpc:
server-config frp restart
自定义路径
server-config frp install \
--token "$FRP_TOKEN" \
--install-dir /home/scyk/frp_0.58.1_linux_amd64 \
--config /home/scyk/frp_0.58.1_linux_amd64/frpc.toml
一键初始化
server-config bootstrap --token "$FRP_TOKEN"
会依次执行 zsh、ssh 和 frp 安装。