服务器初始化
新装的 Alibaba Cloud Linux 4 从零到可部署的过程
基础软件
# Node.js(AL4 官方源,24.x)与 pnpm
dnf install -y nodejs
corepack enable
corepack prepare pnpm@11.24.0 --activate
# PostgreSQL 15(AL4 官方源)
dnf install -y postgresql-server postgresql
postgresql-setup --initdb
systemctl enable --now postgresql
# nginx 与 acme.sh(证书)
dnf install -y nginx
systemctl enable --now nginx
curl https://get.acme.sh | sh -s email=dev@huishiit.com
数据库
sudo -u postgres psql <<'SQL'
CREATE USER huishiit WITH PASSWORD '在此填写随机密码';
CREATE DATABASE huishiit OWNER huishiit;
SQL
密码只写入服务器上的 /opt/huishiit/server/.env,不要提交到任何仓库。
Swap
1.6G 内存的机器跑构建必须配 swap:
fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0' >> /etc/fstab
防火墙
只开 80/443,数据库和 API 只监听 127.0.0.1,由 nginx 反代对外:
firewall-cmd --permanent --add-service=http --add-service=https
firewall-cmd --reload