一、Environment
Operating System: CentOS 7
Server Location: San Jose
二、Let’s Start
1. 安裝和更新 V2Ray (安裝執行檔和 .dat 資料檔)
# bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)
1.1 安裝最新發行的 geoip.dat 和 geosite.dat (只更新 .dat 資料檔)(首次安裝,無需執行)
# bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-dat-release.sh)
1.2 移除 V2Ray
# bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh) --remove
2. 配置文件 /usr/local/etc/v2ray/config.json
{ "log": { "access": "/var/log/v2ray/access.log", "error": "/var/log/v2ray/error.log", "loglevel": "warning" }, "inbounds": [ { "port": 33689, "listen": "127.0.0.1", "protocol": "vmess", "settings": { "clients": [ { "id": "89e2d792-1d03-46ec-9210-23c52d9d4a2f", "alterId": 0 } ] }, "sniffing": { "enabled": true, "destOverride": ["http", "tls"] }, "streamSettings": { "network": "ws", "wsSettings": { "path": "/wYof60qQ" } } } ], "outbounds": [ { "tag": "direct", "protocol": "freedom", "settings": {} }, { "tag": "blocked", "protocol": "blackhole", "settings": {} } ], "routing": { "strategy": "rules", "settings": { "domainStrategy": "AsIs", "rules": [ { "type": "field", "ip": ["geoip:private"], "outboundTag": "blocked" } ] } } }
3. 守護進程脚本 /etc/systemd/system/v2ray.service
[Unit] Description=V2Ray Service Documentation=https://www.v2fly.org/ 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/bin/env v2ray.vmess.aead.forced=false /usr/local/bin/v2ray -config /usr/local/etc/v2ray/config.json Restart=on-failure RestartPreventExitStatus=23 [Install] WantedBy=multi-user.targe
4. 重載、啓動、添加開機自啓、查詢狀態
systemctl daemon-reload systemctl start v2ray.service systemctl enable v2ray.service systemctl status v2ray.service
三、參考文章
- https://github.com/v2fly/fhs-install-v2ray
- https://github.com/v2fly/fhs-install-v2ray/wiki/Migrate-from-the-old-script-to-this
- https://www.v2ray.com/