#!/bin/bash # 只在 CentOS 服务器上执行。不格式化磁盘。 set -euo pipefail if [[ "$(id -u)" -ne 0 ]]; then echo "需要 root" exit 1 fi if [[ ! -f /etc/os-release ]] || ! grep -Eq 'CentOS Stream|centos' /etc/os-release; then echo "这个脚本只在 CentOS 服务器上执行" exit 1 fi if ! swapon --show | grep -q .; then if [[ ! -f /swapfile ]]; then fallocate -l 2G /swapfile chmod 600 /swapfile mkswap /swapfile fi swapon /swapfile || true grep -q '/swapfile' /etc/fstab || echo '/swapfile none swap sw 0 0' >> /etc/fstab fi cat > /etc/sysctl.d/99-gsfdc.conf <<'EOF' vm.swappiness=10 vm.overcommit_memory=1 net.core.somaxconn=1024 EOF sysctl --system >/dev/null || true if ! command -v docker >/dev/null 2>&1; then dnf -y install dnf-plugins-core dnf config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo dnf -y install docker-ce docker-ce-cli containerd.io docker-compose-plugin fi if [[ ! -f /etc/docker/daemon.json ]]; then mkdir -p /etc/docker cat > /etc/docker/daemon.json <<'EOF' { "registry-mirrors": ["https://docker.1ms.run", "https://docker.m.daocloud.io"], "log-driver": "json-file", "log-opts": {"max-size": "10m", "max-file": "3"}, "live-restore": true } EOF fi systemctl enable --now docker if mountpoint -q /data; then mkdir -p /data/gsfdc echo "数据盘已挂在 /data。生成配置时使用 DATA_ROOT=/data/gsfdc" else echo "没有挂载 /data。先不要格式化磁盘。用 lsblk 确认数据盘后,再决定挂载点。" echo "在此之前数据放在部署目录的 data/。" fi if systemctl is-active --quiet firewalld; then firewall-cmd --permanent --add-service=http firewall-cmd --permanent --add-service=https firewall-cmd --reload fi echo "主机准备完成。接下来在部署目录执行 docker load 和 ./up.sh"