v2ray最快手动纯净部署

准备工作:

一台vps带公网IP,ubuntu 18.04+ 即可,root用户

一个解析到你vps公网IP的域名【如 vmess.v2ray.one】

第一部分 [ 手动配置v2ray ]

rm -f /etc/localtime
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
apt update
apt install nginx curl pwgen openssl netcat cron -y

systemctl enable nginx
systemctl start nginx
service nginx stop

#“域名,端口,uuid,ws路径,ssl证书目录“

#“ngin和v2ray配置文件目录“

#1.设置你的解析好的域名,如本例子中的vmess.v2ray.one
domainName="vmess.v2ray.one"

#2.随机生成v2ray需要用到的服务端口
port="`shuf -i 20000-65000 -n 1`"

#3.随机生成一个uuid
uuid="`uuidgen`"

#4.随机生成一个websocket需要使用的path
path="/`pwgen -A0 6 8 | xargs |sed 's/ /\//g'`"

#5.以时间为基准随机创建一个存放ssl证书的目录
ssl_dir="$(mkdir -pv "/usr/local/etc/v2ray/ssl/`date +"%F-%H-%M-%S"`" |awk -F"'" END'{print $2}')"

#6.定义nginx和v2ray配置文件路径
nginxConfig="/etc/nginx/conf.d/v2ray.conf"
v2rayConfig="/usr/local/etc/v2ray/config.json"
curl -O https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh
curl -O https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-dat-release.sh
bash install-release.sh

bash install-dat-release.sh
systemctl enable v2ray

apt install -y socat
curl https://get.acme.sh | sh

Web 验证申请证书
80 端口空闲的证书申请方式
自行更换代码中的域名、邮箱为你解析的域名及邮箱

~/.acme.sh/acme.sh --register-account -m xxxx@xxxx.com
~/.acme.sh/acme.sh  --issue -d mydomain.com   --standalone

安装证书到指定文件夹
自行更换代码中的域名为你解析的域名,注意开启服务器端的入站防火墙80端口

~/.acme.sh/acme.sh --installcert -d mydomain.com --key-file $ssl_dir/v2ray.key --fullchain-file $ssl_dir/v2ray.crt

chown www-data.www-data $ssl_dir/v2ray.*
systemctl start nginx

~/.acme.sh/acme.sh --set-default-ca --server letsencrypt #如果上面的命令等待时间过长,可更换CA源服务器,在重新执行上面的命令

