centos7 安装supervisor
supervisor安装
- 方式一
1,python包管理工具进行安装
yum -y install python-setuptools 或 yum -y install python-pip
#上面命令如果提示找不到python-pip需要更新epel源
yum -y install epel-release
yum -y install python-pip
2,pip 安装supervisor
pip install supervisor
3,也可以使用easy-install 安装
yum -y install python-setuptools
easy-install supervisor 或 pip install supervisor
4,生成配置文件
echo_supervisord_conf > /etc/supervisord.conf
5,配置systemctl启动文件
cat /lib/systemd/system/supervisord.service
# dservice for systemd (CentOS 7.0+)
# by ET-CS (https://github.com/ET-CS)
[Unit]
Description=Supervisor daemon
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
systemctl daemon-reload ##刷新配置文件使其生效
- 方式二 yum安装(推荐)
1,安装
yum -y install supervisor
2,启动命令
systemctl start supervisor ##暂时先不启动,需要配置托管服务
supervisor 托管redis
1,修改supervisor配置文件
vim /etc/supervisord.conf
....
#最后部分修改 [include]模块
[include]
files = supervisord.d/*.ini
[supervisord]
minfds=65535
minprocs=65535
#保存退出
2,创建对应的文件
mkdir -p /etc/supervisord.d
vim redis_6379.ini
[program:redis-6379]
command=/usr/local/bin/redis-server /data/redis/redis-6379/redis-6379.conf
autorestart=true
autostart=true
stopasgroup=true
killasgroup=true
stopsignal=INT
stderr_logfile=/data/redis/redis-6379/supervisor_err.log
stdout_logfile=/data/redis/redis-6379/supervisor_out.log
user=root
stopsignal=INT
startsecs=10
startretries=3
directory=/data/redis/redis-6379/
3,检查配置文件中对应的目录,并创建redis_6380.ini配置文件
cp redis_6379.ini redis_6380.ini
#修改redis_6380.ini 配置文件中关于6379相关的信息,并在/data/redis/目录下创建 redis-6380目录文件
- 启动 supervisor
systemctl daemon-reload
systemctl start supervisord
supervisorctl status #查看redis启动状态,并查看redis相关的日志文件
#重启所以supervisor托管的服务
supervisorctl restart all
#重启其中一个服务
supervisorctl restart redis-6379
注意:supervisor 托管的服务不允许开启后台启动,类似docker容器启动服务,需要把redis.conf 中删除或关闭daemonize no。
redis这部分可以配置redis cluster集群,集群之间配置互为主从结构,保证redis数据的一致性问题。
相关redis cluster搭建,参考另一篇文章。redis cluster集群搭建
Supervisor 服务相关配置文件详解,参考文章: