[success]最近太多梯子被封,本人的也不幸免。现在SSR或者SS已经越来越不稳定,迫切需要新的技术。所以我把目光转向了v2ray。废话不多说,直接开始教程[/success]
目前有很多一键安装的脚本,这里我不多说,自己可以去网上找找,我这里直接进行手动安装,锻炼一下自己的linux能力。
下载安装包
我们到作者的Releases那里下载安装包
我们需要先查询CPU型号和系统位数
查询型号:
cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
我的是虚拟的cpu
判断位数:
getconf LONG_BIT
这里会返回位数,我的是64位系统。
好的,我们开始安装,安装前先复制一下你需要的下载链接然后按照下面的步骤
[highlight lanaguage=”bash”]
$ wget 下载链接 $ unzip v2ray*.zip $ cd v2ray* $ cp vpoint_vmess_freedom.json config.json $ sudo mkdir -p /var/log/v2ray/ $ sudo ./v2ray
[/highlight]
我这里解压后没有文件夹所以不需要切换文件夹,大家可以根据自己的情况进行选择。
如果出现下面的,说明安装成功
配置文件
我们下面配置一下v2ray[highlight lanaguage=”bash”]
vim config.json
[/highlight]
配置之前我们先获取一下ID。当然你也可以不换(不过不建议)
大家把下面的ID复制一下
放到配置文件里面
当然v2ray还支持配置shadowsocket。下面是简单的配置示例。大家把下面的代码插入到配置文件里面就可以了。
这里注意一下json数据的完整性
[highlight lanaguage=”bash”]
"inboundDetour": [
{
"protocol": "shadowsocks",
"port": 30001, // 监听 30001 端口
"settings": {
"method": "aes-256-cfb",
"password": "v2ray", // 密码,必须和客户端相同
"udp": false // 是否开启 UDP 转发
}
}
],
[/highlight]
修改完成后我们继续运行。
永久运行
大家创建配置文件然后复制下面的内容我这里直接用的别人写好的脚本。
[highlight lanaguage=”bash”]
$ 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
[/highlight]
修改好后我们可以用下面的命令使配置生效
[highlight lanaguage=”bash”]
sudo chmod +x /etc/init.d/v2ray #更改权限 sudo update-rc.d v2ray defaults #设置开机启动
[/highlight]
我们可以使用下面两条命令来开启或关闭v2ray
[highlight lanaguage=”bash”]
sudo systemctl stop v2ray sudo systemctl restart v2ray
[/highlight]
如果前面的脚本没用,我们可以使用SYSTEMD 启动方式
[highlight lanaguage=”bash”]
#编辑文件 sudo vim /etc/systemd/system/v2ray.service #编写下面的内容
[Unit] Description=V2ray deamon [Service] Type=simple ExecStart=/home/username/project/v2ray/v2ray[Install] WantedBy=multi-user.target #下面我们修改程序的路径,路径为绝对路径
sudo systemctl enable v2ray sudo systemctl daemon-reload sudo systemctl start v2ray #我们可以使用下面命令启动
sudo systemctl stop v2ray sudo systemctl restart v2ray
[/highlight]