#!/bin/bash
GREEN='\033[0;32m' RED='\033[0;31m' NC='\033[0m' # No Color
if [ "$(id -u)" -ne 0 ]; then echo "请以 root 用户运行此脚本!" exit 1 fi
apt update && apt upgrade -y
apt install -y curl wget unzip openssl
DOMAIN=${1:-"example.com"} # 如果未提供域名参数,则默认使用 example.com DAYS_VALID=365 # 证书有效期(天数) CERT_DIR="/usr/local/etc/xray" # 证书存储目录
mkdir -p ${CERT_DIR}
openssl genrsa -out ${CERT_DIR}/${DOMAIN}.key 2048
openssl req -new -key ${CERT_DIR}/${DOMAIN}.key -out ${CERT_DIR}/${DOMAIN}.csr -subj "/CN=${DOMAIN}"
openssl x509 -req -days ${DAYS_VALID} -in ${CERT_DIR}/${DOMAIN}.csr -signkey ${CERT_DIR}/${DOMAIN}.key -out ${CERT_DIR}/${DOMAIN}.crt
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install UUID=$(xray uuid) cat >> /usr/local/etc/xray/config.json << EOF { "inbounds": [ { "tag": "direct", "port": 443, "protocol": "vless", "settings": { "clients": [ { "id": "${UUID}", "flow": "" } ], "decryption": "none", "fallbacks": [] }, "streamSettings": { "network": "tcp", "security": "tls", "tlsSettings": { "serverNames": [ "" ], "alpn": [ "h2", "http/1.1" ], "certificates": [ { "certificateFile": "${CERT_DIR}/${DOMAIN}.crt", "keyFile": "${CERT_DIR}/${DOMAIN}.key" } ] } }, "sniffing": { "enabled": true, "destOverride": [ "http", "tls", "quic" ], "routeOnly": true } } ], "outbounds": [ { "tag": "direct", "protocol": "freedom" }, { "tag": "warp", "protocol": "socks", "settings": { "servers": [ { "address": "127.0.0.1", "port": 2333 } ] } } ], "routing": { "rules": [ { "type": "field", "outboundTag": "warp", "domain": [ "domain:openai.com", "domain:chatgpt.com", "domain:ai.com", "domain:chat.com", "domain:cloudflare.com", "domain:youtube.com", "domain:netflix.com" ] } ] } } EOF systemctl enable xray
curl -fsSL https://pkg.cloudflareclient.com/pubkey.gpg | gpg --yes --dearmor --output /usr/share/keyrings/cloudflare-warp-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/cloudflare-warp-archive-keyring.gpg] https://pkg.cloudflareclient.com/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/cloudflare-client.list apt update && apt install cloudflare-warp
warp-cli mode proxy warp-cli proxy port 2333 warp-cli registration new warp-cli connect systemctl enable warp-svc
get_public_ip() { # 使用主服务获取 IP IP=$(curl -s ifconfig.me) if [ -z "$IP" ]; then echo "主服务 ifconfig.me 不可用,尝试其他服务..." # 备选服务 1: ipinfo.io IP=$(curl -s ipinfo.io/ip) if [ -z "$IP" ]; then echo "备选服务 ipinfo.io 不可用,尝试其他服务..." # 备选服务 2: ip-api.com IP=$(curl -s http://ip-api.com/line?fields=query) if [ -z "$IP" ]; then echo "无法获取公网 IP 地址,请检查网络连接。" IP="未知" fi fi fi echo "$IP" }
IP=$(get_public_ip)
echo "可使用以下命令查看服务状态:" echo " systemctl status xray # 检查 Xray 服务状态" echo " warp-cli status # 检查 WARP 状态" echo -e "uuid: ${UUID}" echo -e "本机公网 IP 地址: ${IP}" echo "xray-core 配置文件路径: /usr/local/etc/xray/config.json"
1
NevadaLi 21 天前 via iPhone
不如…直接说遇到的问题?
|