Supervisord是一个进程管理工具,它可以方便地启动、停止、重启服务进程。相比于直接使用systemd或者init.d脚本,Supervisord提供了更加灵活和强大的功能,是管理v2ray等服务的不二之选。
安装Python和pip:
apt-get update apt-get install -y python3 python3-pip
安装Supervisord:
pip3 install supervisord
创建Supervisord配置文件:
mkdir -p /etc/supervisord.d touch /etc/supervisord.d/v2ray.ini
下载并安装v2ray:
wget https://github.com/v2fly/v2ray-core/releases/latest/download/v2ray-linux-64.zip unzip v2ray-linux-64.zip mv v2ray /usr/local/bin/
创建v2ray配置文件:
touch /etc/v2ray/config.json
编辑v2ray配置文件,根据您的需求进行配置。
编辑/etc/supervisord.d/v2ray.ini文件,添加以下内容:
[program:v2ray] command=/usr/local/bin/v2ray -config /etc/v2ray/config.json autostart=true autorestart=true user=root stdout_logfile=/var/log/v2ray.log stderr_logfile=/var/log/v2ray.err.log
启动Supervisord:
supervisord -c /etc/supervisord.conf
启动v2ray:
supervisorctl start v2ray
停止v2ray:
supervisorctl stop v2ray
查看v2ray状态:
supervisorctl status v2ray
重启v2ray:
supervisorctl restart v2ray
Q1: Supervisord如何开机自启? A1: 您可以将Supervisord添加到系统启动脚本中,比如在/etc/rc.local文件中添加以下内容:
/usr/bin/supervisord -c /etc/supervisord.conf
Q2: Supervisord的Web界面如何访问? A2: 默认情况下,Supervisord的Web界面监听在9001端口。您可以在/etc/supervisord.conf文件中配置Web界面的监听地址和端口:
[inet_http_server] port=0.0.0.0:9001 username=admin password=password
Q3: Supervisord如何查看日志? A3: Supervisord会将v2ray的日志输出到/var/log/v2ray.log和/var/log/v2ray.err.log文件中。您可以使用以下命令查看日志:
tail -n 100 /var/log/v2ray.log tail -n 100 /var/log/v2ray.err.log
Q4: Supervisord如何排查故障? A4: 如果v2ray服务无法正常运行,您可以查看Supervisord的日志,定位问题所在:
supervisorctl tail v2ray stderr supervisorctl tail v2ray stdout