主页 > 路由器 > V2ray编译及定制

V2ray编译及定制

2018年10月7日 V2ray编译及定制有2条评论 阅读: 250 次

编译环境:

Ubuntu 16.04 64位系统,需国外机器或加代理

1、安装 golang
go语言的下载地址:https://golang.org/dl/
curl -o go_latest.tar.gz -L https://dl.google.com/go/go1.11.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go_latest.tar.gz
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go

2、下载 V2Ray 源文件
go get -u v2ray.com/core/...
go get -u v2ray.com/ext/...

3、编译 V2Ray
go install v2ray.com/ext/tools/build/vbuild
$GOPATH/bin/vbuild
如果要交叉编译,需加上平台参数
$GOPATH/bin/vbuild -os=linux -arch=arm
$GOPATH/bin/vbuild -os=linux -arch=mips
$GOPATH/bin/vbuild -os=linux -arch=mipsle

V2Ray 程序及配置文件会被放在 $GOPATH/bin/v2ray-XXX

4、精简
修改$GOPATH/src/v2ray.com/core/main/distro/all/all.go文件

只留必要的配置

package all
 
import (
	// The following are necessary as they register handlers in their init functions.
 
	// Required features. Can't remove unless there is replacements.
	_ "v2ray.com/core/app/dispatcher"
	_ "v2ray.com/core/app/proxyman/inbound"
	_ "v2ray.com/core/app/proxyman/outbound"
 
	// Default commander and all its services. This is an optional feature.
	//_ "v2ray.com/core/app/commander"
	//_ "v2ray.com/core/app/log/command"
	//_ "v2ray.com/core/app/proxyman/command"
	//_ "v2ray.com/core/app/stats/command"
 
	// Other optional features.
	//_ "v2ray.com/core/app/dns"
	_ "v2ray.com/core/app/log"
	_ "v2ray.com/core/app/policy"
	_ "v2ray.com/core/app/router"
	//_ "v2ray.com/core/app/stats"
 
	// Inbound and outbound proxies.
	//_ "v2ray.com/core/proxy/blackhole"
	_ "v2ray.com/core/proxy/dokodemo"
	_ "v2ray.com/core/proxy/freedom"
	//_ "v2ray.com/core/proxy/http"
	//_ "v2ray.com/core/proxy/mtproto"
	//_ "v2ray.com/core/proxy/shadowsocks"
	_ "v2ray.com/core/proxy/socks"
	//_ "v2ray.com/core/proxy/vmess/inbound"
	_ "v2ray.com/core/proxy/vmess/outbound"
 
	// Transports
	//_ "v2ray.com/core/transport/internet/domainsocket"
	//_ "v2ray.com/core/transport/internet/http"
	//_ "v2ray.com/core/transport/internet/kcp"
	_ "v2ray.com/core/transport/internet/tcp"
	//_ "v2ray.com/core/transport/internet/tls"
	//_ "v2ray.com/core/transport/internet/udp"
	//_ "v2ray.com/core/transport/internet/websocket"
 
	// Transport headers
	_ "v2ray.com/core/transport/internet/headers/http"
	//_ "v2ray.com/core/transport/internet/headers/noop"
	_ "v2ray.com/core/transport/internet/headers/srtp"
	_ "v2ray.com/core/transport/internet/headers/tls"
	_ "v2ray.com/core/transport/internet/headers/utp"
	_ "v2ray.com/core/transport/internet/headers/wechat"
	//_ "v2ray.com/core/transport/internet/headers/wireguard"
 
	// JSON config support. Choose only one from the two below.
	// The following line loads JSON from v2ctl
	//_ "v2ray.com/core/main/json"
	// The following line loads JSON internally
	 _ "v2ray.com/core/main/jsonem"
 
	// Load config from file or http(s)
	_ "v2ray.com/core/main/confloader/external"
)

此配置可以不用v2ctl程序,直接从json文件读取配置:
//_ "v2ray.com/core/main/json"
// The following line loads JSON internally
_ "v2ray.com/core/main/jsonem"

各模块架构如图:

然后用上一步的方法重新编译,编译后的二进制文件用upx压缩

如果本文对你有帮助,请打赏作者,鼓励我们继续写作!

评论:2

  1. rhotov 回复
    2018年10月7日 于 下午6:36

    刚才测试了一下,2.4G单核的小鸡作服务器,mkcp协议,客户端开个youtube 4K视频,服务器CPU直接飙到90%-满载了 。

    • ywb 回复
      2018年10月8日 于 上午9:50

      瓶颈一般在路由器,除非你的服务器太弱

发表评论

电子邮件地址不会被公开。 必填项已用*标注