在 CentOS7.x
系统中一键安装 supervisord
服务,适用系统自带的python2.7版本,升级与否都可。
软件 | 版本 |
---|---|
OS | CentOS 7.x |
supervisor | 4.2.1 |
setuptools | 41.0.0 |
meld | 3-2.0.1 |
安装步骤
默认安装在/home/supervisor
下,也可指定安装目录参数自定义安装。执行完安装脚本,就可以在/home/supervisor
目录下看到有相应的配置文件目录etc
、日志目录logs
及临时文件目录tmp
,并且使用systemd
对supervisord
进行管理,安装完成后会自动销毁安装文件。
1.使用 root
用户上传 supervisor_install.tar.gz
到任意目录
cd /root
wget -c https://github.com/ghl1024/supervisor-install/releases/download/V1.0/supervisor_install.tar.gz
2.解压
tar xf supervisor_install.tar.gz
3.进入到目录
cd supervisor_install
4.执行安装脚本
./supervisor_install.sh #不跟参数默认安装在/home/supervisor下
./supervisor_install.sh /opt/supervisor #安装在/opt/supervisor下
./supervisor_install.sh /data/supervisor #安装在/data/supervisor下
5.查看状态
systemctl status supervisord.service
netstat -tnlp | grep "9001" | grep -v "grep"
ps -ef | grep "supervisord" | grep -v "grep"
安装在/home/supervisor
下示例
[root@hayden ~]$ pwd
/root
[root@hayden ~]$ wget -c https://github.com/ghl1024/supervisor-install/releases/download/V1.0/supervisor_install.tar.gz
[root@hayden ~]$ ll
total 1316
-rw-r--r-- 1 root root 1346912 Dec 17 19:38 supervisor_install.tar.gz
[root@hayden ~]$ tar xf supervisor_install.tar.gz
[root@hayden ~]$ cd supervisor/
[root@hayden supervisor]$ ll
total 1336
-rw-r--r-- 1 root root 64610 Dec 17 19:37 elementtree-1.2.7-20070827-preview.zip
-rwxr-xr-x 1 root root 2336 Dec 17 19:37 install_supervisor.sh
-rw-r--r-- 1 root root 36097 Dec 17 19:37 meld3-2.0.1.tar.gz
-rw-r--r-- 1 root root 786744 Dec 17 19:37 setuptools-41.0.0.tar.gz
-rw-r--r-- 1 root root 460935 Dec 17 19:37 supervisor-4.2.1.tar.gz
-rw-r--r-- 1 root root 2060 Dec 17 19:37 supervisord.conf
-rw-r--r-- 1 root root 245 Dec 17 19:37 supervisord.service
[root@hayden supervisor]$ sh install_supervisor.sh
Processing meld3-2.0.1.tar.gz
Writing /tmp/easy_install-y6vT9u/meld3-2.0.1/setup.cfg
Running meld3-2.0.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-y6vT9u/meld3-2.0.1/egg-dist-tmp-Ai63Ax
zip_safe flag not set; analyzing archive contents...
Removing /usr/lib/python2.7/site-packages/meld3-2.0.1-py2.7.egg
Moving meld3-2.0.1-py2.7.egg to /usr/lib/python2.7/site-packages
meld3 2.0.1 is already the active version in easy-install.pth
Installed /usr/lib/python2.7/site-packages/meld3-2.0.1-py2.7.egg
Processing dependencies for meld3==2.0.1
Finished processing dependencies for meld3==2.0.1
=============================================
supervisord已启动
安装目录为:/home/supervisor
systemd管理服务名称为:supervisord.service
占用端口为:9001
=============================================
[root@hayden supervisor]$ systemctl status supervisord.service
● supervisord.service - Process Monitoring and Control Daemon
Loaded: loaded (/usr/lib/systemd/system/supervisord.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2020-12-17 19:48:15 CST; 14s ago
Main PID: 11606 (supervisord)
CGroup: /system.slice/supervisord.service
└─11606 /usr/bin/python /usr/bin/supervisord -c /home/supervisor/etc/supervisord.conf
Dec 17 19:48:14 hayden systemd[1]: Starting Process Monitoring and Control Daemon...
Dec 17 19:48:15 hayden systemd[1]: Started Process Monitoring and Control Daemon.
[root@hayden supervisor]$ netstat -tnlp | grep "9001"
tcp 0 0 0.0.0.0:9001 0.0.0.0:* LISTEN 11606/python
[root@hayden supervisor]$ ps -ef | grep "supervisord" | grep -v "grep"
root 11606 1 0 19:48 ? 00:00:00 /usr/bin/python /usr/bin/supervisord -c /home/supervisor/etc/supervisord.conf
安装在/opt/supervisor
下示例
[root@hayden ~]$ pwd
/root
[root@hayden ~]$ wget -c https://github.com/ghl1024/supervisor-install/releases/download/V1.0/supervisor_install.tar.gz
[root@hayden ~]$ ll
total 1316
-rw-r--r-- 1 root root 1346912 Dec 17 19:38 supervisor_install.tar.gz
[root@hayden ~]$ tar xf supervisor_install.tar.gz
[root@hayden ~]$ cd supervisor/
[root@hayden supervisor]$ ll
total 1336
-rw-r--r-- 1 root root 64610 Dec 17 19:37 elementtree-1.2.7-20070827-preview.zip
-rwxr-xr-x 1 root root 2336 Dec 17 19:37 install_supervisor.sh
-rw-r--r-- 1 root root 36097 Dec 17 19:37 meld3-2.0.1.tar.gz
-rw-r--r-- 1 root root 786744 Dec 17 19:37 setuptools-41.0.0.tar.gz
-rw-r--r-- 1 root root 460935 Dec 17 19:37 supervisor-4.2.1.tar.gz
-rw-r--r-- 1 root root 2060 Dec 17 19:37 supervisord.conf
-rw-r--r-- 1 root root 245 Dec 17 19:37 supervisord.service
[root@hayden supervisor]$ sh install_supervisor.sh /opt/supervisor
Processing meld3-2.0.1.tar.gz
Writing /tmp/easy_install-Il9dVS/meld3-2.0.1/setup.cfg
Running meld3-2.0.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-Il9dVS/meld3-2.0.1/egg-dist-tmp-KKp4Ol
zip_safe flag not set; analyzing archive contents...
Removing /usr/lib/python2.7/site-packages/meld3-2.0.1-py2.7.egg
Moving meld3-2.0.1-py2.7.egg to /usr/lib/python2.7/site-packages
meld3 2.0.1 is already the active version in easy-install.pth
Installed /usr/lib/python2.7/site-packages/meld3-2.0.1-py2.7.egg
Processing dependencies for meld3==2.0.1
Finished processing dependencies for meld3==2.0.1
=============================================
supervisord已启动
安装目录为:/opt/supervisor
systemd管理服务名称为:supervisord.service
占用端口为:9001
=============================================
[root@hayden supervisor]$ systemctl status supervisord.service
● supervisord.service - Process Monitoring and Control Daemon
Loaded: loaded (/usr/lib/systemd/system/supervisord.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2020-12-17 19:58:19 CST; 2min 50s ago
Main PID: 12548 (supervisord)
CGroup: /system.slice/supervisord.service
└─12548 /usr/bin/python /usr/bin/supervisord -c /opt/supervisor/etc/supervisord.conf
Dec 17 19:58:19 hayden systemd[1]: Starting Process Monitoring and Control Daemon...
Dec 17 19:58:19 hayden systemd[1]: Started Process Monitoring and Control Daemon.
[root@hayden supervisor]$ netstat -tnlp | grep "9001" | grep -v "grep"
tcp 0 0 0.0.0.0:9001 0.0.0.0:* LISTEN 12548/python
[root@hayden supervisor]$ ps -ef | grep "supervisord" | grep -v "grep"
root 12548 1 0 19:58 ? 00:00:00 /usr/bin/python /usr/bin/supervisord -c /opt/supervisor/etc/supervisord.conf
supervisor和 systemd 对比
supervisor
优点
- 可以通过网页执行启动停止的操作
- 单配置文件可控制多个程序
- 可控制进程数量
- 进程资源控制能力比较强
缺点
- 本身需要被监控
- 开机自启依赖其他程序
- 不能跨主机
- 依赖于meld3、setuptools
- 进程需在前台运行
systemd
优点
- 可使用模板文件
- 附带定时器、路径监控器、数据监控器等功能
- 比较弱的跨主机能力,节点必须互相添加ssh key信任,只能远程控制已有的服务
- 开机可以自启
- 大多数发行版的标准配置
- 配套journalctl二进制保存日志很难伪造,日志格式统一,日志大小可限制
- 限制特定服务可用的系统资源量例如CPU、程序堆栈、文件句柄数量、子进程数量
缺点
- 多配置文件才能配置多个程序
supervisor 常用命令
supervisorctl update
#更新新的配置到supervisord(不会重启原来已运行的程序)
supervisorctl reload
#载入所有配置文件,并按新的配置启动、管理所有进程(会重启原来已运行的程序)
supervisorctl start xxx
#启动某个进程
supervisorctl restart xxx
#重启某个进程
supervisorctl stop xxx
#停止某一个进程(xxx),xxx为[program:theprogramname]里配置的值
supervisorctl stop groupworker
#重启所有属于名为groupworker这个分组的进程(start,restart同理)
supervisorctl stop all
#停止全部进程,注:start、restart、stop都不会载入最新的配置文
supervisorctl reread
#当一个服务由自动启动修改为手动启动时执行一下就ok