title: 02-使用pip安装
order: 2
icon: lightbulb
说明:1.通过python-pip安装的是最新版的supervisor,该方式安装的需要手动配置主进程配置文件和子进程配置文件。
2.也可以通过yum安装
1.启动一台基础镜像为centos7的容器
[root@172-0-110-100 ~]# docker run -itd --name supervisord --privileged=true centos:7 /usr/sbin/init
Unable to find image 'centos:7' locally
7: Pulling from library/centos
2d473b07cdd5: Pull complete
Digest: sha256:9d4bcbbb213dfd745b58be38b13b996ebb5ac315fe75711bd618426a630e0987
Status: Downloaded newer image for centos:7
4cbc1518193f229d6c72d28e866dd8fcbad6b152c8ab30c8a0d75d377585a877
[root@172-0-110-100 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4cbc1518193f centos:7 "/bin/bash" 16 seconds ago Up 14 seconds supervisord
2.容器下安装python工具
[root@172-0-110-100 ~]# docker exec -it supervisord bash
[root@4cbc1518193f /]# yum install wget -y
[root@4cbc1518193f /]# rm -rf /etc/yum.repos.d/*
[root@4cbc1518193f /]# wget http://mirrors.aliyun.com/repo/Centos-7.repo -O /etc/yum.repos.d/Centos-7.repo
[root@4cbc1518193f /]# yum -y install epel-release
[root@4cbc1518193f /]# yum -y install python-pip
3.安装supervisord工具
## 使用pip命令安装supervisor工具
[root@4cbc1518193f /]# pip install supervisor
Collecting supervisor
Downloading https://files.pythonhosted.org/packages/2c/7a/0ad3973941590c040475046fef37a2b08a76691e61aa59540828ee235a6e/supervisor-4.2.5-py2.py3-none-any.whl (319kB)
100% |################################| 327kB 19kB/s
Requirement already satisfied (use --upgrade to upgrade): setuptools in /usr/lib/python2.7/site-packages (from supervisor)
Installing collected packages: supervisor
Successfully installed supervisor-4.2.5
You are using pip version 8.1.2, however version 23.2.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
## 查看supervisor是否安装成功,实质上是获取主配置文件里面的信息
[root@4cbc1518193f /]# echo_supervisord_conf
; Sample supervisor config file.
;
; For more information on the config file, please see:
; http://supervisord.org/configuration.html
;
; Notes:
; - Shell expansion ("~" or "$HOME") is not supported. Environment
; variables can be expanded using this syntax: "%(ENV_HOME)s".
; - Quotes around values are not supported, except in the case of
; the environment= options as shown below.
; - Comments must have a leading space: "a=b ;comment" not "a=b;comment".
; - Command will be truncated if it looks like a config file comment, e.g.
; "command=bash -c 'foo ; bar'" will truncate to "command=bash -c 'foo ".
………………
; The [include] section can just contain the "files" setting. This
; setting can list multiple files (separated by whitespace or
; newlines). It can also contain wildcards. The filenames are
; interpreted as relative to this file. Included files *cannot*
; include files themselves.
;[include]
;files = relative/directory/*.ini
4.编写主配置文件信息及创建子配置文件目录
[root@4cbc1518193f /]# echo_supervisord_conf > /etc/supervisord.conf
[root@4cbc1518193f /]# mkdir /etc/supervisord.d
[root@4cbc1518193f /]# ll /etc/ | grep super*
-rw-r--r-- 1 root root 10607 Sep 5 03:18 supervisord.conf
drwxr-xr-x 2 root root 6 Sep 5 03:19 supervisord.d
主配置文件可根据需求修改,比如开放web管理等
5.启动服务
[root@4cbc1518193f /]# supervisord -c /etc/supervisord.conf
[root@4cbc1518193f /]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 02:27 pts/0 00:00:00 /bin/bash
root 157 0 0 03:15 pts/1 00:00:00 bash
root 179 0 0 08:17 pts/2 00:00:00 bash
root 202 1 0 08:40 ? 00:00:00 /usr/bin/python2 /usr/bin/supervisord -c /etc/supervisord.conf
root 203 179 0 08:40 pts/2 00:00:00 ps -ef
评论区