V2Ray完全使用教程
V2Ray完全使用教程
V2Ray是一个优秀且开源的网络代理工具,可以帮助你自由的使用互联网,目前已经全平台支持Windows、Mac、Android、IOS、Linux等操作系统的使用。相对起Shadowsocks来说属于后起之秀,在混淆能力、兼容性、速度上有着独到的优点。
一、V2Ray介绍
新加入流式传输协议mKCP,可以有效的提升传输速度。作者更新非常勤快,相信在今后可以带来更多令人期待的新特性,使V2Ray的性能和安全性得到不断提升。对此感兴趣的可以可以去GitHub Star V2Ray-core这个项目,也可以捐助鼓励开发者更积极的工作。
V2Ray的运行需要服务端和客户端的相互支持,所以也就需要安装配置服务端和客户端,这个过程并不是很简单,需要付出你的一点点努力才能完成,所以我在这里分享出我的使用经验,与君共勉。
所需工具:
- 境外VPS
- 加油+努力
二、服务端搭建过程
2-1自动安装脚本(推荐)
目前自动安装脚本支持所有主流系统,只需一行命令即可完成安装过程,当你想要更新V2Ray的时候同样只需要运行下面一行命令即可。
bash <(curl -L -s https://install.direct/go.sh)
运行以上命令需要root权限,所以请切换到root账户下运行。该脚本会自动安装
unzip
和deamon
,并自动安装以下两个文件:
脚本安装完成无误后,可以进行如下操作:
- 编辑
vim /etc/v2ray/config.json
文件来配置你需要的代理方式; - 运行
service v2ray start
来启动 V2Ray 进程; - 之后可以使用
service v2ray start|stop|status|reload|restart|force-reload
控制 V2Ray 的运行。
以上命令均需要root权限。对于第一步编辑配置文件,可以偷懒不进行改动,不过最好改动一下端口以及ID,改动ID是为了安全不被盗用,改动端口为三位数或更少,对速度有所改善(最好改为80、443端口)。若需要配置Shadowscoks代理,则需要进一步配置,可以参考下面章节 1-2手动安装中的部分。
2-2手动安装
如果你不能使用自动安装或者安装失败,那么可以尝试手动安装,这里列出主要过程,并附上详细说明(这里的配置文件“
vpoint_vmess_freedom.json
”对应自动安装脚本中的/etc/v2ray/config.json
,二者完全相同):$ wget 下载链接 $ unzip v2ray*.zip $ cd v2ray* $ chmod +x v2ray $ ./v2ray -config vpoint_vmess_freedom.json
首先SSH连接上自己的VPS,然后到Releases找到适合自己VPS系统的版本,在下载链接上右键复制链接。然后切回SSH窗口,输入命令
wget 下载链接
进行下载,下载完成后使用 unzip xxx.zip
以解压文件,接着使用 cd v2ray*
命令进入解压出的文件夹。
首先使用
vim vpoint_vmess_freedom.json
命令编辑配置文件,其实ID和端口如果图省事可以不换(大雾),如果想要换掉ID可以使用Online UUID Generator这个网站生成。注:服务端的ID需要和客户端保持一致。
不过想要需要支持Shadownsocks,还需要再进行配置。顺便一提,Shadowsocks的端口配置支持1000-1010这种形式的多端口配置。可以参考官方文档Shadoowsocks配置样例。
"inboundDetour": [ { "protocol": "shadowsocks", "port": 30001, // 监听 30001 端口 "settings": { "method": "aes-256-cfb", "password": "v2ray", // 密码,必须和客户端相同 "udp": false // 是否开启 UDP 转发 } } ],
注意在使用时需要删掉注释,接着把这段配置粘贴进配置文件中,端口、密码可以适当修改。修改好后保存,使用
chmod +x v2ray
给它加上执行权限,之后可以通过./v2ray -h
查看使用方法,或者直接通过 sudo ./v2ray -config vpoint_vmess_freedom.json
执行就成了。
Shadowsocks支持的加密方法有aes-256-cfb、aes-128-cfb、chacha20(推荐)、chacha20-ietf。
到这里还没有完全完成,因为在关闭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 hereDAEMON=/usr/bin/v2ray
#这里改成v2ray程序的绝对路径 PIDFILE=/var/run/$NAME.pid LOGFILE=/var/log/$NAME.log SCRIPTNAME=/etc/init.d/$NAMEDAEMON_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
。
配置好保存后需要执行下面两条命令使配置生效:
sudo chmod +x /etc/init.d/v2ray #更改权限 sudo update-rc.d v2ray defaults #设置开机启动
三、客户端的使用
3-1Windows
这里主要就是从之前的下载V2Ray服务端的网站,下载Windows抑或是其他适合自己目前系统的客户端(客户端和服务端是一体的),你也可以下载使用带有图形化界面的第三方客户端。在配置中如果没其他变动,配置文件中也就改个IP就能用了,原本IP也需要相同,但是如果服务端没有修改是默认的,那么客户端也无需修改。之后在浏览器也需要个扩展插件配合,Chrome的扩展Omega或者Firefox的Autoproxy,其中配置成socks 127.0.0.1:1080就好了。如果在服务端配置中还加上了Shadowsocks的支持,那么也可以直接使用Shadowsocks的客户端。
3-2安卓Android
开头就已经提到了,安卓上已经出了Actinium和实验版本的V2Ray这两个相关客户端了,可以直接去Google Play下载安装,附图:
我目前只使用Actinium所以讲述这款APP的使用方法,可惜目前两款APP均未实现图形化配置,所以需要下载Windows端的V2Ray,修改
config.json
中的ID、IP等配置后保存,若此配置可以在电脑端使用,就可以把此配置传输到手机中,打开之前安装好的APP Actinium,点击右上角打开菜单选择添加配置,通过文件管理器找到自己刚刚传送的配置文件后确认,命名后就可以起飞上网了~All done!四、遇到什么问题?
1)vps硬盘被v2ray的日志占满了。
/var/log/v2ray/error.log的日志文件过大,这个不确定是否是普遍性的问题,但是我确实遇到过,可以通过修改
/var/log/v2ray/error.log的日志文件过大,这个不确定是否是普遍性的问题,但是我确实遇到过,可以通过修改
/etc/v2ray/config.json
中的"log" : { "access": "/var/log/v2ray/access.log", "error": "/var/log/v2ray/error.log",
删除error,成下列内容:
"log" : { "access": "/var/log/v2ray/access.log", "": "/var/log/v2ray/error.log",
修改保存后可以取消输出日志。我知道,这并不是一个好办法,不过可以暂时解决问题。
0 评论: