#!/usr/bin/env bash
set -e
# ==============================
# 1. 更新系统并安装基础依赖
# ==============================
apt update
apt upgrade -y
apt install -y \
curl \
wget \
tar \
socat \
ca-certificates
# ==============================
# 2. Swap
# 已有 Swap:保持原样
# 没有 Swap:自动创建 1GB
# ==============================
if [ -z "$(swapon --show=NAME --noheadings)" ]; then
echo "No swap detected. Creating 1GB swap..."
if [ "$(findmnt -no FSTYPE /)" = "btrfs" ]; then
echo "Btrfs detected. Please configure swap manually."
exit 1
fi
fallocate -l 1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
if ! grep -qE '^/swapfile[[:space:]]' /etc/fstab; then
echo '/swapfile none swap sw 0 0' >> /etc/fstab
fi
else
echo "Existing swap detected. Keeping current configuration."
fi
# ==============================
# 3. Swappiness + BBR
# ==============================
cat > /etc/sysctl.d/99-proxy-baseline.conf <<'EOF'
vm.swappiness = 10
EOF
if modprobe tcp_bbr 2>/dev/null && \
sysctl -n net.ipv4.tcp_available_congestion_control | grep -qw bbr
then
echo "tcp_bbr" > /etc/modules-load.d/99-bbr.conf
cat >> /etc/sysctl.d/99-proxy-baseline.conf <<'EOF'
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
EOF
echo "BBR enabled."
else
echo "BBR not available. Keeping system default."
rm -f /etc/modules-load.d/99-bbr.conf
fi
sysctl -p /etc/sysctl.d/99-proxy-baseline.conf
# ==============================
# 4. 最终状态
# ==============================
echo
echo "===== Swap ====="
swapon --show
free -h
echo
echo "===== BBR ====="
sysctl net.ipv4.tcp_congestion_control
sysctl net.core.default_qdisc
echo
echo "System ready for 3X-UI."
# ========================================================
# 步骤三:安装 3X-UI 面板
# ========================================================
bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh)
出现:Choose [1]: 回车键
Would you like to customize the Panel Port settings? (If not, a random port will be applied) [y/n]: y
Please set up the panel port: 8888
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): 2
ip -6 addr show scope global
Bind the panel to 127.0.0.1 only? (recommended — forces SSH tunnel / reverse-proxy access) [y/N]: n
请回到你的 FinalShell 终端(如果刚才退出了,请重新输入 x-ui 并回车唤出菜单):
输入数字 7 并按回车(对应菜单中的 7. Reset Username & Password)。
输入你想设置的账号(比如 admin,或者你自己常用的名字),然后按回车。
输入你想设置的密码,然后按回车。
Please enter your selection [0-28]: 7
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]: c*****M
Please set the login password [default is a random password]: t*******x
Do you want to disable currently configured two-factor authentication? (y/n): n
Restart the panel, Attention: Restarting the panel will also restart xray [Default y]: y
[INF] x-ui and xray Restarted successfully
直接在终端输入 x-ui 并回车,然后输入 11 查看面板的登录路径!
Please enter your selection [0-28]: 11
