v2ray完全使用教程

V2Ray 项目是一个免费的跨平台工具,可以助你加密网络流量,绕过网络供应商的干扰。

这是一个较新的上网工具,主要目的就是上谷歌、推特等网站。由于在今天推出的新版本支持shadowsocks协议,暂时弥补了目前没有手机端的缺陷。这个工具目前还比较小众,所以不会成为研究对象,也正因为比较小众,目前还没有比较多而详细的教程供参考,所以就提高了初学者使用门槛。这里写下我的搭建过程供后人参考。

需要工具:
  • vps一台
  • 加油+努力+勇气
一、服务端搭建过程

这里列出主要过程,下面是详细解说:

wget 下载链接
unzip v2ray*.zip
cd v2ray*
chmod +x v2ray
./v2ray -config vpoint_vmess_freedom.json

首先ssh连接上自己的vps,然后到这里找到适合自己vps的版本,直接在下载链接上右键复制链接。然后切回ssh窗口,输入命令 wget 粘贴之前复制的链接进行下载,下载完成后使用 unzip xxx.zip以解压文件。使用cd命令进入解压出的文件夹。

首先使用vim vpoint_vmess_freedom.json命令编辑配置文件,其实id和端口换不换都可以,如果想要换掉id可以通过Online UUID Generator这给网站生成。

不过想要需要支持shadownsocks,还需要再进行配置。顺便一提,shadowsocks的端口配置支持1000-1010这种的多端口配置。可以参考官方文档shadoowsocks配置样例

  "inboundDetour": [
    {
      "protocol": "shadowsocks",   // 开启 Shadowsocks
      "port": 30001, // 监听 30001 端口
      "settings": {
        "method": "aes-256-cfb", // 加密方式,支持 aes-256-cfb 和 aes-128-cfb
        "password": "v2ray",     // 密码,必须和客户端相同
        "udp": false             // 是否开启 UDP 转发
      }
    },
  ],

注意需要删掉注释,然后把这段配置粘贴进配置文件中,端口、密码可以适当修改。修改好后保存,使用chmod +x v2ray给它加上执行权限,这样就完成了。之后可以通过./v2ray -h查看使用方法,或者直接通过 sudo ./v2ray -config vpoint_vmess_freedom.json执行就成了。不过这样在关闭ssh窗口时,v2ray也就关闭了,所以需要让它维持后台运行。这里的官方教程讲的非常详细,

sudo vim /etc/init.d/v2ray #创建配置文件并粘贴下列内容  
#!/bin/sh
### BEGIN INIT INFO
# Provides:          v2ray
# Required-Start:    $network $local_fs $remote_fs
# Required-Stop:     $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: socksv5 based proxy written by go.
# Description:       v2ray is a socksv5 proxy written by go. Connection can be crypto by aes or
#            des. this might help for people in China to corss GFW.
### END INIT INFO

# Author: Shell Xu <shell909090@gmail.com>
# Modify: Isulew Li <netcookies@gmail.com>

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin  
DESC=v2ray             # Introduce a short description here  
NAME=v2ray             # Introduce the short server's name here  
DAEMON=/usr/bin/v2ray  #这里改成v2ray程序的完整位置  
PIDFILE=/var/run/$NAME.pid  
LOGFILE=/var/log/$NAME.log  
SCRIPTNAME=/etc/init.d/$NAME

DAEMON_OPTS="-config /etc/v2ray/config.json" #这里改成配置文件完整位置

# Exit if the package is not installed
[ -x $DAEMON ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()  
{
    # Return
    #   0 if daemon has been started
    #   1 if daemon was already running
    #   2 if daemon could not be started
    #   3 if configuration file not ready for daemon
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
        || return 1
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --background \
         --no-close -m -- $DAEMON_OPTS >> $LOGFILE 2>&1 \
        || return 2
    chmod -f 600 $LOGFILE
    # Add code here, if necessary, that waits for the process to be ready
    # to handle requests from services started subsequently which depend
    # on this one.  As a last resort, sleep for some time.
}

#
# Function that stops the daemon/service
#
do_stop()  
{
    # Return
    #   0 if daemon has been stopped
    #   1 if daemon was already stopped
    #   2 if daemon could not be stopped
    #   other if a failure occurred
    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
    RETVAL="$?"
    [ "$RETVAL" = 2 ] && return 2
    # Wait for children to finish too if this is a daemon that forks
    # and if the daemon is only ever run from this initscript.
    # If the above conditions are not satisfied then add some other code
    # that waits for the process to drop all resources that could be
    # needed by services started subsequently.  A last resort is to
    # sleep for some time.
    start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
    [ "$?" = 2 ] && return 2
    # Many daemons don't delete their pidfiles when they exit.
    rm -f $PIDFILE
    return "$RETVAL"
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {  
    #
    # If the daemon can reload its configuration without
    # restarting (for example, when it is sent a SIGHUP),
    # then implement that here.
    #
    start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE
    return 0
}

case "$1" in  
  start)
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
    do_start
    case "$?" in
        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
  ;;
  stop)
    [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
    do_stop
    case "$?" in
        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
  status)
       status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
       ;;
  reload|force-reload)
    #
    # If do_reload() is not implemented then leave this commented out
    # and leave 'force-reload' as an alias for 'restart'.
    #
    log_daemon_msg "Reloading $DESC" "$NAME"
    do_reload
    log_end_msg $?
    ;;
  restart|force-reload)
    #
    # If the "reload" option is implemented then remove the
    # 'force-reload' alias
    #
    log_daemon_msg "Restarting $DESC" "$NAME"
    do_stop
    case "$?" in
      0|1)
        do_start
        case "$?" in
            0) log_end_msg 0 ;;
            1) log_end_msg 1 ;; # Old process is still running
            *) log_end_msg 1 ;; # Failed to start
        esac
        ;;
      *)
        # Failed to stop
        log_end_msg 1
        ;;
    esac
    ;;
  *)
    #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
    echo "Usage: $SCRIPTNAME {start|stop|status|reload|restart|force-reload}" >&2
    exit 3
    ;;
esac

在配置的/etc/init.d/v2ray中只需要修改两个地方就可以了,一个是主程序位置,一个是配置文件位置,都需要使用绝对位置。DAEMON=/usr/bin/v2ray这里填入主程序位置,假如自己的程序在/home/xxx/v2ray/v2ray中,需要 完整填入,这里的前一个v2ray为文件夹名,后一个v2ray为程序名。然后在DAEMON_OPTS="-config /etc/v2ray/config.json"这行后面的位置改成自己的配置文件位置,就变成了DAEMON_OPTS="-config /home/xxx/v2ray/vpoint_vmess_freedom.json

官方的示例配置还告诉了如何使用shadowsocks协议以及各种其他协议使用方法。可以选择性的配置。

二、客户端的使用

这里主要就是从之前的下载v2ray服务端的网站,下载windows抑或是其他适合自己目前系统的客户端(客户端和服务端是一体的)。在配置中如果没其他变动,配置文件中也就改个ip就能用了,原本Id也需要相同,但是如果服务端没有修改是默认的,那么客户端也无需修改。之后在浏览器也需要个扩展插件配合,chrome的扩展omega或者firefox的autoproxy,其中配置成socks 127.0.0.1:1080就好了。

如果在服务端配置中还加上了shadowsocks的支持,那么也可以直接使用shadowsocks的客户端。

相关网站:

v2ray官网:https://www.v2ray.com/
v2ray github:https://github.com/v2ray/v2ray-core

 

原文:http://www.chinagfw.org/2016/02/v2ray.html

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s