fix
This commit is contained in:
190
README.md
190
README.md
@@ -1,146 +1,114 @@
|
||||
# server-config-cli
|
||||
|
||||
一个用于初始化服务器环境的 Node.js CLI,覆盖 zsh、openssh-server 和 frp client 配置。frp 支持通过命令追加端口穿透配置。
|
||||
一个用 [Ink](https://github.com/vadimdemedes/ink) 写的交互式 TUI,用来初始化服务器:zsh + oh-my-zsh + nvm、openssh-server、frp 客户端及其端口穿透配置。
|
||||
|
||||
## 安装和本地使用
|
||||
启动后是菜单式界面,没有传统的子命令/flag —— 所有选项、token、端口都在 TUI 里输入。
|
||||
|
||||
## 安装
|
||||
|
||||
```bash
|
||||
npm link
|
||||
server-config --help
|
||||
npm install
|
||||
npm run build # 必须先打包,bin/server-config.js 会加载 dist/app.mjs
|
||||
npm link # 可选;之后可以直接 server-config 调起
|
||||
```
|
||||
|
||||
也可以不 link,直接在项目目录执行:
|
||||
也可以不 link,直接:
|
||||
|
||||
```bash
|
||||
node bin/server-config.js --help
|
||||
node bin/server-config.js
|
||||
```
|
||||
|
||||
建议先用 `--dry-run` 看要执行的命令:
|
||||
要求 Node ≥ 18(建议 20+),并且必须在真正的终端里运行(stdin 需要 TTY,否则 Ink 报 "Raw mode is not supported")。
|
||||
|
||||
```bash
|
||||
server-config zsh install --dry-run
|
||||
server-config ssh install --dry-run
|
||||
server-config frp install --token "$FRP_TOKEN" --dry-run
|
||||
## 启动后界面
|
||||
|
||||
```
|
||||
╭───────────────────────────────────────╮
|
||||
│ server-config zsh · ssh · frp client │
|
||||
╰───────────────────────────────────────╯
|
||||
|
||||
Choose an action:
|
||||
|
||||
❯ Install zsh + oh-my-zsh + nvm
|
||||
Install OpenSSH server
|
||||
FRP setup ▸
|
||||
Bootstrap (zsh + ssh + frp)
|
||||
Quit
|
||||
|
||||
↑↓ select · Enter confirm · q quit
|
||||
```
|
||||
|
||||
## zsh
|
||||
通用键位:
|
||||
|
||||
```bash
|
||||
server-config zsh install
|
||||
```
|
||||
- `↑` `↓` 移动光标,`Enter` 确认
|
||||
- `Tab` / `↓` 在表单字段间切换,`↑` 回上一项
|
||||
- `Esc` 返回上一屏(运行中除外)
|
||||
- 在主菜单按 `q` 退出
|
||||
|
||||
会执行:
|
||||
## 各动作做什么
|
||||
|
||||
- `apt update && apt upgrade`
|
||||
- 安装 `zsh git curl wget`
|
||||
- 切换当前用户 shell 到 `/bin/zsh`
|
||||
- 安装 oh-my-zsh
|
||||
- 安装 nvm,并执行 `nvm install --lts`
|
||||
- 安装 `zsh-autosuggestions` 和 `zsh-syntax-highlighting`
|
||||
- 更新 `~/.zshrc` 的插件列表为 `git zsh-autosuggestions zsh-syntax-highlighting`
|
||||
### Install zsh + oh-my-zsh + nvm
|
||||
|
||||
安装完成后重新登录 shell,或手动执行:
|
||||
会依次执行:
|
||||
|
||||
```bash
|
||||
source ~/.zshrc
|
||||
```
|
||||
- `apt update` + `apt upgrade -y`
|
||||
- 装 `zsh git curl wget`
|
||||
- `chsh -s /bin/zsh`
|
||||
- 从 gitee 镜像装 oh-my-zsh(`RUNZSH=no CHSH=no KEEP_ZSHRC=yes`)
|
||||
- 装 nvm(`v0.40.4`)并 `nvm install --lts`、`nvm alias default lts/*`
|
||||
- 安装 `zsh-autosuggestions` 和 `zsh-syntax-highlighting`(已存在则 `git pull`)
|
||||
- 把 `~/.zshrc` 的 `plugins=(...)` 改成 `git zsh-autosuggestions zsh-syntax-highlighting`
|
||||
|
||||
## ssh
|
||||
完成后请 `source ~/.zshrc` 或重开终端。
|
||||
|
||||
```bash
|
||||
server-config ssh install
|
||||
```
|
||||
### Install OpenSSH server
|
||||
|
||||
会安装 `openssh-server`,并执行 `systemctl enable --now ssh`。
|
||||
`apt install openssh-server -y` + `systemctl enable --now ssh`。
|
||||
|
||||
## frp
|
||||
### FRP setup
|
||||
|
||||
不要把 frp token 写死到仓库。使用环境变量或命令参数传入:
|
||||
进入子菜单:
|
||||
|
||||
```bash
|
||||
export FRP_TOKEN="your-token"
|
||||
server-config frp install --token "$FRP_TOKEN"
|
||||
```
|
||||
- **Install frp client + service** — 下载 `frp_0.58.1_linux_amd64.tar.gz`,解压、放到 `/opt/frp/frp_0.58.1_linux_amd64/`,写 `frpc.toml` 和 systemd unit,然后 `systemctl enable --now frpc`。需要输入 token,也可以通过 `FRP_TOKEN` 环境变量预填。
|
||||
- **Init / rewrite frpc.toml** — 仅重写配置(保留已有代理段)。
|
||||
- **Add proxy** — 表单式输入名字 / 类型 / local IP / local port / remote port,写入的实际 name 会带 8 位随机后缀(例如 `ssh-aaa12312`),避免重名。可选执行后重启 frpc。
|
||||
- **List / remove proxies** — 选中即生成删除计划,预览后确认执行。
|
||||
- **Restart frpc** — `systemctl restart frpc`。
|
||||
|
||||
默认配置:
|
||||
### Bootstrap
|
||||
|
||||
按顺序执行 zsh + ssh + frp 三套,token 走同一个输入。
|
||||
|
||||
## 计划预览和执行
|
||||
|
||||
任何会改系统的动作都会先停在 "Plan" 屏:列出每一步要做什么(命令或写文件),可以选 **Run now** 或 **Cancel**。
|
||||
|
||||
确认运行后进入实时日志屏:每一步显示状态图标(◐ 运行中 / ✓ 成功 / ✗ 失败),底部 12 行滚动展示子进程 stdout/stderr。任何一步失败立刻停止后续步骤。
|
||||
|
||||
## 默认值
|
||||
|
||||
- `serverAddr = "81.70.134.9"`
|
||||
- `serverPort = 15443`
|
||||
- `auth.token = "$FRP_TOKEN"`
|
||||
- `transport.tls.enable = false`
|
||||
- `transport.tcpMux = true`
|
||||
- `log.to = "/var/log/frpc.log"`
|
||||
- `log.level = "info"`
|
||||
- `log.maxDays = 7`
|
||||
- frp 版本:`0.58.1`
|
||||
- 安装目录:`/opt/frp/frp_0.58.1_linux_amd64`
|
||||
- systemd 服务:`frpc`
|
||||
- 安装目录:`/opt/frp/frp_<version>_linux_amd64`
|
||||
- 配置文件:`<install-dir>/frpc.toml`
|
||||
- 服务名:`frpc`
|
||||
- 默认服务端:`81.70.134.9:15443`
|
||||
- 日志:`/var/log/frpc.log`,level `info`,保留 7 天
|
||||
- `transport.tcpMux = true`,`transport.tls.enable = false`
|
||||
|
||||
只初始化配置文件:
|
||||
`serverAddr` / `serverPort` / `installDir` 在 FRP 配置表单里都可以改。如果要改更深的配置(log 路径、TLS 等),目前需要直接编辑 `src/lib/tasks.js` 里的 `buildGlobalsFromOptions`。
|
||||
|
||||
## 开发
|
||||
|
||||
```bash
|
||||
server-config frp init --token "$FRP_TOKEN"
|
||||
npm run build:watch # 文件变了自动 rebuild
|
||||
npm test # 跑 frp-config 解析/渲染的单元测试
|
||||
npm run check # 对所有手写 .js 做 node --check
|
||||
```
|
||||
|
||||
如果配置文件已经存在,默认不会覆盖。需要覆盖时加:
|
||||
代码分三层:
|
||||
|
||||
```bash
|
||||
server-config frp init --token "$FRP_TOKEN" --force
|
||||
```
|
||||
- `src/lib/` — 纯逻辑(CJS),没有 Ink/React 依赖:`frp-config.js` 解析渲染,`tasks.js` 输出计划,`runner.js` 执行并发事件。
|
||||
- `src/screens/` — Ink/React 组件,每个屏一个文件。
|
||||
- `src/app.jsx` — 入口 + screen stack。
|
||||
|
||||
### 增加端口穿透
|
||||
|
||||
SSH 示例,本机 ssh 监听 `22`,远端暴露 `17227`:
|
||||
|
||||
```bash
|
||||
server-config frp add ssh --local-port 22 --remote-port 17227 --restart
|
||||
```
|
||||
|
||||
实际写入 frp 的 `name` 会自动追加随机后缀,例如 `ssh-aaa12312`,避免与已有代理重名。删除代理时使用 `server-config frp list` 看到的完整名称。
|
||||
|
||||
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-aaa12312 --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 安装。
|
||||
esbuild 把 `src/app.jsx` 打到 `dist/app.mjs`(ESM 输出,因为 Ink 7 / yoga-layout 用了 top-level await)。
|
||||
|
||||
Reference in New Issue
Block a user