CentOS安装Xray

1、下载安装脚本
wget https://github.com/XTLS/Xray-install/raw/main/install-release.sh

2、执行脚本
chmod +x install-release.sh
./install-release.sh

3、执行执行日志

info: Installing Xray v1.5.4 for x86_64
Downloading Xray archive: https://github.com/XTLS/Xray-core/releases/download/v1.5.4/Xray-linux-64.zip
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   656  100   656    0     0   2791      0 --:--:-- --:--:-- --:--:--  2779
100 9703k  100 9703k    0     0  5849k      0  0:00:01  0:00:01 --:--:-- 10.4M
info: Extract the Xray package to /tmp/tmp.iaq3rn9Alk and prepare it for installation.
Failed to list unit files: Connection timed out
rm: cannot remove '/etc/systemd/system/xray.service.d/10-donot_touch_multi_conf.conf': No such file or directory
rm: cannot remove '/etc/systemd/system/xray@.service.d/10-donot_touch_multi_conf.conf': No such file or directory
info: Systemd service files have been installed successfully!
warning: The following are the actual parameters for the xray service startup.
warning: Please make sure the configuration file path is correctly set.
# /etc/systemd/system/xray.service
[Unit]
Description=Xray Service
Documentation=https://github.com/xtls
After=network.target nss-lookup.target

[Service]
User=nobody
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
NoNewPrivileges=true
ExecStart=/usr/local/bin/xray run -config /usr/local/etc/xray/config.json
Restart=on-failure
RestartPreventExitStatus=23
LimitNPROC=10000
LimitNOFILE=1000000

[Install]
WantedBy=multi-user.target

# /etc/systemd/system/xray.service.d/10-donot_touch_single_conf.conf
# In case you have a good reason to do so, duplicate this file in the same directory and make your customizes there.
# Or all changes you made will be lost!  # Refer: https://www.freedesktop.org/software/systemd/man/systemd.unit.html
[Service]
ExecStart=
ExecStart=/usr/local/bin/xray run -config /usr/local/etc/xray/config.json

Failed to reload daemon: Connection timed out
installed: /usr/local/bin/xray
installed: /usr/local/share/xray/geoip.dat
installed: /usr/local/share/xray/geosite.dat
installed: /usr/local/etc/xray/config.json
installed: /var/log/xray/
installed: /var/log/xray/access.log
installed: /var/log/xray/error.log
installed: /etc/systemd/system/xray.service
installed: /etc/systemd/system/xray@.service
removed: /tmp/tmp.iaq3rn9Alk
info: Xray v1.5.4 is installed.
You may need to execute a command to remove dependent software: dnf remove curl unzip
Created symlink /etc/systemd/system/multi-user.target.wants/xray.service → /etc/systemd/system/xray.service.
info: Enable and start the Xray service

4、配置文件
采用VMess-TCP模式

vi /usr/local/etc/xray/config.json
{
    "log": {
        "access": "/var/log/xray/access.log",
        "error": "/var/log/xray/error.log",
        "loglevel": "info"
    },
    "routing": {
        "domainStrategy": "AsIs",
        "rules": [
            {
                "type": "field",
                "ip": [
                    "geoip:private"
                ],
                "outboundTag": "block"
            }
        ]
    },
    "inbounds": [
        {
            "listen": "xxx.xxx.xxx.xxx",
            "port": 12340,
            "protocol": "vmess",
            "settings": {
                "clients": [
                    {
                        "id": "a4ee4ff1-2c5c-421b-aa3d-b8a748638d84"
                    }
                ]
            },
            "streamSettings": {
                "network": "tcp"
            }
        }
    ],
    "outbounds": [
        {
            "protocol": "freedom",
            "tag": "direct"
        },
        {
            "protocol": "blackhole",
            "tag": "block"
        }
    ]
}

5、创建日志文件
touch /var/log/xray/access.log
touch /var/log/xray/error.log
chmod 777 -R /var/log/xray

6、客户端使用v2rayN工具配置
TCP模式,伪装类型选none

参考资料:
https://github.com/v2fly/v2ray-examples