mac 下通过supervisor管理v2ray多线路管理

/ 0评 / 0

我们空余的服务器很多,基本朋友们都会装个出墙的工具.这么多出墙工具之中,Sandy偏爱V2ray

但是服务器多了v2ray core版本不支持多线路怎么办?有些看官说你直接下载个v2rayX什么都能解决.非得整的这么麻烦!V2rayX更新太慢了.....很多新的协议无法支持.最大的问题无法自由的使用json配置文件.好了废话不多说我们来整v2ray core吧!

老规则使用工具先列出来:

masOS系统

Surge/ssr/ss/浏览器插件 Proxy SwitchyOmega (支持scoks5的工具都可以) 本文使用Surge其他自行研究或者联系我

v2ray core

supervisor

东西全了,我们整起来吧!

安装v2ray

brew tap v2ray/v2ray
brew install v2ray-core

如果报没有发现brew命令的话参考brew安装:Brew安装

Brew介绍

Mac下Homebrew安装的软件放在什么地方
一般情况是这么操作的:

1、通过brew install安装应用最先是放在/usr/local/Cellar/目录下。

2、有些应用会自动创建软链接放在/usr/bin或者/usr/sbin,同时也会将整个文件夹放在/usr/local

3、可以使用brew list 软件名确定安装位置。

安装supervisor

brew install supervisor

下面是supervisor的介绍,不想看直接跳过到:开始配置supervisor管理V2ray段落

配置自启动

完成后有如下提示信息

To have launchd start supervisor now and restart at login:
brew services start supervisor # 自动启动
Or, if you don't want/need a background service you can just run:
  supervisord -c /usr/local/etc/supervisord.ini
==> Summary # 安装位置
?  /usr/local/Cellar/supervisor/3.3.4: 541 files, 6.5MB

提示信息已经说的很清楚了:

不想让supervisor作为后台服务随系统启动,可以通过用指定配置文件的方式来启动:

supervisord -c /usr/local/etc/supervisord.ini

如果要让supervisor随系统自启动,用一下命令就可以了:

brew services start supervisor

默认的配置文件:/usr/local/etc/supervisord.ini

设置随系统自动启动

sandyliao @ LSandy-MBP $ brew services start supervisor
==> Tapping homebrew/services
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Counting objects: 12, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 12 (delta 0), reused 7 (delta 0), pack-reused 0
Unpacking objects: 100% (12/12), done.
Tapped 0 formulae (40 files, 54.2KB)
==> Successfully started `supervisor` (label: homebrew.mxcl.supervisor)

其实在安装完成后,已经自动生成了 plist 文件模板,位置在这里:/usr/local/Cellar/supervisor/3.3.4/homebrew.mxcl.supervisor.plist 。

常用命令

supervisor提供的几个可执行文件(链接文件):

sandyliao @ LSandy-MBP $ cd /usr/local/Cellar/supervisor/3.3.4/bin
sandyliao @ LSandy-MBP $ ls
echo_supervisord_conf pidproxy              supervisorctl         supervisord

命令帮助:

# 带上配置文件参数 不然会在进入supervisor的shell的时候提示如下错误
sandyliao @ LSandy-MBP $ supervisorctl
http://localhost:9001 refused connection
supervisor>
sandyliao @ LSandy-MBP $ supervisorctl -c /usr/local/etc/supervisord.ini
supervisor> help

default commands (type help <topic>):
=====================================
add    exit      open  reload  restart   start   tail
avail  fg        pid   remove  shutdown  status  update
clear  maintail  quit  reread  signal    stop    version

supervisor>

####################

sandyliao @ LSandy-MBP $ supervisorctl --help
supervisorctl -- control applications run by supervisord from the cmd line.

Usage: /usr/local/bin/supervisorctl [options] [action [arguments]]

Options:
-c/--configuration FILENAME -- configuration file path (searches if not given)
-h/--help -- print usage message and exit
-i/--interactive -- start an interactive shell after executing commands
-s/--serverurl URL -- URL

echo_supervisord_conf 可以输出配置文件模板。

sandyliao @ LSandy-MBP $ echo_supervisord_conf

[unix_http_server]
file=/usr/local/var/run/supervisor.sock   ; the path to the socket file
;chmod=0700                 ; socket file mode (default 0700)
;chown=nobody:nogroup       ; socket file uid:gid owner
;username=user              ; default is no username (open server)
;password=123               ; default is no password (open server)

;[inet_http_server]         ; inet (TCP) server disabled by default
;port=127.0.0.1:9001        ; ip_address:port specifier, *:port for all iface
;username=user              ; default is no username (open server)
;password=123               ; default is no password (open server)
; ......

经常启停控制

