Files
ServerStack/docs/USAGE.md
T
condor 679e0b4184 init
2026-07-24 18:54:53 +08:00

212 lines
9.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ServerStack 脚本使用说明
> 适用版本:当前项目(重构 + 软件裁剪 + 仅支持 Debian 9-13 / Ubuntu 16-26)。
> 所有命令**必须以 root 身份**在目标 Linux 服务器上运行。
> 项目根目录约定为 `ServerStack/`,入口脚本都在 `bin/` 下,**请在该项目根目录执行**。
---
## 0. 通用说明
- **交互模式**:直接运行脚本,按菜单提示逐项选择。
- **无人值守(CLI)模式**:在脚本后加长选项,可跳过菜单直接安装。
- 安装日志:`runtime/install.log`
- 版本与路径配置:`config/versions.txt``config/options.conf`
- 若 SSH 端口非 22,安装脚本会提示并写入 `/etc/ssh/sshd_config`(可选防火墙 `--iptables`)。
---
## 1. 主安装 `bin/install.sh`
### 1.1 交互模式
```bash
cd ServerStack
bash bin/install.sh
```
菜单依次询问(可全部选 `n` 跳过某类):
| 步骤 | 选项 | 说明 |
|------|------|------|
| Web 服务器 | y/n | 是否安装 Web |
| Nginx | `1` 安装 / `2` 不安装 | 仅保留 Nginx(已裁剪 Apache/Tengine/OpenResty |
| 数据库 | y/n | 是否安装 DB |
| DB 版本 | `1` MySQL-8.0 / `2` MySQL-5.7 / `3` MariaDB-10.11 / `4` MariaDB-11.8 / `5` MariaDB-12.3 / `6` PostgreSQL-15.14 / `7` PostgreSQL-16.10 / `8` PostgreSQL-17.6 / `9` MongoDB | 9 选 1(默认 `2` |
| DB 安装方式 | `1` 二进制包 / `2` 源码编译 | 仅 MySQL/MariaDB 出现(默认 `1` |
| DB 密码 | 输入或回车用随机密码 | MySQL/MariaDB→rootPG→postgresMongo→root |
| PHP | y/n | 是否安装 PHP |
| PHP 版本 | `1` php-7.4 / `2` php-8.0 / `3` php-8.1 | 3 选 1(默认 `1` |
| OPcode 缓存 | y/n → `1` Zend OPcache / `2` APCu | |
| PHP 扩展 | 多选编号,如 `4 11 12` | 0 不装;可用 imagick/gmagick/fileinfo/imap/ldap/phalcon/yaf/redis/mongodb/swoole/xdebug 等 |
| Node.js | y/n | |
| Pure-FTPd | y/n | |
| phpMyAdmin | y/n | |
| redis-server | y/n | |
| iptables | y/n | 是否启用防火墙 |
### 1.2 无人值守(CLI)示例
```bash
# 安装 Nginx + MySQL-8.0(二进制) + PHP-8.1(OPcache) + redis,结束不重启
bash bin/install.sh --nginx_option 1 --db_option 1 --dbinstallmethod 1 \
--dbrootpwd 'YourDBpass123' --php_option 3 --phpcache_option 1 \
--php_extensions "fileinfo redis" --redis
# 只装 PostgreSQL-17.6,并启用防火墙、装完后重启
bash bin/install.sh --db_option 8 --dbrootpwd 'PgPass123' \
--iptables --reboot
```
常用 CLI 参数:
| 参数 | 取值 | 说明 |
|------|------|------|
| `--nginx_option` | `1`/`2` | 1 安装 Nginx2 不安装 |
| `--php_option` | `1`/`2`/`3` | php-7.4 / 8.0 / 8.1 |
| `--mphp_ver` | `74`/`80`/`81` | 多版本 PHP 共存(配合 `--mphp_addons` |
| `--mphp_addons` | 无值 | 为 mphp 版本安装附加组件 |
| `--phpcache_option` | 编号 | PHP OPcode 缓存选择 |
| `--php_extensions` | 扩展名列表 | 空格分隔,如 `imagick redis swoole` |
| `--db_option` | `1``9` | 见上表 |
| `--dbinstallmethod` | `1`/`2` | 1 二进制,2 源码 |
| `--dbrootpwd` | 字符串 | 数据库超级密码(同时用于 PG/Mongo) |
| `--pureftpd` | 无值 | 安装 Pure-FTPd |
| `--redis` | 无值 | 安装 Redis |
| `--phpmyadmin` | 无值 | 安装 phpMyAdmin |
| `--python` / `--nodejs` | 无值 | 安装 Python / Node.js |
| `--ssh_port` | 端口号 | 修改 SSH 端口 |
| `--iptables` | 无值 | 启用 iptables 防火墙 |
| `--reboot` | 无值 | 安装完成后重启 |
| `-h/--help` | 无值 | 查看帮助 |
---
## 2. 卸载 `bin/uninstall.sh`
```bash
bash bin/uninstall.sh --all # 卸载全部
bash bin/uninstall.sh --web # 仅卸载 Nginx
bash bin/uninstall.sh --mysql # 卸载 MySQL/MariaDB
bash bin/uninstall.sh --postgresql # 卸载 PostgreSQL
bash bin/uninstall.sh --mongodb # 卸载 MongoDB
bash bin/uninstall.sh --php # 卸载主 PHP
bash bin/uninstall.sh --mphp_ver 81 # 卸载某个多版本 PHP74/80/81
bash bin/uninstall.sh --allphp # 卸载所有 PHP
bash bin/uninstall.sh --phpcache # 卸载 PHP OPcode 缓存
bash bin/uninstall.sh --php_extensions redis # 卸载指定 PHP 扩展
bash bin/uninstall.sh -q # 静默模式
```
---
## 3. 升级 `bin/upgrade.sh`
```bash
bash bin/upgrade.sh --nginx [版本] # 升级 Nginx
bash bin/upgrade.sh --db [版本] # 升级 MySQL/MariaDB
bash bin/upgrade.sh --php [版本] # 升级 PHP
bash bin/upgrade.sh --redis [版本] # 升级 Redis
bash bin/upgrade.sh --phpmyadmin [版本]
bash bin/upgrade.sh --oneinstack # 升级 ServerStack 自身到最新
bash bin/upgrade.sh --acme.sh # 升级 acme.sh
bash bin/upgrade.sh -h
```
> 版本号省略时自动取官方最新稳定版。
---
## 4. 虚拟主机 `bin/vhost.sh`
```bash
bash bin/vhost.sh --add # 交互式新增站点(含 SSL 选项)
bash bin/vhost.sh --list # 列出所有虚拟主机
bash bin/vhost.sh --delete # 删除虚拟主机
bash bin/vhost.sh --mphp_ver 81 # 指定多版本 PHP74/80/81
bash bin/vhost.sh --proxy # 反向代理模式
bash bin/vhost.sh --httponly # 仅 HTTP
bash bin/vhost.sh --selfsigned # 自签名 SSL
bash bin/vhost.sh --letsencrypt # Let's Encrypt 免费证书
bash bin/vhost.sh --dnsapi # 用 DNS API 自动签发证书
```
新增站点时会提示:域名、根目录、是否开启 rewrite(内置 discuz/wordpress/typecho/thinkphp 等模板)、PHP 版本、SSL 方式。
---
## 5. 扩展/安全组件 `bin/addons.sh`
```bash
bash bin/addons.sh --install --composer # 安装 Composer
bash bin/addons.sh --install --fail2ban # 安装 Fail2banSSH 防暴破)
bash bin/addons.sh --install --ngx_lua_waf # 安装 Nginx Lua WAF
bash bin/addons.sh --install --python # 安装 Python
bash bin/addons.sh --uninstall --composer # 卸载对应组件
bash bin/addons.sh -h
```
---
## 6. 备份 `bin/backup_setup.sh` + `bin/backup.sh`
### 6.1 配置备份目标 `backup_setup.sh`
```bash
bash bin/backup_setup.sh
```
交互选择备份目的地(1 本机 / 2 远程主机 / 3 阿里云 OSS / 4 腾讯云 COS / 5 又拍云 / 6 七牛 / 7 AWS S3 / 8 Dropbox),并按提示输入对应凭据(均交互输入,不写入脚本)。
设置会生成 `config_backup.txt`(含远程主机 IP/用户/口令——**明文存储,请妥善保管**)。
### 6.2 执行备份 `backup.sh`
```bash
bash bin/backup.sh
```
按 settings 自动备份:网站目录、数据库(本地+可选远程/对象存储)、并清理过期备份。
> 远程/对象存储备份底层会调用 `scripts/` 下的 `db_bk.sh`、`mabs.sh` 等批量运维工具,需 `backup_setup.sh` 已配置好目标。
---
## 7. FTP 用户管理 `bin/pureftpd_vhost.sh`
```bash
bash bin/pureftpd_vhost.sh --add -u ftpuser -p pass -d /data/www # 新增 FTP 用户
bash bin/pureftpd_vhost.sh --usermod -u ftpuser -d /new/dir # 改主目录
bash bin/pureftpd_vhost.sh --passwd -u ftpuser -p newpass # 改密码
bash bin/pureftpd_vhost.sh --delete -u ftpuser # 删用户
bash bin/pureftpd_vhost.sh --list # 列出所有用户
bash bin/pureftpd_vhost.sh --showuser -u ftpuser # 查看用户详情
```
---
## 8. 重置数据库 root 密码 `bin/reset_db_root_password.sh`
```bash
bash bin/reset_db_root_password.sh -p 'NewPass123' # 用新密码重置
bash bin/reset_db_root_password.sh -f # 忘记旧密码,强制重置
bash bin/reset_db_root_password.sh -q # 静默
bash bin/reset_db_root_password.sh -h
```
> 默认会生成 8 位随机密码(无 `-p` 时),重置后请在输出中记录。
---
## 9. `scripts/` 运维辅助(非安装必需,手动调用)
| 脚本 | 用途 | 注意 |
|------|------|------|
| `scripts/db_bk.sh <库名>` | 单库备份 | 被 backup.sh 调用 |
| `scripts/website_bk.sh` | 网站目录备份 | 被 backup.sh 调用 |
| `scripts/mabs.sh` + `thread.sh` + `mssh.exp` + `mscp.exp` | 多主机批量 SSH/SCP 推送与命令执行 | 需自备 `iplist.txt`/`config.txt`;明文存远程口令;不会自动触发 |
| `scripts/ckssh.py` | 检测某 IP 的 SSH 端口是否通 | 仅 TCP 连通性检测 |
---
## 10. 注意事项(与上游 OneinStack 的差异)
1. **仅支持 Debian 9-13 / Ubuntu 16-26**apt-get 系);RHEL/CentOS 等会直接退出。
2. **软件已裁剪**Web 仅 NginxDB 仅 MySQL/MariaDB/PostgreSQL/MongoDB;缓存仅 Redis;移除 Tengine/OpenResty/Apache/Percona/Memcached/Tomcat/OpenJDK。
3. **PHP 仅 7.4 / 8.0 / 8.1**;多版本共存仅支持这三者。
4. **Nginx 已精简**:不含 rtmp 流媒体与 fancyindex 目录美化模块。
5. 安装日志路径为 `runtime/install.log`(向上游 `install.log` 内容一致)。
---
## 11. 快速参考(一条命令装常用栈)
```bash
# LNMP + Redis + phpMyAdmin,装完重启
cd ServerStack
bash bin/install.sh --nginx_option 1 --db_option 1 --dbinstallmethod 1 \
--dbrootpwd 'DBpass!2026' --php_option 3 --phpcache_option 1 \
--php_extensions "fileinfo redis" --redis --phpmyadmin --reboot
```