147 lines
2.9 KiB
Markdown
147 lines
2.9 KiB
Markdown
# 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 wget`
|
||
- 切换当前用户 shell 到 `/bin/zsh`
|
||
- 安装 oh-my-zsh
|
||
- 安装 nvm,并执行 `nvm install --lts`
|
||
- 安装 `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"
|
||
```
|
||
|
||
默认配置:
|
||
|
||
- `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`
|
||
|
||
只初始化配置文件:
|
||
|
||
```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
|
||
```
|
||
|
||
实际写入 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 安装。
|