1251 字
6 分钟
VPS新机开荒手册
一、基础测试
1.1 融合怪性能测试
bash <(wget -qO- --no-check-certificate https://gitlab.com/spiritysdx/za/-/raw/main/ecs.sh)覆盖 CPU、内存、磁盘 I/O、网络速度、路由追踪、运营商信息。
1.2 IP 流媒体与信誉测试
bash <(curl -sL IP.Check.Place)检测 Netflix / Disney+ / YouTube 解锁、Google / Cloudflare 可用性、IP 信誉、DNS 泄露等。
二、系统更新与安全加固
2.1 系统更新
# Ubuntu / Debianapt update && apt upgrade -y
# CentOS / RHELyum update -y
# AlmaLinux / Rocky Linux / openEulerdnf update -y2.2 SSH 安全加固
修改端口(可选):
sed -i 's/#Port 22/Port 2222/' /etc/ssh/sshd_configsystemctl restart sshd启用密钥登录、禁用密码登录:
# 本地生成密钥ssh-keygen -t ed25519
# 上传公钥ssh-copy-id -p 22 user@your-server-ip
# 服务端调整sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin prohibit-password/' /etc/ssh/sshd_configsed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/' /etc/ssh/sshd_configsed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_configsystemctl restart sshd关闭密码登录前务必确认密钥登录可用,避免把自己锁在门外。
2.3 防火墙
UFW:
ufw allow 22/tcpufw allow 80/tcpufw allow 443/tcpufw enableufw statusFirewalld:
firewall-cmd --permanent --add-service=sshfirewall-cmd --permanent --add-service=httpfirewall-cmd --permanent --add-service=httpsfirewall-cmd --reloadfirewall-cmd --list-all2.4 Fail2Ban
apt install fail2ban -y # Debian / Ubuntuyum install fail2ban -y # CentOS / RHELsystemctl enable --now fail2ban2.5 创建普通用户
adduser usernameusermod -aG sudo username # Debian / Ubuntuusermod -aG wheel username # CentOS / RHELsu - username三、常用工具
3.1 基础工具包
apt install -y vim curl wget git htop net-tools unzip zip tar gzip jq# 或yum install -y vim curl wget git htop net-tools unzip zip tar gzip jq3.2 Zsh + Oh My Zsh
apt install zsh -ysh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"chsh -s $(which zsh)3.3 Tmux
apt install tmux -ytmux new -s dev # 新建会话tmux attach -t dev # 附加tmux ls # 列表# Ctrl+B D 脱离会话四、Docker 环境
4.1 Docker 安装
curl -fsSL https://get.docker.com | bashsystemctl enable --now docker
# 国内镜像加速mkdir -p /etc/dockercat > /etc/docker/daemon.json <<EOF{ "registry-mirrors": [ "https://docker.mirrors.ustc.edu.cn", "https://registry.docker-cn.com" ]}EOFsystemctl daemon-reloadsystemctl restart docker
usermod -aG docker $USERnewgrp dockerdocker run hello-world4.2 Docker Compose v2
mkdir -p /usr/local/lib/docker/cli-pluginscurl -SL https://github.com/docker/compose/releases/latest/download/docker-compose-linux-$(uname -m) \ -o /usr/local/lib/docker/cli-plugins/docker-composechmod +x /usr/local/lib/docker/cli-plugins/docker-composedocker compose version4.3 常用容器
Nginx Proxy Manager:
version: '3'services: app: image: jc21/nginx-proxy-manager:latest ports: - '80:80' - '81:81' - '443:443' environment: DB_MYSQL_HOST: db DB_MYSQL_PORT: 3306 DB_MYSQL_USER: npm DB_MYSQL_PASSWORD: npm DB_MYSQL_NAME: npm volumes: - ./data:/data - ./letsencrypt:/etc/letsencrypt db: image: jc21/mariadb-aria:latest environment: MYSQL_ROOT_PASSWORD: npm MYSQL_DATABASE: npm MYSQL_USER: npm MYSQL_PASSWORD: npm volumes: - ./mysql:/var/lib/mysqlWatchtower 自动更新:
docker run -d --name watchtower \ -v /var/run/docker.sock:/var/run/docker.sock \ containrrr/watchtower --cleanup --schedule "0 0 4 * * *"五、面板服务
5.1 1Panel
bash <(curl -sSL https://linuxmirrors.cn/docker.sh)bash -c "$(curl -sSL https://resource.fit2cloud.com/1panel/package/v2/quick_start.sh)"覆盖网站、数据库(MySQL / PostgreSQL / MongoDB)、文件、备份、日志、应用商店、监控中心等。
5.2 宝塔面板
# Ubuntu / Debianwget -O install.sh http://download.bt.cn/install/install-ubuntu_6.0.sh && bash install.sh# CentOSwget -O install.sh http://download.bt.cn/install/install_6.0.sh && bash install.sh5.3 CasaOS(家庭服务器)
curl -fsSL https://get.casaos.io | sudo bash六、代理工具
6.1 3X-UI
bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh)常用命令:
x-ui start | stop | restart | status | update | uninstall6.2 Sing-box
docker run -d --name sing-box --network host \ -v $(pwd)/config:/etc/sing-box \ -v $(pwd)/certs:/root/certs \ ghcr.io/sagernet/sing-box:latest七、监控与备份
7.1 Uptime Kuma
version: '3'services: uptime-kuma: image: louislam/uptime-kuma:1 container_name: uptime-kuma ports: - "3001:3001" volumes: - ./uptime-kuma-data:/app/data restart: always7.2 Prometheus + Grafana
version: '3'services: prometheus: image: prom/prometheus:latest ports: ["9090:9090"] volumes: - ./prometheus.yml:/etc/prometheus/prometheus.yml - ./prometheus-data:/prometheus restart: always grafana: image: grafana/grafana:latest ports: ["3000:3000"] volumes: - ./grafana-data:/var/lib/grafana environment: - GF_SECURITY_ADMIN_USER=admin - GF_SECURITY_ADMIN_PASSWORD=your_password restart: always node-exporter: image: prom/node-exporter:latest ports: ["9100:9100"] volumes: - /proc:/host/proc:ro - /sys:/host/sys:ro - /:/rootfs:ro command: - '--path.procfs=/host/proc' - '--path.sysfs=/host/sys' - '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)' restart: always7.3 AList 网盘挂载
version: '3'services: alist: image: xhofe/alist:latest ports: ["5244:5244"] volumes: - ./alist-data:/opt/alist/data environment: - PUID=1000 - PGID=1000 - UMASK=022 restart: always7.4 Restic 增量备份
apt install restic -yrestic init --repo /backup/restic-backuprestic backup /important/data --repo /backup/restic-backuprestic restore latest --target /restore/path --repo /backup/restic-backuprestic snapshots --repo /backup/restic-backup7.5 Rclone 云同步
curl https://rclone.org/install.sh | sudo bashrclone configrclone sync /local/path remote:bucket/path# crontab 定时# 0 2 * * * /usr/bin/rclone sync /local/path remote:bucket/path7.6 Docker 卷备份脚本
#!/bin/bashBACKUP_DIR="/backup/docker"DATE=$(date +%Y%m%d_%H%M%S)
docker run --rm \ -v your_container_volume:/data:ro \ -v $BACKUP_DIR:/backup \ alpine tar czf /backup/volume_backup_$DATE.tar.gz -C /data .
find $BACKUP_DIR -name "volume_backup_*.tar.gz" -mtime +7 -delete八、性能优化
8.1 文件描述符
echo "* soft nofile 65536" >> /etc/security/limits.confecho "* hard nofile 65536" >> /etc/security/limits.conf8.2 TCP 参数
cat >> /etc/sysctl.conf <<EOFfs.file-max = 1000000fs.inotify.max_user_instances = 8192
net.ipv4.tcp_fastopen = 3net.ipv4.tcp_slow_start_after_idle = 0net.ipv4.tcp_max_syn_backlog = 8192net.core.netdev_max_backlog = 8192net.core.somaxconn = 8192net.ipv4.tcp_tw_reuse = 1net.ipv4.ip_local_port_range = 1024 65535net.ipv4.tcp_fin_timeout = 15net.ipv4.tcp_keepalive_time = 600net.ipv4.tcp_keepalive_intvl = 30net.ipv4.tcp_keepalive_probes = 3EOFsysctl -p8.3 Swap
dd if=/dev/zero of=/swapfile bs=1M count=2048chmod 600 /swapfilemkswap /swapfileswapon /swapfileecho '/swapfile none swap sw 0 0' >> /etc/fstabecho 'vm.swappiness=10' >> /etc/sysctl.confsysctl -p8.4 BBR
cat >> /etc/sysctl.conf <<EOFnet.core.default_qdisc=fqnet.ipv4.tcp_congestion_control=bbrEOFsysctl -psysctl net.ipv4.tcp_available_congestion_controllsmod | grep bbr九、实用脚本
9.1 系统信息
cat > ~/info.sh <<'EOF'#!/bin/bashecho "==========================================="echo " 系统信息查询"echo "==========================================="echo "操作系统:$(cat /etc/os-release | grep PRETTY_NAME | cut -d '"' -f2)"echo "内核版本:$(uname -r)"echo "CPU 型号:$(lscpu | grep "Model name" | cut -d':' -f2 | xargs)"echo "CPU 核心数:$(nproc)"echo "内存总量:$(free -h | grep Mem | awk '{print $2}')"echo "已用内存:$(free -h | grep Mem | awk '{print $3}')"echo "磁盘空间:"df -h | grep -E '^/dev/'echo "外网 IP:$(curl -s cip.cc)"echo "==========================================="EOFchmod +x ~/info.sh9.2 Docker 清理
cat > ~/docker-clean.sh <<'EOF'#!/bin/bashdocker image prune -fdocker container prune -fdocker volume prune -fEOFchmod +x ~/docker-clean.sh十、注意事项
- 禁用密码登录前必须先验证密钥登录
- 定期更新系统与容器镜像
- 防火墙只放行必要端口
- 面板端口建议改默认值并配置访问白名单
- 代理相关工具在部署前先确认当地合规要求
- 重要数据至少遵循”本地 + 异地”双副本原则
总结
- 新手:1Panel / 宝塔面板,图形化管理
- 进阶:Docker + Compose,手写 yaml,灵活度高
- 家庭用户:CasaOS
- 企业/生产:完整监控 + 告警 + 备份方案