阿里云 ECS 环境配置
大约 2 分钟
阿里云 ECS 环境配置
记录本站所在服务器的基本信息、初始化和常用运维命令。
最后更新:2026-11-20
1. 实例信息
| 项目 | 值 |
|---|---|
| 实例名 | iZ2ze7wm5uimtkc84ho2kaZ |
| 公网 IP | 39.97.254.3 |
| 系统 | Debian GNU/Linux 12 (bookworm) |
| 内核 | 6.1.x amd64 |
| 系统盘 | 40G(/dev/vda3) |
| 内存 | 1.7G |
| Web 服务 | nginx 1.22.1 |
| 证书 | Let's Encrypt(certbot 2.1.0) |
| VPN | WireGuard,服务端 10.0.0.1 |
2. 系统初始化
重装系统后的第一轮操作:
# 1. 时区与时间
timedatectl set-timezone Asia/Shanghai
timedatectl status
# 2. 更新索引并升级
apt update && apt upgrade -y
# 3. 常用工具
apt install -y curl vim git tar gzip unzip htop net-tools
# 4. 基础 Web 组件
apt install -y nginx
systemctl enable --now nginx2.1 SSH 公钥
重装系统会清空 /root/.ssh/authorized_keys,需要重新下发:
mkdir -p /root/.ssh && chmod 700 /root/.ssh
echo 'ssh-rsa AAAA...你的公钥... user@host' >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys服务器主机密钥也会变,本地首次连接会提示
REMOTE HOST IDENTIFICATION HAS CHANGED。确认是自己重装后:ssh-keygen -R 10.0.0.1 ssh-keygen -R 39.97.254.3
2.2 加固(可选)
# 禁止密码登录,仅公钥
sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config
sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin prohibit-password/' /etc/ssh/sshd_config
systemctl restart ssh
# 简单防火墙(注意先放行 22,否则会锁死自己)
apt install -y ufw
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw allow 51820/udp
ufw --force enable3. 安全组规则
控制台 → 安全组 → 入方向:
| 协议 | 端口 | 授权对象 | 用途 |
|---|---|---|---|
| TCP | 22 | 按需(建议仅自己的 IP) | SSH |
| TCP | 80 | 0.0.0.0/0 | HTTP / 证书验证 |
| TCP | 443 | 0.0.0.0/0 | HTTPS |
| UDP | 51820 | 0.0.0.0/0 | WireGuard |
备案未通过时,大陆服务器的 80/443 会被拦截,需要临时用高位端口(如 8081)访问。
4. 常用运维命令
# 服务状态
systemctl status nginx --no-pager
systemctl status certbot.timer --no-pager
systemctl status wg-quick@wg0 --no-pager # active (exited) 是正常状态
# 端口监听
ss -tlnp | grep -E ':(22|80|443)'
ss -ulnp | grep 51820
# 磁盘与内存
df -h /
free -m
du -sh /var/www/my-docs /var/log /var/cache/apt
# 日志
journalctl -u nginx --since '1 hour ago' --no-pager
tail -f /var/log/nginx/error.log
# 重启后的自检清单
systemctl is-enabled nginx certbot.timer wg-quick@wg0
curl -I https://www.ouyangss.site/5. 备份与快照
重装系统会清空磁盘,而快照是唯一的后悔药。 建议:
- 在阿里云控制台为系统盘开启自动快照策略(例如每天一次,保留 7 天)
- 重大操作(升级系统、改 nginx、改 VPN)之前手动打一次快照
- 站点内容本身在本地 Git 仓库,服务器上的东西尽量做到"可由脚本重建"——本次事故正是靠这一点在 3 分钟内恢复上线
事故背景见 部署事故复盘。
鄂公网安备42011102006488号