0
点赞
收藏
分享

微信扫一扫

使用Supervisor监控和启动MongoDB集群服务

说明

关于Supervisor网上资料很多,大家可以去看下,这里重点是使用Supervisor进行监控和启动MongoDB集群服务。

安装 Supervisor

(1)添加 yum 源

# cat /etc/yum.repos.d/epel.repo

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place its address here.
#baseurl=http://download.example/pub/epel/7/$basearch
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch&infra=$infra&content=$contentdir
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

(2)生成缓存

yum makecache fast

(3)安装 Supervisor 包

yum install supervisor -y

Supervisor 配置

linux 安装完后会有一个主配置文件/etc/supervisord.conf和一个/etc/supervisord.d自配置文件目录。

(1)独立配置格式

独立配置路径以及加载哪些配置。有的是conf,有的是ini格式的。yum安装为ini格式。

(2)创建项目的配置文件

[program:mongo-25001]
; 启动命令
command = mongod --config /data/mongo/shard1/mongod.conf
; 程序异常退出后自动重启
autorestart=true
; 在 supervisord 启动的时候也自动启动
autostart=true
; 启动失败自动重试次数,默认是 3
startretries = 3
; stdout 日志文件,需要手动创建目录(如无),supervisord 会自动创建日志文件
stderr_logfile=/var/log/mongo-25001-error.log
stdout_logfile=/var/log/mongo-25001-out.log
; 用哪个用户启动
user=root
; 启动 5 秒后没有异常退出,就当作已经正常启动了
startsecs=5

修改 mongodb 服务进程启动参数

被监控的进程要以非daemon方式运行,以mongodb为例,需要去掉mongodb进程启动命令里的--fork 参数:

# cat /data/mongo/shard1/mongod.conf
...
processManagement:
  fork: false
  #fork: true
...

启动 Supervisor 服务

systemctl start supervisord.service
systemctl status supervisord.service
systemctl enable supervisord.service

查看 mongodb 服务

ss -lnptu|grep mongo

查看监控的进程

# supervisorctl status
mongo-25001                      RUNNING   pid 16864, uptime 0:16:31

supervisorctl 常用命令

supervisorctl restart <application name,eg:mongo-25001>  #重启指定应用
supervisorctl stop <application name>  #停止指定应用
supervisorctl start <application name>  #启动指定应用
supervisorctl status # 查看服务状态
supervisorctl restart all  #重启所有应用
supervisorctl stop all  #停止所有应用
supervisorctl start all  #启动所有应用
supervisorctl update  #配置文件修改后可以使用该命令加载新的配置
supervisorctl reload  #重新启动配置中的所有程序

典型报错

使用supervisorctl status查看发现有进程被不断重启,报错如下:

#XXX(项目名)      FATAL     Exited too quickly (process log may have details)

原因就是上面所说的,被监控的进程要以非daemon方式运行

# supervisor只支持前台程序的托管到后台(启动前需要kill掉已经存在的进程),例如:
# redis
redis就需要把redis.conf配置文件中的daemonize设置为no
#nginx
nginx就需要在命令行后缀增加 -g ‘daemon off;’
#mongodb
mongodb如果不断重启,多半也是因为启动命令中加了后台运行的参数 & 同样的去掉就可以了

开启 web supervisor 管理台

supervisord.conf中配置:

[inet_http_server]
port=0.0.0.0:9001
username=admin
password=Test@1106

这样,在浏览器中输入配置中写的地址和端口号,输入配置好的用户名和密码,便可以看到基于网页的控制台界面。可以察看supervisor监控的信息,可以察看进程的日志等。

告警监控

目前采用 Prometheus 监控IP+Port形式,supervisor本身的监控后面再加。

参考文档

  • 使用Supervisor监控和启动mongoDB集群服务
举报

相关推荐

0 条评论