统计
  • 文章总数:76 篇
  • 评论总数:18 条
  • 分类总数:19 个
  • 最后更新:10月18日

Linux搭建v2ray服务端

本文阅读 2 分钟
首页 运维 正文

注意:本地时间和服务器时间不能超过90秒,否者不能连接

Linux 官方安装脚本,不支持centos 6

bash <(curl https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)

美国节点 Linux 安装脚本,支持centos 6,需要自己创建守护服务

bash <(curl -L -s http://mg.cd-sw.com/v2/go.sh)

国内节点 Linux 安装脚本支持centos 6,需要自己创建守护服务

bash <(curl -L -s https://cdn.cd-sw.com/v2/go.sh)

x-ui 面板 可视化面板 一键安装脚本!不支持centos 6

bash <(curl -Ls https://raw.githubusercontent.com/vaxilu/x-ui/master/install.sh)

官方网站:v2ray.com

需要关闭防火墙和启动

v2启动命令

service v2ray start

v2重启

service v2ray restart

centos 6 临时关闭防火墙

service iptables stop

centos 6 永久关闭防火墙

chkconfig iptables off

centos 7 停止firewall防火墙

systemctl stop firewalld.service

centos 7 永久关闭防火墙(推荐)

systemctl disable firewalld.service

卸载方法

service v2ray stop
chkconfig v2ray off
rm -rf /etc/init.d/v2ray
rm -rf /etc/v2ray #(配置文件)
rm -rf /usr/bin/v2ray #(程序)
rm -rf /var/log/v2ray #(日志)

centos 6 安装会报错

问题就是安装脚本在创建守护服务的时候不支持CentOS6

解决办法

将下述代码保存为/etc/init.d/v2ray,并添加执行权限。

#!/bin/sh
#
# v2ray        Startup script for v2ray
#
# chkconfig: - 24 76
# processname: v2ray
# pidfile: /var/run/v2ray.pid
# description: V2Ray proxy services
#
 
### 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: V2Ray proxy services
# Description:       V2Ray proxy services
### END INIT INFO
 
DESC=v2ray
NAME=v2ray
DAEMON=/usr/bin/v2ray/v2ray
PIDFILE=/var/run/$NAME.pid
LOCKFILE=/var/lock/subsys/$NAME
SCRIPTNAME=/etc/init.d/$NAME
RETVAL=0
 
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
 
# Source function library.
. /etc/rc.d/init.d/functions
 
start() {
  local pids=$(pgrep -f $DAEMON)
  if [ -n "$pids" ]; then
    echo "$NAME (pid $pids) is already running"
    RETVAL=0
    return 0
  fi
 
  echo -n $"Starting $NAME: "
 
  mkdir -p /var/log/v2ray
  $DAEMON $DAEMON_OPTS 1>/dev/null 2>&1 &
  echo $! > $PIDFILE
 
  sleep 2
  pgrep -f $DAEMON >/dev/null 2>&1
  RETVAL=$?
  if [ $RETVAL -eq 0 ]; then
    success; echo
    touch $LOCKFILE
  else
    failure; echo
  fi
  return $RETVAL
}
 
stop() {
  local pids=$(pgrep -f $DAEMON)
  if [ -z "$pids" ]; then
    echo "$NAME is not running"
    RETVAL=0
    return 0
  fi
 
  echo -n $"Stopping $NAME: "
  killproc -p ${PIDFILE} ${NAME}
  RETVAL=$?
  echo
  [ $RETVAL = 0 ] && rm -f ${LOCKFILE} ${PIDFILE}
}
 
reload() {
  echo -n $"Reloading $NAME: "
  killproc -p ${PIDFILE} ${NAME} -HUP
  RETVAL=$?
  echo
}
 
rh_status() {
  status -p ${PIDFILE} ${DAEMON}
}
 
# See how we were called.
case "$1" in
  start)
    rh_status >/dev/null 2>&1 && exit 0
    start
    ;;
  stop)
    stop
    ;;
  status)
    rh_status
    RETVAL=$?
    ;;
  restart)
    stop
    start
    ;;
  reload)
    reload
  ;;
  *)
    echo "Usage: $SCRIPTNAME {start|stop|status|reload|restart}" >&2
    RETVAL=2
  ;;
esac
exit $RETVAL

加入开机启动,开启服务,问题彻底解决

