服务器配置为OVH 的 ADVANCE-1 | AMD EPYC 4244P 独立服务器
| CPU | AMD EPYC 4244P – 6c/12t – 3.8 GHz/5.1 GHz |
| RAM | 32 GB 5200 MHz |
| Data disks | 2×960 GB SSD NVMe Soft RAID |
| Operating system (OS) | Debian 13 (Trixie) |
| 其它 | 安装服务器时,自定义SWAP为 2 x 4.0 GiB |
设置root登陆
ShellScript
# 先以debian用户登陆, 然后启用root ssh key登陆,
# 编辑 /etc/ssh/sshd_config 文件, 设置如下选项
# 允许 root 登录但禁止密码
# PermitRootLogin prohibit-password
# 确认开启密钥认证
# PubkeyAuthentication yes
# 全系统禁止密码登录
# PasswordAuthentication no
# Ctrl + O -> Enter 保存, Ctrl + X 退出
sudo -i
grep -E "PermitRootLogin|PubkeyAuthentication|PasswordAuthentication" /etc/ssh/sshd_config
nano /etc/ssh/sshd_config
# 清理 authorized_keys 中的强制指令
# 删除 ssh-ed25519(或 ssh-rsa)之前的所有内容
nano /root/.ssh/authorized_keys
# 重启服务
systemctl restart ssh
优化SWAP
ShellScript
# 有两块 NVMe 硬盘,并且每块硬盘上都划分了一个 4GB 的分区作为 Swap,总计 8GB
# 优化SWAP写入顺序为并行模式运行,读写速度翻倍
# 优先级(PRIO)相同,系统默认会以类似 RAID 0 (Striping) 的方式跨磁盘使用它们,这在 NVMe 硬盘上能提供相当不错的 I/O 性能
# 查看当前的 UUID
lsblk -f | grep swap
# 核对 UUID, 将对应的UUID行的 defaults 修改为 sw,pri=5, 如:
# UUID=e4f8999f-2210-46d0-a178-7cdaf6c79332 swap swap sw,pri=5 0 0
# UUID=ba26ebad-52a6-4185-949e-f7ada7d3d675 swap swap sw,pri=5 0 0
cat /etc/fstab
nano /etc/fstab
# 重新加载 Swap 以生效
swapoff -a && swapon -a
# 验证
swapon --show调整systemd限制
ShellScript
echo "DefaultLimitNOFILE=1048576" | tee -a /etc/systemd/system.conf
echo "DefaultLimitNOFILESoft=1048576" | tee -a /etc/systemd/system.conf
echo "DefaultLimitNOFILE=1048576" | tee -a /etc/systemd/user.conf
echo "DefaultLimitNOFILESoft=1048576" | tee -a /etc/systemd/user.conf
# 重载配置
systemctl daemon-reexec优化SSD和CPU电源性能
ShellScript
# 启用定期 TRIM: 这能保持 SSD 的长期读写性能
systemctl enable --now fstrim.timer
# 安装 linux-cpupower CPU 电源管理工具
apt update
apt install -y linux-cpupower
# 设置所有核心进入性能模式
cpupower frequency-set -g performance内核网络参数优化 (sysctl)
ShellScript
# 使用更现代的目录方式
nano /etc/sysctl.d/optimization.conf
# -------------------------------粘贴以下优化内容-------------------
fs.file-max = 2097152
# 开启 BBR 拥塞控制
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
# 增加并发连接处理能力
net.core.somaxconn = 65535
net.ipv4.tcp_max_syn_backlog = 65535
# 内核读写缓存
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
# 优化端口回收
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 1024 65535
# ------------------------------粘贴结束--------------------------
# 应用配置
sysctl --system
系统资源限制 (ulimit)
ShellScript
nano /etc/security/limits.conf
# -------------------------------粘贴以下优化内容-------------------
* soft nofile 65535
* hard nofile 65535
debian soft nofile 65535
debian hard nofile 65535
# ------------------------------粘贴结束--------------------------
# 验证
ulimit -a
ulimit -n优化时间同步
ShellScript
apt update
apt install -y chrony
nano /etc/chrony/conf.d/custom.conf
# -------------------粘贴以下内容,添加全球通用且快速的服务器-----------
# 使用 Cloudflare 和 Google 的 NTP 服务器,速度快且稳定
server time.cloudflare.com iburst prefer
server time.google.com iburst
server pool.ntp.org iburst
server time.nist.gov iburst
server ptbtime1.ptb.de iburst
server ntp.ripe.net iburst
server 0.europe.pool.ntp.org iburst
server 1.north-america.pool.ntp.org iburst
# 允许系统时钟在偏差较大时快速调整(前 3 次同步)
makestep 1.0 3
# 即使在没有网络连接的情况下,也通过漂移文件记录时钟误差
driftfile /var/lib/chrony/drift
# 提高实时性
rtcsync
# -------------------粘贴结束 -----------
# 重启服务
systemctl restart chrony
# 查看同步源的状态
chronyc sources -v
# 设置时区
timedatectl set-timezone Asia/Shanghai
# 查看当前时区
timedatectl让xshell 和 xsftp同步
ShellScript
# 让xshell 和 xsftp同步
cat <<'EOF' >> /root/.bashrc
PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
EOF
source /root/.bashrcapt 安装必要的软件包
ShellScript
# 升级
apt update && sudo apt full-upgrade -y
# 安装必要的软件包
apt install -y zip unzip wget curl screen build-essential libevent-dev gcc make libc6-dev gpg gnupg2 ca-certificates lsb-release debian-archive-keyring git socat apache2-utils
# 清理
apt autoremove -y && sudo apt autoclean
# 重启
reboot
下面就是布署服务器环境了