本帖最后由 qldzs 于 2024-10-18 17:59 编辑
配合Caddy使用,没有Caddy,就自己改改域名对应的证书路径。
- # (0) 脚本环境
- domains=xxx.xx.pw
- #(1)安装环境
- #yum -y install unzip && yum -y install wget
- apt -y install unzip && apt -y install wget
- #(2)下载安装文件
- mkdir /root/xray && cd /root/xray
- #【根据CPU 选择不同下载地址】
- #wget https://github.com/XTLS/Xray-core/releases/download/v1.8.6/Xray-linux-64.zip && unzip Xray-linux-64.zip
- wget https://github.com/XTLS/Xray-core/releases/download/v1.8.6/Xray-linux-arm64-v8a.zip && unzip Xray-linux-arm64-v8a.zip
- #(3)配置相关文件
- chmod +x xray
- mkdir -p /usr/local/etc/xray
- mkdir -p /var/log/xray/
- ln xray /usr/local/bin/xray
- ln geoip.dat /usr/local/bin/geoip.dat
- ln geosite.dat /usr/local/bin/geosite.dat
- echo"" > /var/log/xray/access.log
- echo"" > /var/log/xray/error.log
- #(4)设置启动脚本
- echo "[Unit]
- Description=start server
- After=network.target
- [Service]
- Type=simple
- ExecStart=/usr/local/bin/xray -config /usr/local/etc/xray/config.json
- Restart=on-failure
- [Install]
- WantedBy=multi-user.target" > xray.service
- echo "[Unit]
- Description=start server
- After=network.target
- [Service]
- Type=simple
- ExecStart=/usr/local/bin/xray -config /usr/local/etc/xray/config.json
- Restart=on-failure
- [Install]
- WantedBy=multi-user.target" > [email protected]
- ln xray.service /etc/systemd/system/xray.service
- ln [email protected] /etc/systemd/system/[email protected]
- #(5.1)上下文环境
- v2port="31111"
- v2addr="0.0.0.0"
- v2id="e9fd071e-b332-41a2-a008-205518957d89"
- v2ssid="e9fd071e-b332-41a2-a008-205518957d89"
- urlpath="files"
- upspeed="100"
- dowspeed="5"
- #(5.2)设置配置文件
- cat >/usr/local/etc/xray/config.json<<EOF
- {
- "inbounds": [
- {
- "port": 13443,
- "protocol": "vless",
- "settings": {
- "clients": [
- {
- "id": "e9fd071e-b332-41a2-a008-205518957d89",
- "flow": "xtls-rprx-vision"
- }
- ],
- "decryption": "none",
- "fallbacks": [
- {
- "dest": "31305",
- "xver": 1
- }
- ]
- },
- "streamSettings": {
- "network": "tcp",
- "security": "reality",
- "realitySettings": {
- "show": false,
- "dest": "${domains}:443",
- "xver": 0,
- "serverNames": [
- "${domains}"
- ],
- "privateKey": "KAojCWlvZBW11I1Rhu111BJC11111AylcpOA1FTByUU",
- "publicKey": "5y9gyFC68LIy1111111d6Q111y1ISRqCs11jEfbEnTs",
- "maxTimeDiff": 70000,
- "shortIds": [
- ""
- ]
- }
- }
- },
- {
- "listen": "0.0.0.0",
- "port": 11143, // 端口
- "protocol": "vless",
- "settings": {
- "clients": [
- {
- "id": "e9fd071e-b332-41a2-a008-205518957d89", // 用户ID
- "flow": "xtls-rprx-vision"
- }
- ],
- "decryption": "none"
- },
- "streamSettings": {
- "network": "tcp",
- "security": "tls",
- "tlsSettings": {
- "certificates": [
- {
- "certificateFile": "/var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/${domains}/${domains}.crt", // 证书
- "keyFile": "/var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/${domains}/${domains}.key" //私钥
- }
- ]
- }
- },
- "sniffing": {
- "enabled": true,
- "destOverride": [
- "http",
- "tls"
- ]
- }
- },
- {
- "listen": "0.0.0.0",
- "port": 31111,
- "protocol": "vless",
- "settings": {
- "udp": true,
- "network": "tcp, udp",
- "decryption": "none",
- "clients": [
- {
- "id": "${v2id}",
- "level": 0
- }
- ]
- },
- "streamSettings": {
- "network": "ws",
- "wsSettings": {
- "path": "/xxxs"
- }
- },
- "sniffing": {
- "enabled": true,
- "destOverride": [
- "http",
- "tls"
- ]
- }
- },
- {
- "protocol": "vless",
- "listen": "0.0.0.0",
- "port": 31110,
- "settings": {
- "udp": true,
- "network": "tcp, udp",
- "decryption": "none",
- "clients": [
- {
- "id": "${v2id}",
- "level": 0
- }
- ]
- },
- "streamSettings": {
- "network": "tcp"
- }
- },
- {
- "protocol": "vless",
- "listen": "0.0.0.0",
- "port": 31112,
- "settings": {
- "decryption": "none",
- "clients": [
- {
- "id": "${v2id}"
- }
- ]
- },
- "streamSettings": {
- "network": "kcp",
- "kcpSettings": {
- "mtu": 1350,
- "tti": 20,
- "uplinkCapacity": 100,
- "downlinkCapacity": 5,
- "congestion": false,
- "readBufferSize": 1,
- "writeBufferSize": 1,
- "header": {
- "type": "none"
- }
- }
- }
- }
- ],
- "outbounds": [
- {
- "protocol": "freedom",
- "settings": {}
- },
- {
- "protocol": "blackhole",
- "settings": {},
- "tag": "blocked"
- }
- ],
- "routing": {
- "rules": [
- {
- "type": "field",
- "ip": ["geoip:private"],
- "outboundTag": "blocked"
- }
- ]
- }
- }
- EOF
- #(7)启动自启动脚本
- systemctl daemon-reload #修改启动脚本后重载命令
- systemctl enable xray
- systemctl restart xray
- systemctl status xray -l #显示完整
- #查看端口占用
- netstat -tlnp|grep 31111
复制代码 |