64M内存VPS利用手札:(三)debian下安装v2ray模块化代理软件包


对,还是上次那台64M内存的小鸡,之前已经安装了shadowsocks-libev和Kcptun,详见64M内存VPS利用手札:(一)安装shadowsocks-libev64M内存VPS利用手札:(二)debian下安装Kcptun加速SS服务 。为了有个保障,或者说我只是为了压榨性能而已,我决定再装一套v2ray 在上面。

一、什么是v2ray?

V2Ray 是一个开源的模块化的代理软件包,它的目标是提供常用的代理软件模块,简化网络代理软件的开发。相对SS来说,这是一个比较小众的软件,但从另外的角度来说:小众=安全。

二、有啥特色?

  • 更完善的协议: V2Ray 使用了新的自行研发的 VMess 协议,改进了 Shadowsocks 一些已有的缺点,更难被墙检测到
  • 更强大的性能: 相对于 Shadowsocks,V2Ray 的网络性能更好,具体数据可以看官方博客
  • 更丰富的功能: V2Ray 比起 Shadowsocks 多了许多功能,以下是部分 V2Ray 的功能
    1. mKCP: V2Ray 的 KCP 协议实现,不必另行安装 kcptun
    2. 动态端口:动态改变通信的端口,对抗对长时间大流量端口的限速封锁
    3. 路由功能:可以随意设定指定数据包的流向
    4. 传出代理:看名字可能不太好理解,其实差不多可以称之为多重代理。类似于 Tor 的代理
    5. 数据包伪装:类似于 Shadowsocks-rss 的混淆,另外对于 mKCP 的数据包也可伪装
    6. WebSocket 协议:可以 PaaS 平台搭建V2Ray,通过 websocket 代理。也可以通过它使用 cdn(如 cloudflare) 中转。

三、服务器端安装V2RAY

1、校对时间

对于 V2Ray,它的验证方式包含时间,就算是配置没有任何问题,如果时间不正确,也无法连接 V2Ray 服务器的,服务器会认为你这是不合法的请求。所以系统时间一定要正确,只要保证时间误差在一分钟之内就没问题。

$ date -R
Thu, 25 May 2017 04:49:52 -0400

查看自己的vps时间和本地时间是否一致,如上-0400明显不对。

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

再次查看,如果时间和本地时间差距过大,请自行修改或者同步。

root@gfw:~# date -R
Thu, 25 May 2017 16:52:26 +0800

2、安装v2ray

目前官方已经有一键安装脚本了,所以安装相当方便

wget https://raw.githubusercontent.com/v2ray/v2ray-core/master/release/install-release.sh
chmod +x install-release.sh
./install-release.sh

当然你也可以手动安装或者编译安装,详见官方安装手册

3、服务端配置文件

编辑配置文件config.json

vim /etc/v2ray/config.json
{
    "log": {
        "access": "/var/log/v2ray/access.log", // 访问日志
        "error": "/var/log/v2ray/error.log", // 错误日志
        "loglevel": "warning" // 日志等级, 警告
    },
    "inbound": {
        "port": 37192, // 服务器监听端口
        "protocol": "vmess", // 主传出协议,参见协议列表
        "settings": {
            "clients": [
                {
                    "id": "e136b929-5837-4fae-b3c2-bcf6b00dac71", // 用户 ID,客户端与服务器必须相同
                    "level": 1, // 用户等级,自用 VPS 可设为 1;共享 VPS 请设为 0。
                    "alterId": 64 // 与客户端相同
                }
            ]
        }
    },
    "outbound": {
        "protocol": "freedom", // 主传出协议,参见协议列表
        "settings": {}
    },
    "outboundDetour": [
        {
            "protocol": "blackhole", // 主传出协议,参见协议列表
            "settings": {},
            "tag": "blocked"
        }
    ],
    "routing": {
        "strategy": "rules",
        "settings": {
            "rules": [
                {
                    "type": "field",
                    "ip": [
                        "0.0.0.0/8",
                        "10.0.0.0/8",
                        "100.64.0.0/10",
                        "127.0.0.0/8",
                        "169.254.0.0/16",
                        "172.16.0.0/12",
                        "192.0.0.0/24",
                        "192.0.2.0/24",
                        "192.168.0.0/16",
                        "198.18.0.0/15",
                        "198.51.100.0/24",
                        "203.0.113.0/24",
                        "::1/128",
                        "fc00::/7",
                        "fe80::/10"
                    ],
                    "outboundTag": "blocked"
                }
            ]
        }
    },
    "transport": {
        "kcpSettings": {
            "uplinkCapacity": 2,
            "downlinkCapacity": 10
        }
    }
}