echo "
server {
	listen 80;
	server_name "$domainName";
	return 301 https://"'$host$request_uri'";

}
server {
	listen 443 ssl http2 default_server;
	listen [::]:443 ssl http2 default_server;
	server_name "$domainName";

	ssl_certificate $ssl_dir/v2ray.crt;
	ssl_certificate_key $ssl_dir/v2ray.key;
	ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+ECDSA+AES128:EECDH+aRSA+AES128:RSA+AES128:EECDH+ECDSA+AES256:EECDH+aRSA+AES256:RSA+AES256:EECDH+ECDSA+3DES:EECDH+aRSA+3DES:RSA+3DES:"!"MD5;
	ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;

	root /usr/share/nginx/html;
	
	location "$path" {
		proxy_redirect off;
		proxy_pass http://127.0.0.1:"$port";
		proxy_http_version 1.1;
		proxy_set_header Upgrade "'"$http_upgrade"'";
		proxy_set_header Connection '"'upgrade'"';
		proxy_set_header Host "'"$http_host"'";
	}

}
" > $nginxConfig
echo '
{
  "log" : {
    "access": "/var/log/v2ray/access.log",
    "error": "/var/log/v2ray/error.log",
    "loglevel": "warning"
  },
  "inbound": {
    "port": '$port',
    "listen": "127.0.0.1",
    "protocol": "vmess",
    "settings": {
      "decryption":"none",
      "clients": [
        {
          "id": '"\"$uuid\""',
          "level": 1
        }
      ]
    },
   "streamSettings":{
      "network": "ws",
      "wsSettings": {
           "path": '"\"$path\""'
      }
   }
  },
  "outbound": {
    "protocol": "freedom",
    "settings": {
      "decryption":"none"
    }
  },
  "outboundDetour": [
    {
      "protocol": "blackhole",
      "settings": {
        "decryption":"none"
      },
      "tag": "blocked"
    }
  ],
  "routing": {
    "strategy": "rules",
    "settings": {
      "decryption":"none",
      "rules": [
        {
          "type": "field",
          "ip": [ "geoip:private" ],
          "outboundTag": "blocked"
        }
      ]
    }
  }
}
' > $v2rayConfig
[ "vless" = "$2" ] && sed -i 's/vmess/vless/' $v2rayConfig
rm -rf /usr/share/nginx/html/*
cd /usr/share/nginx/html/
wget https://github.com/V2RaySSR/Trojan/raw/master/web.zip
unzip web.zip
systemctl restart nginx
systemctl restart v2ray
systemctl status -l v2ray
/usr/sbin/nginx -t && systemctl restart nginx
echo
echo "域名: $domainName" 
echo "UUID: $uuid" 
[ "vless" = "$2" ] && echo "协议:vless" || echo "额外ID: 0" 
echo "安全: tls"
echo "传输: websocket"
echo "路径: $path"

# 注:为适应v2ray-core目前和未来的版本更新,vmess协议额外ID选项已移除,
客户端vmess协议额外id配置为0即可,当前最新版v2rayN客户端已默认为0

第二部分 [ 一键批处理安装v2ray ]

curl -s https://raw.githubusercontent.com/HappyLife-page/v2ray/main/v2ray_installation_vmess.sh | bash -s vmess.v2ray.one vless

vmess.v2ray.one 改为你的解析好的域名即可
如果域名后指定vless,则配置vless协议,不写则默认为vmess协议
只需要等待30s左右,服务器网络好的话会更快
你可以打开链接

https://raw.githubusercontent.com/HappyLife-page/v2ray/main/v2ray_installation_vmess.sh

直接查看批处理的完整内容,这里粘贴原始批处理如下:

#!/bin/bash
# Auth: happylife
# Desc: v2ray installation script
# Plat: ubuntu 18.04+
# Eg  : bash v2ray_installation_vmess.sh "你的域名" [vless]

if [ -z "$1" ];then
	echo "域名不能为空"
	exit
fi


# 配置系统时区为东八区

rm -f /etc/localtime
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime


# 使用ubuntu官方源安装nginx和依赖包并设置开机启动
apt update
apt install nginx curl pwgen openssl netcat cron -y
systemctl enable nginx
systemctl start nginx


# 开始部署之前,我们先配置一下需要用到的参数,如下:
# "域名,端口,uuid,ws路径,ssl证书目录"
# 1.设置你的解析好的域名
domainName="$1"
# 2.随机生成v2ray需要用到的服务端口
port="`shuf -i 20000-65000 -n 1`"
# 3.随机生成一个uuid
uuid="`uuidgen`"
# 4.随机生成一个websocket需要使用的path
path="/`pwgen -A0 6 8 | xargs |sed 's/ /\//g'`"
# 5.以时间为基准随机创建一个存放ssl证书的目录
ssl_dir="$(mkdir -pv "/usr/local/etc/v2ray/ssl/`date +"%F-%H-%M-%S"`" |awk -F"'" END'{print $2}')"
# 6.定义nginx和v2ray配置文件路径
nginxConfig="/etc/nginx/conf.d/v2ray.conf"
v2rayConfig="/usr/local/etc/v2ray/config.json"


# 使用v2ray官方命令安装v2ray并设置开机启动
curl -O https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh
curl -O https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-dat-release.sh
bash install-release.sh
bash install-dat-release.sh
systemctl enable v2ray


##安装acme,并申请加密证书
source ~/.bashrc
curl  https://get.acme.sh | sh
~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
~/.acme.sh/acme.sh --issue -d "$domainName" --alpn -k ec-256
~/.acme.sh/acme.sh --installcert -d "$domainName" --fullchainpath $ssl_dir/v2ray.crt --keypath $ssl_dir/v2ray.key --ecc
chown www-data.www-data $ssl_dir/v2ray.*


# 配置nginx【如下80服务块完全可以不需要】,执行如下命令即可添加nginx配置文件
echo "
server {
	listen 80;
	server_name "$domainName";
	return 301 https://"'$host'""'$request_uri'";
}
server {
	listen 443 ssl http2 default_server;
	listen [::]:443 ssl http2 default_server;
	server_name "$domainName";
	ssl_certificate $ssl_dir/v2ray.crt;
	ssl_certificate_key $ssl_dir/v2ray.key;
	ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+ECDSA+AES128:EECDH+aRSA+AES128:RSA+AES128:EECDH+ECDSA+AES256:EECDH+aRSA+AES256:RSA+AES256:EECDH+ECDSA+3DES:EECDH+aRSA+3DES:RSA+3DES:!MD5;
	ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
	root /usr/share/nginx/html;
	
	location "$path" {
		proxy_redirect off;
		proxy_pass http://127.0.0.1:"$port";
		proxy_http_version 1.1;
		proxy_set_header Upgrade "'"$http_upgrade"'";
		proxy_set_header Connection '"'upgrade'"';
		proxy_set_header Host "'"$http_host"'";
	}
}
" > $nginxConfig


# 配置v2ray,执行如下命令即可添加v2ray配置文件
echo '
{
  "log" : {
    "access": "/var/log/v2ray/access.log",
    "error": "/var/log/v2ray/error.log",
    "loglevel": "warning"
  },
  "inbound": {
    "port": '$port',
    "listen": "127.0.0.1",
    "protocol": "vmess",
    "settings": {
      "decryption":"none",
      "clients": [
        {
          "id": '"\"$uuid\""',
          "level": 1
        }
      ]
    },
   "streamSettings":{
      "network": "ws",
      "wsSettings": {
           "path": '"\"$path\""'
      }
   }
  },
  "outbound": {
    "protocol": "freedom",
    "settings": {
      "decryption":"none"
    }
  },
  "outboundDetour": [
    {
      "protocol": "blackhole",
      "settings": {
        "decryption":"none"
      },
      "tag": "blocked"
    }
  ],
  "routing": {
    "strategy": "rules",
    "settings": {
      "decryption":"none",
      "rules": [
        {
          "type": "field",
          "ip": [ "geoip:private" ],
          "outboundTag": "blocked"
        }
      ]
    }
  }
}
' > $v2rayConfig


# 默认配置vmess协议,如果指定vless协议则配置vless协议
[ "vless" = "$2" ] && sed -i 's/vmess/vless/' $v2rayConfig


# 重启v2ray和nginx
systemctl restart v2ray
systemctl status -l v2ray
/usr/sbin/nginx -t && systemctl restart nginx


# 输出配置信息
echo
echo "域名: $domainName"
echo "端口: 443"
echo "UUID: $uuid"
[ "vless" = "$2" ] && echo "协议:vless" || echo "额外ID: 0"
echo "安全: tls"
echo "传输: websocket"
echo "路径: $path"

对比该批处理和第一部分的手动纯净安装内容你会发现,哟,内容基本都是一样的吗???

没错,以“#”开头的都是注释,你完全可以把第一部分的内容当作脚本的内容复制粘贴到你的命令行终端 执行即可

唯一的区别就是:一键批处理后面跟上你的域名,而手动安装需要手动设置你的域名。没错,就是这样简单,还在等什么?赶快开一台测试机试试手吧,你也可以成为安乐侯!

我所做的就是整合了那些可以命令执行的操作到批处理里,方便快速部署配置,而不用再手动操作每一个步骤那么麻烦!!!

现在开始,丢掉你每次一行一行执行命令的烦恼,快来试试吧~

声明:

本批处理开源,任何人都可以拿去修改,再发!

另外对批处理感兴趣的朋友,这是一个入门学习的好材料哦

项目地址: https://github.com/HappyLife-page/v2ray
转载地址: https://www.happylife.page/2021/05/14/v2ray纯净部署之vmess/
参考文档: https://tlanyan.pp.ua/v2ray-traffic-mask/