supervisorctl
supervisor> reload
Really restart the remote supervisord process y/N? y
Restarted supervisord
supervisor> start logstash
logstash: started
supervisor> stop logstash

 开始配置supervisor管理V2ray

生成配置文件

vi /usr/local/etc/supervisord.ini

自己的配置文件放在 /usr/local/etc/supervisord.ini

最后加入include设置

[include]
files = /usr/local/etc/supervisor.d/*.ini

/usr/local/etc/supervisor.d目录下新建config-share.ini的配置文件,用于托管这个进程,通过command指令来设置,v2ray的配置文件位于/usr/local/etc/supervisor.d/config/config-share.json,可根据自己需求进行修改!

如果出现无supervisor.d和config目录,请手工建立或者mkdir建立

config-share.ini文件配置说明如下

#[program:配置名称,每一个ini文件都不能重复]
[program:share] 
command=/usr/local/bin/v2ray -config /usr/local/etc/supervisor.d/config-share.json
autostart=true
autorestart=true

confi-share.json文件配置(v2ray客户端配置)

{
    "log": {
        "access": "",
        "error": "",
        "loglevel": ""
    },
    "inbound": {
        "port": 1080,
        "listen": "0.0.0.0",
        "protocol": "socks",
        "settings": {
            "auth": "noauth",
            "udp": true,
            "ip": "127.0.0.1",
            "clients": null
        },
        "streamSettings": null
    },
    "outbound": {
        "tag": "agentout",
        "protocol": "vmess",
        "settings": {
            "vnext": [{
                "address": "地址",
                "port": 端口,
                "users": [{
                    "id": "密码",
                    "alterId": 32,
                    "security": "aes-128-gcm"
                }]
            }]
        },
        "streamSettings": {
            "network": "tcp",
            "security": "",
            "tcpSettings": null,
            "kcpSettings": null,
            "wsSettings": null
        },
        "mux": {
            "enabled": true
        }
    },
    "inboundDetour": null,
    "outboundDetour": [{
            "protocol": "freedom",
            "settings": {
                "response": null
            },
            "tag": "direct"
        },
        {
            "protocol": "blackhole",
            "settings": {
                "response": {
                    "type": "http"
                }
            },
            "tag": "blockout"
        }
    ],
    "dns": {
        "servers": [
            "8.8.8.8",
            "8.8.4.4",
            "localhost"
        ]
    },
    "routing": {
        "strategy": "rules",
        "settings": {
            "domainStrategy": "IPIfNonMatch",
            "rules": [{
                    "type": "field",
                    "port": null,
                    "outboundTag": "direct",
                    "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"
                    ],
                    "domain": null
                },
                {
                    "type": "field",
                    "port": null,
                    "outboundTag": "agentout",
                    "ip": null,
                    "domain": [
                        "ip111.cn"
                    ]
                },
                {
                    "type": "chinasites",
                    "port": null,
                    "outboundTag": "direct",
                    "ip": null,
                    "domain": null
                },
                {
                    "type": "chinaip",
                    "port": null,
                    "outboundTag": "direct",
                    "ip": null,
                    "domain": null
                }
            ]
        }
    }
}

配置文件下载:config-share.json 多个服务器的json文件,请把"port": 1080,端口改成其他,并且surge里面也要对应这个端口

然后输入supervisorctl

# sandyliao @ LSandy-MBP in ~ on git:master x [14:39:14] C:127
$ supervisorctl 
share                        RUNNING   pid 24303, uptime 0:38:15

然后输入reload平滑重新启动

# sandyliao @ LSandy-MBP in ~ on git:master x [14:39:14] C:127
$ supervisorctl 
share                        RUNNING   pid 24303, uptime 0:38:15
supervisor> reload
Really restart the remote supervisord process y/N? y
Restarted supervisord

配置好了之后
supervisorctl reload 重新加载一次配置文件
supervisord 启动supervisor 及得修改完配置文件之后要supervisorctl reload
到这一步 部署就成功了

surge 配置

surge 中配置socks5

选择配置:

多个config配置,请把端口设置成和config一样的端口,不要冲突

在调试过程中经常会出现的问题:

1.config-share.ini是supervisor配置,config-share.json是v2ray配置

2.config-****.ini为多个配置的情况下,里面的program和command要修改相对于的名字

3.config-****.json为多个配置的情况下,本地端口不能一样

4.出现supervisor无法启动,或者提示端口占用.请lsof -i tcp:1080查询是不是占用,如果是占用请kill PID

5.surge配置的时候端口必须和ini配置的端口一样,请记住一定要socks5

 

国际惯例,结尾部分写上卸载命令:

brew uninstall v2ray
brew uninstall supervisor

 

 

 

 

 

 

发表评论

邮箱地址不会被公开。 必填项已用*标注