如需要使用shadowsocks协议,请查考下面的配置文件

{
    "log": {
        "access": "/var/log/v2ray/access.log", // 访问日志文件
        "error": "/var/log/v2ray/error.log", // 错误日志文件
        "loglevel": "warning" // 错误日志等级,可选 debug / info / warning / error
    },
    "inbound": {
        "port": 37192, // 监听 30002 端口,由于 Shadowsocks 的限制,多用户的时候只能开多个端口
        "protocol": "vmess", // 额外的传出协议,参见协议列表
        "settings": { // 配置和上述类似
            "clients": [
                {
                    "id": "e136b929-5837-4fae-b3c2-bcf6b00dac71", // 用户 ID,客户端须使用相同的 ID 才可以中转流量
                    "level": 1 // 用户等级,自用 VPS 可设为 1;共享 VPS 请设为 0。
                }
            ]
        }
    },
    "outbound": {
        "protocol": "freedom", // 额外的传出协议,参见协议列表
        "settings": {} // 配置和上述类似
    },
    "inboundDetour": [ // 扩展的传入连接
        {
            "protocol": "shadowsocks", // 额外的传出协议,参见协议列表
            "port": 30001, // 监听 30002 端口,由于 Shadowsocks 的限制,多用户的时候只能开多个端口
            "settings": { // 配置和上述类似
                "method": "aes-256-cfb", // 加密方式,支持 aes-256-cfb 和 aes-128-cfb
                "password": "awy.me", // 密码,必须和客户端相同
                "udp": false // 是否开启 UDP 转发
            }
        },
        {
            "protocol": "shadowsocks", // 额外的传出协议,参见协议列表
            "port": 30002, // 监听 30002 端口,由于 Shadowsocks 的限制,多用户的时候只能开多个端口
            "settings": { // 配置和上述类似
                "method": "aes-256-cfb", // 加密方式,支持 aes-256-cfb 和 aes-128-cfb
                "password": "awy.me-2", // 密码,必须和客户端相同
                "udp": false // 是否开启 UDP 转发
            }
        }
    ],
    "outboundDetour": [
        {
            "protocol": "blackhole", // 额外的传出协议,参见协议列表
            "settings": {}, // 配置和上述类似
            "tag": "blocked"
        }
    ],
    "routing": {
        "strategy": "rules",
        "settings": { // 配置和上述类似
            "rules": [
                {
                    "type": "field", // 路由设置,默认将屏蔽所有局域网流量,以提升安全性。
                    "ip": [
                        "0.0.0.0/8",
                        "10.0.0.0/8",
                        "100.64.0.0/10",
                        "127.0.0.0/8",
                        "169.254.0.0/16",
                        "172.16.0.0/12",
                        "192.0.0.0/24",
                        "192.0.2.0/24",
                        "192.168.0.0/16",
                        "198.18.0.0/15",
                        "198.51.100.0/24",
                        "203.0.113.0/24",
                        "::1/128",
                        "fc00::/7",
                        "fe80::/10"
                    ],
                    "outboundTag": "blocked"
                }
            ]
        }
    }
}

其中你随意修改端口,如果想要修改 ID,可以访问这个网站生成:https://www.uuidgenerator.net/ ,建议使用其中的V4版。

修改完后需要重启服务。

