一、Supervisor简介
supervisor是一个Linux/Unix系统上的进程监控工具,supervisor是一个Python开发的通用的进程管理程序,可以管理和监控Linux上面的进程,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动重启。不过同daemontools一样,它不能监控daemon进程
1. yum安装supervisor
yum install -y epel-release supervisor
2. 生成配置文件
echo_supervisord_conf > /etc/supervisord.conf
3. 编辑配置文件
```
[unix_http_server]
file=/var/run/supervisor/supervisor.sock ; (the path to the socket file)
[inet_http_server] ; inet (TCP) server disabled by default
port=*:9001 ; (ip_address:port specifier, *:port for all iface)
[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor/supervisor.sock ; use a unix:// URL for a unix socket
[include]
files = /etc/supervisord.d/*.conf ; 注意写绝对路径
```
4. 启动supervisord,设置开机启动
supervisord -c /etc/supervisord.conf
echo "supervisord -c /etc/supervisord.conf" >> /etc/rc.local
chmod +x /etc/rc.d/rc.local
5. 访问supervisor的web界面
http://ip:9001
6. 添加管理进程的配置文件,存放在/etc/supervisord.d/
```
[program:elasticsearch]
command = /usr/local/elasticsearch/bin/elasticsearch ; 程序的启动目录
user=elk ; 使用什么用户启动
priority=10 ; 优先级,默认999 数字越小优先级越高
numprocs=1 ; 启动几个进程
autostart=true ; 随着supervisord的启动而启动
autorestart=true ; 异常退出后,自动重启
startrestries=3 ; 启动失败时的最多重试次数
redirect_stderr=true ; 重定向stderr到stdout
stdout_logfile_maxbytes = 20MB ; stdout 日志文件大小,默认 50MB
stdout_logfile_backups = 10 ; stdout 日志文件备份数
stdout_logfile = /home/logs/supervisor/elasticsearch_stdout.log ; 日志文件
```
展示图:
二、Cesi 简介
CeSi 是 Supervisor 官方推荐的集中化管理 Supervisor 实例的 Web UI,该工具是用 Python 编写,基于 Flask Web 框架 。
Superviosr 自带的 Web UI 不支持跨机器管理
Supervisor 进程,功能比较简单,通过 CeSi 可以集中管理各个服务器节点的进程,在 Web 界面就可以轻松管理各个服务的启动、关闭、重启等,很方便使用。
1. 安装依赖
yum install -y git wget epel-release python34 python34-pip npm bzip2
npm install -g n (升级node到最新版)
n latest
curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
yum install -y yarn (安装yarn)
2. 安装cesi (参考官网教程)
```
export CESI_SETUP_PATH=/opt/cesi
mkdir ${CESI_SETUP_PATH}
cd ${CESI_SETUP_PATH}
wget https://github.com/gamegos/cesi/releases/download/v2.6.7/cesi-extended.tar.gz -O cesi.tar.gz
tar -xvf cesi.tar.gz
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt
deactivate
cd ${CESI_SETUP_PATH}/cesi/ui
yarn install
yarn build
cp ${CESI_SETUP_PATH}/defaults/cesi.conf.toml /etc/cesi.conf.toml
vi /etc/cesi.conf.toml
[cesi]
database = "sqlite:///users.db" # Relative path
activity_log = "activity.log" # File path for CeSI logs
admin_username = "admin" # Username of admin user
admin_password = "admin" # Password of admin user
[[nodes]]
name = "node1"
environment = ""
username = ""
password = ""
host = "172.16.16.75"
port = "9001"
[[nodes]]
name = "node2"
environment = ""
username = "admin"
password = "btr2014"
host = "172.16.8.12"
port = "9001"
cp ${CESI_SETUP_PATH}/defaults/cesi.service /etc/systemd/system/cesi.service
vi /etc/systemd/system/cesi.service
[Unit]
Description=cesi
[Service]
Environment=
ExecStart=/root/cesi/venv/bin/python3 /root/cesi/cesi/run.py --config-file /etc/cesi.conf.toml
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=TERM
User=root
WorkingDirectory=/root/cesi
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start cesi
展示图:
![](https://s1.51cto.com/images/blog/201903/05/398eda22207b54bd888ba09ebcfe03d3.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。