本文分为两个阶段:
阶段一:完成服务器基础优化
阶段二:安装并配置 3X-UI 面板
建议按照文章顺序逐步操作。执行命令前,请确认当前登录的账号拥有 sudo 权限。
阶段一:服务器基础优化
1. 备份原始 sysctl 配置文件
修改服务器配置前,建议先备份原始的 sysctl 配置文件。后续如果出现异常,可以使用备份文件恢复。
sudo cp /etc/sysctl.conf /etc/sysctl.conf.bak.$(date +%F)
2. 写入通用安全与性能优化参数
下面的命令采用追加模式写入配置,不会覆盖 /etc/sysctl.conf 中已有的内容。
该方案主要针对 1C1G、2C2G 等常见的低配或入门级 VPS,包含虚拟内存、BBR、TCP 缓冲区、连接队列和系统安全等相关设置。
cat <<EOF | sudo tee -a /etc/sysctl.conf
# === 通用性能优化方案(适配 1C1G / 2C2G 等绝大多数服务器)===
# 1. 虚拟内存:优先使用物理内存,90% 物理内存满后才用 Swap
vm.swappiness = 10
# 2. BBR 拥塞控制:提升高延迟/跨国网络吞吐量
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
# 3. TCP 缓冲区优化:最大上限 4MB~8MB,平衡速度与内存占用,防止小内存爆机
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 65536 4194304
net.core.rmem_max = 8388608
net.core.wmem_max = 8388608
# 4. 连接队列:设为 2048,兼容低配 CPU(1C/2C),防止高并发丢包
net.core.somaxconn = 2048
net.ipv4.tcp_max_syn_backlog = 2048
# 5. 连接回收与网络探测
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mtu_probing = 1
# 6. 系统安全与进程限制加固
kernel.pid_max = 65536
fs.protected_fifos = 1
fs.protected_hardlinks = 1
fs.protected_regular = 2
fs.protected_symlinks = 1
EOF
3. 让配置立即生效
配置写入完成后,执行下面的命令重新加载 /etc/sysctl.conf:
sudo sysctl -p
如果终端没有出现明显报错,说明配置已经成功加载。
4. 检查 BBR 是否启用
执行下面的命令检查 BBR 内核模块:
lsmod | grep bbr
如果终端能够看到包含 bbr 的输出,说明 BBR 已经正常加载。
阶段二:安装 3X-UI 面板
1. 执行 3X-UI 官方安装脚本
运行下面的命令开始安装面板:
bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh)
安装过程中会出现多个交互式选项,请按照下面的说明进行设置。
2. 自定义面板端口
安装程序会询问是否需要自定义面板端口:
Would you like to customize the Panel Port settings? (If not, a random port will be applied) [y/n]: y
输入 y,表示手动设置面板端口。
面板端口可以设置为 8080,也可以使用其他未被占用的端口。输入前建议先确认端口号,避免输入错误后需要重新调整。
3. 选择 SSL 证书安装方式
接下来,安装程序会询问 SSL 证书的配置方式:
═══════════════════════════════════════════
SSL Certificate Setup (RECOMMENDED)
═══════════════════════════════════════════
SSL is strongly recommended. Skip only if a reverse proxy
or SSH tunnel handles TLS for you.
Let's Encrypt now supports both domains and IP addresses!
Choose SSL certificate setup method:
1. Let's Encrypt for Domain (90-day validity, auto-renews)
2. Let's Encrypt for IP Address (6-day validity, auto-renews)
3. Custom SSL Certificate (Path to existing files)
4. Skip SSL (advanced — behind reverse proxy / SSH tunnel only)
Note: Options 1 & 2 require port 80 open. Option 3 requires manual paths.
Note: Option 4 serves the panel over plain HTTP — only safe behind nginx/Caddy or an SSH tunnel.
Choose an option (default 2 for IP): 4
本教程暂时不在安装过程中配置证书,因此直接输入 4 跳过 SSL 配置。
需要注意的是,跳过 SSL 后,面板将通过普通 HTTP 提供访问。请根据自己的实际使用环境,做好面板访问和安全防护设置。
4. 设置面板监听地址
随后,安装程序会询问是否仅将面板绑定到本地地址 127.0.0.1:
Bind the panel to 127.0.0.1 only? (recommended — forces SSH tunnel / reverse-proxy access) [y/N]: n
这里输入 n。
完成安装后,我们会进入面板,将监听地址修改为 0.0.0.0。
5. 重置面板用户名和密码
安装完成后,在终端输入:
x-ui
进入管理菜单后,回复数字:
7
系统会询问是否确认重置面板的用户名和密码:
Are you sure to reset the username and password of the panel? [Default n]: y
输入 y 后,即可开始设置新的登录用户名和密码。
这一步非常重要,后续登录 3X-UI 面板时需要使用这里设置的账号信息。
6. 设置 3X-UI 面板登录信息
下面是完整的设置过程示例:
Are you sure to reset the username and password of the panel? [Default n]: y
Please set the login username [default is a random username]: hozzo6
Please set the login password [default is a random password]: gofwaz
Do you want to disable currently configured two-factor authentication? (y/n): y
Two factor authentication has been disabled.
Panel login username has been reset to: hozzo6
Panel login password has been reset to: gofwaz
设置完成后,请妥善保存面板的用户名、密码、端口和服务器 IP 地址。
为了保障服务器安全,建议实际使用时设置一个强度更高且不易被猜测的密码,不要直接使用教程中的示例账号和密码。
本阶段操作总结
完成以上操作后,你已经完成了:
备份服务器原始的
sysctl配置文件;写入服务器性能与安全优化参数;
重新加载系统配置;
检查 BBR 内核模块;
安装 3X-UI 面板;
设置面板端口和监听方式;
重置面板登录用户名和密码。
下一步可以登录 3X-UI 面板,继续完成入站配置、客户端创建和节点信息导出。
🔗 相关资源: VMRACK:https://www.vmrack.net?ref_code=5q7PSYKXVxj FinalShell 官方下载:https://www.hostbuf.com/t/988.html
