讲的非常详细,
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 <[email protected]> # Modify: Isulew Li <[email protected]> # 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 。
配置好保存后需要:
sudo chmod +x /etc/init.d/v2ray #更改权限 sudo update-rc.d v2ray defaults #设置开机启动
官方的示例配置还告诉了如何使用shadowsocks协议以及各种其他协议使用方法。可以选择性的配置。
二、客户端的使用
这里主要就是从之前的下载v2ray服务端的网站,下载windows抑或是其他适合自己目前系统的客户端(客户端和服务端是一体的)。在配置中如果没其 他变动,配置文件中也就改个ip就能用了,原本Id也需要相同,但是如果服务端没有修改是默认的,那么客户端也无需修改。之后在浏览器也需要个扩展插件配 合,chrome的扩展 omega或者firefox的autoproxy,其中配置成socks 127.0.0.1:1080就好了。
如果在服务端配置中还加上了shadowsocks的支持,那么也可以直接使用shadowsocks的客户端。
三、遇到什么问题?
1)vps硬盘被v2ray的日志占满了。Gy1免费翻墙网
/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",
修改保存后可以取消输出日志。我知道,这并不是一个好办法,不过可以暂时解决问题。
来源:https://www.v2ray.com/blog/2016/one-year.htmlGy1免费翻墙网
2/2 首页 上一页 1 2
|