This commit is contained in:
2026-04-15 13:58:22 +08:00
commit de93193279
7 changed files with 835 additions and 0 deletions

142
README.md Normal file
View File

@@ -0,0 +1,142 @@
# server-config-cli
一个用于初始化服务器环境的 Node.js CLI覆盖 zsh、openssh-server 和 frp client 配置。frp 支持通过命令追加端口穿透配置。
## 安装和本地使用
```bash
npm link
server-config --help
```
也可以不 link直接在项目目录执行
```bash
node bin/server-config.js --help
```
建议先用 `--dry-run` 看要执行的命令:
```bash
server-config zsh install --dry-run
server-config ssh install --dry-run
server-config frp install --token "$FRP_TOKEN" --dry-run
```
## zsh
```bash
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或手动执行
```bash
source ~/.zshrc
```
## ssh
```bash
server-config ssh install
```
会安装 `openssh-server`,并执行 `systemctl enable --now ssh`
## frp
不要把 frp token 写死到仓库。使用环境变量或命令参数传入:
```bash
export FRP_TOKEN="your-token"
server-config frp install --token "$FRP_TOKEN"
```
默认配置:
- `server_addr = "81.70.134.9"`
- `server_port = 15443`
- `tls_enable = false`
- `tcp_mux = true`
- `log_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`
只初始化配置文件:
```bash
server-config frp init --token "$FRP_TOKEN"
```
如果配置文件已经存在,默认不会覆盖。需要覆盖时加:
```bash
server-config frp init --token "$FRP_TOKEN" --force
```
### 增加端口穿透
SSH 示例,本机 ssh 监听 `22`,远端暴露 `17227`
```bash
server-config frp add ssh --local-port 22 --remote-port 17227 --restart
```
MySQL 示例:
```bash
server-config frp add mysql --local-port 3306 --remote-port 33061 --restart
```
如果本地服务不在 `127.0.0.1`,可以指定:
```bash
server-config frp add web --local-ip 0.0.0.0 --local-port 8080 --remote-port 18080 --restart
```
查看当前代理:
```bash
server-config frp list
```
删除代理:
```bash
server-config frp remove mysql --restart
```
重启 frpc
```bash
server-config frp restart
```
### 自定义路径
```bash
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
```
## 一键初始化
```bash
server-config bootstrap --token "$FRP_TOKEN"
```
会依次执行 zsh、ssh 和 frp 安装。