【转】从源码手动编译安装 Xray:最干净的科学上网方式(VLESS + REALITY)

原文地址:https://vpsdeck.com/xray-source-install-vless-reality/

/images/xray_vless_xtls_reality_2400x720.png

前言

目前网络上关于 Xray 的安装教程大多数都是一键脚本,这虽然方便,但也带来许多冗余配置和潜在安全隐患。
如果你是一个对系统整洁度要求较高的 MJJ(没救了极客 🤭),不妨试试 从源码手动编译安装 Xray,只安装自己真正需要的部分,稳定、快速、防封更胜一筹。

本文以 Debian 12.9 为例,使用最新版本的 Golang 编译 Xray-core,并部署 VLESS + REALITY 的最简服务端配置。


1. 实验环境

  • 服务器服务商
  • 操作系统:Debian 12.9
  • 服务器配置:1 核 / 768MB RAM / 15GB SSD
  • 服务器位置:美国洛杉矶
  • 线路情况
    • 电信:双程 CN2 GIA
    • 移动:双程 CMIN2
    • 联通:去程 9929 / 回程 CN2 GIA

2. 安装基础依赖包

sudo apt update -y && sudo apt upgrade -y && sudo apt install git vim curl nano -y

这些工具主要用于文件编辑、下载与基础调试,属于最小必要依赖。


3. 安装 Golang(Go 语言编译器)

进入官方文档查看安装说明:👉 https://go.dev/doc/install 官方 Golang 最新发行包: 👉 https://go.dev/dl/

cd /opt/
curl -LO https://go.dev/dl/go1.25.5.linux-amd64.tar.gz
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.25.5.linux-amd64.tar.gz
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
source ~/.bashrc

✅ 如果你的 VPS 是 ARM 架构,请使用 go1.25.5.linux-arm64.tar.gz


4. 编译 Xray-core

4.1 拉取源码

git clone https://github.com/XTLS/Xray-core.git
cd Xray-core && go mod download

4.2 构建可执行文件

CGO_ENABLED=0 go build -o xray -trimpath -ldflags "-s -w -buildid=" ./main
sudo mv xray /usr/local/bin

5. 配置 Xray 服务端(VLESS + REALITY)

5.1 创建配置文件目录与文件

sudo mkdir -p /etc/xray
sudo nano /etc/xray/config.json

5.2 推荐配置模板(请根据提示修改)

{
  "log": {
    "loglevel": "warning"
  },
  "inbounds": [
    {
      "port": 你的端口,
      "protocol": "vless",
      "settings": {
        "clients": [
          {
            "id": "你的UUID",
            "flow": "xtls-rprx-vision"
          }
        ],
        "decryption": "none"
      },
      "streamSettings": {
        "network": "tcp",
        "security": "reality",
        "realitySettings": {
          "dest": "www.bing.com:443",
          "serverNames": ["www.bing.com", "bing.com"],
          "privateKey": "你的PrivateKey",
          "shortIds": ["你的ShortID"]
        }
      },
      "sniffing": {
        "enabled": true,
        "destOverride": ["http", "tls", "quic"]
      }
    }
  ],
  "outbounds": [
    {
      "protocol": "freedom",
      "tag": "direct"
    },
    {
      "protocol": "blackhole",
      "tag": "block"
    }
  ]
}

🔧 参数生成

  • port: 修改成你喜欢的端口,建议五位数以上,比如 11983
  • UUID: xray uuid
  • PrivateKey: xray x25519
  • ShortID(8位 hex): openssl rand -hex 8

6. 创建 systemd 管理服务

sudo nano /etc/systemd/system/xray.service

填入以下内容:

[Unit]
Description=Xray Service
Documentation=https://github.com/xtls
After=network.target nss-lookup.target

[Service]
User=root
NoNewPrivileges=true
ExecStart=/usr/local/bin/xray run -config /etc/xray/config.json
Restart=on-failure
RestartPreventExitStatus=23

[Install]
WantedBy=multi-user.target

启动服务

sudo systemctl daemon-reexec
sudo systemctl enable --now xray

查看运行状态

sudo systemctl status xray --no-pager

若服务未启动成功,查看日志:

sudo journalctl -u xray -n 80 --no-pager

7. 常用命令汇总

动作命令
启动sudo systemctl start xray
停止sudo systemctl stop xray
重启sudo systemctl restart xray
状态查看sudo systemctl status xray --no-pager
查看日志sudo journalctl -u xray -n 80 --no-pager

八、总结

你只需要三个文件,即可完成简洁干净的科学上网服务部署:

  • /usr/local/bin/xray — 编译后的主程序
  • /etc/xray/config.json — 配置文件
  • /etc/systemd/system/xray.service — 管理服务脚本

相比一键脚本安装方式,这种从源码编译的方式,更透明、更纯净,非常适合追求控制感和极致优化的玩家。

————版权归原作者所有,转载需注明————–

评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