chmod a+x /etc/init.d/v2ray
chkconfig v2ray on
service v2ray start
查看配置文件 /etc/v2ray/config.json
参考tcp配置文件(随机无特征的游戏协议流量)
{
        "log": {
                "access": "/var/log/v2ray/access.log",
                "error": "/var/log/v2ray/error.log",
                "loglevel": "warning"
        },
        "inbounds": [
                {
                        "port": 23000,
                        "protocol": "vmess",
                        "settings": {
                                "clients": [
                                        {
                                                "id": "da5c5b2d-06ca-4363-9b4d-3a9e23ce291d",
                                                "level": 1,
                                                "alterId": 64
                                        }
                                ]
                        },
                        "streamSettings": {
                                "network": "tcp"
                        },
                        "sniffing": {
                                "enabled": true,
                                "destOverride": [
                                        "http",
                                        "tls"
                                ]
                        }
                }
                //include_ss
                //include_socks
                //include_mtproto
                //include_in_config
                //
        ],
        "outbounds": [
                {
                        "protocol": "freedom",
                        "settings": {}
                },
                {
                        "protocol": "blackhole",
                        "settings": {},
                        "tag": "blocked"
                },
                {
                        "protocol": "freedom",
                        "settings": {},
                        "tag": "direct"
                },
                {
                        "protocol": "mtproto",
                        "settings": {},
                        "tag": "tg-out"
                }
                //include_out_config
                //
        ],
        "dns": {
                "server": [
                        "8.8.8.8",
                        "1.1.1.1",
                        "localhost"
                ]
        },
        "routing": {
                "domainStrategy": "IPOnDemand",
                "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"
                        },
                        {
                                "type": "field",
                                "inboundTag": ["tg-in"],
                                "outboundTag": "tg-out"
                        }
                        //include_ban_ad
                        //include_rules
                        //
                ]
        },
        "transport": {
                "kcpSettings": {
            "uplinkCapacity": 100,
            "downlinkCapacity": 100,
            "congestion": false
        },
                "sockopt": {
                        "tcpFastOpen": true
                }
        }
}
查看配置文件 /etc/v2ray/config.json
kcp模式配置文件,伪装视频聊天流量(速度快,如果收到错误包会被干扰无法使用)
{
        "log": {
                "access": "/var/log/v2ray/access.log",
                "error": "/var/log/v2ray/error.log",
                "loglevel": "warning"
        },
        "inbounds": [
                {
                        "port": 23000,
                        "protocol": "vmess",
                        "settings": {
                                "clients": [
                                        {
                                                "id": "da5c5b2d-06ca-4363-9b4d-3a9e23ce291d",
                                                "level": 1,
                                                "alterId": 64
                                        }
                                ]
                        },
                        "streamSettings": {
                                "network": "kcp",
                                "kcpSettings": {
                                        "header": {
                                                "type": "wechat-video"
                                        }
                                }
                        },
                        "sniffing": {
                                "enabled": true,
                                "destOverride": [
                                        "http",
                                        "tls"
                                ]
                        }
                }
                //include_ss
                //include_socks
                //include_mtproto
                //include_in_config
                //
        ],
        "outbounds": [
                {
                        "protocol": "freedom",
                        "settings": {}
                },
                {
                        "protocol": "blackhole",
                        "settings": {},
                        "tag": "blocked"
                },
                {
                        "protocol": "freedom",
                        "settings": {},
                        "tag": "direct"
                },
                {
                        "protocol": "mtproto",
                        "settings": {},
                        "tag": "tg-out"
                }
                //include_out_config
                //
        ],
        "dns": {
                "server": [
                        "8.8.8.8",
                        "1.1.1.1",
                        "localhost"
                ]
        },
        "routing": {
                "domainStrategy": "IPOnDemand",
                "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"
                        },
                        {
                                "type": "field",
                                "inboundTag": ["tg-in"],
                                "outboundTag": "tg-out"
                        }
                        //include_ban_ad
                        //include_rules
                        //
                ]
        },
        "transport": {
                "kcpSettings": {
            "uplinkCapacity": 100,
            "downlinkCapacity": 100,
            "congestion": false
        },
                "sockopt": {
                        "tcpFastOpen": true
                }
        }
}
查看配置文件 /etc/v2ray/config.json
ws模式配置文件,伪装工商银行网站访问(更可靠不会被运营商qos)


{
        "log": {
                "access": "/var/log/v2ray/access.log",
                "error": "/var/log/v2ray/error.log",
                "loglevel": "warning"
        },
        "inbounds": [
                {
                        "port": 80,
                        "protocol": "vmess",
                        "settings": {
                                "clients": [
                                        {
                                                "id": "da5c5b2d-06ca-4363-9b4d-3a9e23ce291d",
                                                "level": 1,
                                                "alterId": 64
                                        }
                                ]
                        },
                        "streamSettings": {
                                "network": "ws"
                        },
                        "sniffing": {
                                "enabled": true,
                                "destOverride": [
                                        "http",
                                        "tls"
                                ]
                        }
                }
                //include_ss
                //include_socks
                //include_mtproto
                //include_in_config
                //
        ],
        "outbounds": [
                {
                        "protocol": "freedom",
                        "settings": {}
                },
                {
                        "protocol": "blackhole",
                        "settings": {},
                        "tag": "blocked"
                },
                {
                        "protocol": "freedom",
                        "settings": {},
                        "tag": "direct"
                },
                {
                        "protocol": "mtproto",
                        "settings": {},
                        "tag": "tg-out"
                }
                //include_out_config
                //
        ],
        "dns": {
                "server": [
                        "8.8.8.8",
                        "1.1.1.1",
                        "localhost"
                ]
        },
        "routing": {
                "domainStrategy": "IPOnDemand",
                "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"
                        },
                        {
                                "type": "field",
                                "inboundTag": ["tg-in"],
                                "outboundTag": "tg-out"
                        }
                        //include_ban_ad
                        //include_rules
                        //
                ]
        },
        "transport": {
                "kcpSettings": {
            "uplinkCapacity": 100,
            "downlinkCapacity": 100,
            "congestion": false
        },
                "sockopt": {
                        "tcpFastOpen": true
                }
        }
}

修改后重启生效

service v2ray restart

根据日志查看启动情况

cat /var/log/v2ray/error.log | grep started

或者查看启动进程

top -b -n 1 |grep v2ray

如若转载请注明出处:
-- 展开阅读全文 --
Linux系统宝塔面板一键挂载磁盘
« 上一篇 08-28
换车三保记录
下一篇 » 04-24

发表评论

发表评论