4、使用命令

保存配置文件后就可以启动服务了。

service v2ray start    //启动命令
service v2ray restart  //重启命令
service v2ray stop     //停止命令

四、客户端配置

和kcptun一样,首先下载v2ray核心软件:https://github.com/v2ray/v2ray-core/releases

请根据自己终端需求选择对应的版本。

然后下载三方客户端,推荐v2ray-taskbar。

解压到同一文件夹

然后打开config.json进行客户端配置

{
    "inbound": {
        "port": 1080, // 服务器端口
        "listen": "127.0.0.1",
        "protocol": "socks", // 额外的出口协议。Freedom 协议为直连模式,不经过服务器中转。
        "settings": {
            "auth": "noauth", // 不认证
            "udp": false, // 不开启udp转发
            "ip": "127.0.0.1"
        }
    },
    "outbound": {
        "protocol": "vmess", // 额外的出口协议。Freedom 协议为直连模式,不经过服务器中转。
        "settings": {
            "vnext": [
                {
                    "address": "8.8.8.8", // 服务器地址
                    "port": 17173, // 服务器端口
                    "users": [
                        {
                            "id": "e136b929-5837-4fae-b3c2-bcf6b00dac71", // 用户 ID,须与服务器端配置相同
                            "alterId": 64, // 与服务端一致
                            "security": "auto"
                        }
                    ]
                }
            ]
        },
        "mux": {
            "enabled": true
        }
    },
    "outboundDetour": [
        {
            "protocol": "freedom", // 额外的出口协议。Freedom 协议为直连模式,不经过服务器中转。
            "settings": {},
            "tag": "direct" // 标签,在路由中用到
        }
    ],
    "dns": {
        "servers": [
            "8.8.8.8",
            "8.8.4.4",
            "localhost"
        ]
    },
    "routing": {
        "strategy": "rules",
        "settings": {
            "domainStrategy": "IPIfNonMatch",
            "rules": [
                {
                    "type": "field",
                    "port": "1-52", // 服务器端口
                    "outboundTag": "direct"
                },
                {
                    "type": "field",
                    "port": "54-79", // 服务器端口
                    "outboundTag": "direct"
                },
                {
                    "type": "field",
                    "port": "81-442", // 服务器端口
                    "outboundTag": "direct"
                },
                {
                    "type": "field",
                    "port": "444-65535", // 服务器端口
                    "outboundTag": "direct"
                },
                {
                    "type": "chinasites",
                    "outboundTag": "direct"
                },
                {
                    "type": "field",
                    "ip": [
                        "0.0.0.0/8",
                        "10.0.0.0/8",
                        "100.64.0.0/10",
                        "127.0.0.0/8",
                        "169.254.0.0/16",
                        "172.16.0.0/12",
                        "192.0.0.0/24",
                        "192.0.2.0/24",
                        "192.168.0.0/16",
                        "198.18.0.0/15",
                        "198.51.100.0/24",
                        "203.0.113.0/24",
                        "::1/128",
                        "fc00::/7",
                        "fe80::/10"
                    ],
                    "outboundTag": "direct"
                },
                {
                    "type": "chinaip",
                    "outboundTag": "direct"
                }
            ]
        }
    }
}

运行v2ray-taskbar.exe,显示

V2Ray v2.25 (One for all) 20170427
An unified platform for anti-censorship.
2017/05/25 17:38:29 [Debug]App|Proxyman|Inbound: creating tcp worker on 127.0.0.1:1080
2017/05/25 17:38:29 [Info]Transport|Internet|TCP: listening TCP on 127.0.0.1:1080
2017/05/25 17:38:29 [Warning]Core: V2Ray started

之后浏览器等客户端就可以调用该socks5协议代理了,不会的可以参考用SSH开眼看世界 ,至于添加shadowsocks的用法请自行Google。

该套软件功能很强大,还有很多的配置可以设置,具体的请查看官方网站配置指南

至此此64M的VPS上已经安装了三个工具,收工!