为什么80%的码农都做不了架构师?>>>   

最近blog更新的有点慢了,先补一篇关于supervisord的文章,supervisord使用很久了,那是在还没掌握怎么在linux写编写守护进程之前,不过在会写守护进程之后还是愿意使用supervisord,原因是懒得写代码......

supervisord是一个python程序,所以你的系统中首先要有python,最好是2.7版本,其次supervisord不在默认python库中,需要你手动安装。我的系统是centos6.5,因为忍受不了python2.6,所以系统中使用的是自己打包定制的python2.7,当然顺便把supervisord也给打包进去了,并且包括了supervisord init文件、supervisord conf目录,supervisord sample文件等。看看我自己的python包中默认都加入了哪些第三方lib:

Include:
- python_2.7.11
Include python libs:
- MySQL_python_1.2.4b4
- Fabric_1.10.2
- Setuptools_3.3
- Psutil_0.7.1
- Supervisor_3.2.1
- Paramiko_1.16.0
- Pycrypto_2.6.1
- Meld3_1.0.2
- Ecdsa_0.13
- Cx_Freeze_4.3.4
- Distribute_0.6.28
- Pexpect_4.0.1
- Requests_2.9.1
- Redis_2.10.5
- Sh_1.11
- netifaces_0.10.4

关于Supervisord怎么安装,请看 官网 。

supervisord的使用:

下面看看supervisord的init文件:/etc/init.d/supervisord

#!/bin/bash
#
# /etc/rc.d/init.d/supervisord
# Supervisor is a client/server system that
# allows its users to monitor and control a
# number of processes on UNIX-like operating
# systems.
# chkconfig: - 64 36
# description: Supervisor Server
# processname: supervisord
# Source init functions. /etc/init.d/functionsRETVAL=0
prog="supervisord"
pidfile="/tmp/supervisord.pid"
lockfile="/var/lock/subsys/supervisord"start()
{echo -n $"Starting $prog: "daemon --pidfile $pidfile /usr/local/bin/supervisord -c /etc/supervisord.confRETVAL=$?echo[ $RETVAL -eq 0 ] && touch ${lockfile}
}stop()
{echo -n $"Shutting down $prog: "killproc -p ${pidfile} /usr/local/bin/supervisordRETVAL=$?echoif [ $RETVAL -eq 0 ] ; thenrm -f ${lockfile} ${pidfile}fi
}case "$1" instart)start;;stop)stop;;status)status $prog;;restart)stopstart;;*)echo "Usage: $0 {start|stop|restart|status}";;
esac

注意其中加载的supervisord.conf配置文件路径,以及你的supervisord可执行文件文件路径。

下面看看supervisord的主配置文件:/etc/supervisord.conf

[supervisord]
logfile=/tmp/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=/tmp/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)
umask=022                    ; (process file creation umask;default 022)
user=apprun                  ; (default is current user, required if root)
identifier=supervisor        ; (supervisord identifier, default is 'supervisor')
;directory=/tmp              ; (default is not to cd during start)
;nocleanup=true              ; (don't clean up tempfiles at start;default false)
;childlogdir=/tmp            ; ('AUTO' child log dir, default $TEMP)
;environment=KEY="value"     ; (key value pairs to add to environment)
;strip_ansi=false            ; (strip ansi escape codes in logs; def. false)[inet_http_server]
port=0.0.0.0:9001
username=apprun
password=apprun[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface[supervisorctl]
serverurl=http://0.0.0.0:9001
username=apprun
password=apprun
prompt=bd-stg-api-53
history_file=~/.sc_history  [include]
files = /etc/supervisord.conf.d/*.conf

下面看看 supervisord 的项目置文件, /etc/supervisord.conf.d/*.conf

[program:bd-sisyphus-web]
command=/opt/programs/jdk1.8.0_77/bin/java -jar /opt/app/applications/project1/apps/project1.war --server.port=9000
process_name=%(program_name)s
directory=/opt/app/applications/project1
inumprocs=1
autostart=true
autorestart=false
startretries=5
stopsignal=TERM
stopwaitsecs=15
user=apprun
#redirect_stderr=true
stdout_logfile=/opt/app/applications/project1/logs/project1.log
stderr_logfile=/opt/app/applications/project1/logs/project1-error.log
directory=/opt/app/applications/project1

启动supervisord

/etc/init.d/supervisord start

查看supervisord管理的进程:supervisorctl

输入help可以查看可以使用哪些命令。

supervisord-monitor的使用:

supervisord-monitor是一个用来监控supervisord的项目,使用supervisord暴露出来的http接口来监控supervisord。supervisord-monitor是用php写成,项目地址看这里。

下载supervisord-monitor

git clone https://github.com/mlazarov/supervisord-monitor.git

创建配置文件

cp application/config/supervisor.php.example application/config/supervisor.php

修改supervisor.php的supervisor_servers配置

$config['supervisor_servers'] = array('bd-stg-api-53' => array('url' => 'http://10.203.80.53/RPC2','port' => '9001','username' => 'apprun','password' => 'apprun'),
//      'server02' => array(
//              'url' => 'http://server02.app/RPC2',
//               'port' => '9001'
//      ),
//      'server03' => array(
//               'url' => 'http://server03.app/RPC2',
//                'port' => '9001'
//        ),
);

因为我目前只拿一台做实验,所以部署了一台supervisord,如果你有多台机器部署了supervisord,则可以添加多个server信息。

安装nginx、php、php-fpm

yum install nginx php php-fpm

配置nginx配置:supervisord-monitor.conf

server {listen       10.203.50.36:80;server_name  supervisord-monitor.service.bd;access_log   logs/sup-access.log main;error_log    logs/sup-error.log;log_by_lua_file /opt/programs/nginx_1.8.1/lua_script/collect.lua;location / {root   /opt/programs/supervisord-monitor/public_html;index  index.html index.htm index.php;}location ~ .php$ {root /opt/programs/supervisord-monitor/public_html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}location = /status.json {default_type 'application/json';content_by_lua_file /opt/programs/nginx_1.8.1/lua_script/show.lua;}
}

启动php-fpm、nginx

/etc/init.d/php-fpm start
/etc/init.d/nginx start

访问supervisord-monitor

supervisorclusterctl

有web方式管理supervisord,那就也有命令行方式supervisord了,supervisorclusterctl就是在命令行管理supervisord集群,supervisorclusterctl是依赖ansible来管理supervisord的,也是调用supervisord暴露出来的http接口实现管理。项目地址看这里。

下载supervisorclusterctl

git clone https://github.com/RobWin/supervisorclusterctl.git

安装supervisorclusterctl

cd supervisorclusterctl
python setup.py install

安装ansible

yum install ansible

配置ansble配置文件:ansible.cfg,其余值保持默认即可

[defaults]
inventory      = /etc/ansible/hosts
remote_tmp     = $HOME/.ansible/tmp
pattern        = *
forks          = 5
poll_interval  = 15
sudo_user      = root
transport      = paramiko
remote_port    = 22
module_lang    = C
gathering = implicit
host_key_checking = False
sudo_exe = sudo
timeout = 10
remote_user = apprun
log_path = /var/log/ansible.log
module_name = shell
executable = /bin/bash
private_key_file = /root/.ssh/id_rsa
ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}
action_plugins     = /usr/share/ansible_plugins/action_plugins
callback_plugins   = /usr/share/ansible_plugins/callback_plugins
connection_plugins = /usr/share/ansible_plugins/connection_plugins
lookup_plugins     = /usr/share/ansible_plugins/lookup_plugins
vars_plugins       = /usr/share/ansible_plugins/vars_plugins
filter_plugins     = /usr/share/ansible_plugins/filter_plugins
fact_caching = memory
[privilege_escalation]
[paramiko_connection]
[ssh_connection]
[accelerate]
accelerate_port = 5099
accelerate_timeout = 30
accelerate_connect_timeout = 5.0
accelerate_daemon_timeout = 30
[selinux]

配置/etc/ansible/hosts,追加如下:

[bd-sisyphus-web]
10.203.80.53

验证supervisorclusterctl

转载于:https://my.oschina.net/guol/blog/667780

supervisord+supervisorclusterctl+supervisord-monit相关推荐

  1. supervisord简介

    supervisord简介 转自:http://www.cnblogs.com/jasonkoo/articles/3750638.html [产生背景] 在一个分布式环境中,每台机器上可能需要启动和 ...

  2. systemd下supervisord服务开机自启动以及注意事项

    systemd 下supervisord服务开机自启动 centos7 开机自启动脚本: #vim /lib/systemd/system/supervisord.service# superviso ...

  3. Centos7.x 安装 Supervisord

    [环境] 系统:Centos 7.3 软件:supervisord [安装Supervisord] yum install epel-release yum install -y supervisor ...

  4. golang 程序部署及Supervisord deamon 运行

    此方法运行是基于supervisord的,系统为centos  64位 所以先安装相应的程序 第一步.首先执行  curl https://bootstrap.pypa.io/ez_setup.py ...

  5. Supervisord进程管家

    Supervisord进程管家 Supervisord是一个守护进程的工具,当进程意外终止或服务器掉电起来后,希望进程能够自动运行,supervisord可以很好的为我们做这件事情.同时supervi ...

  6. supervisord安装使用简记

    What is supervisor Supervisor is a client/server system that allows its users to monitor and control ...

  7. linux服务与进程管理sup,linux下进程管理工具-supervisord

    一 简介 supervisord是linux下的一个优秀的进程管理工具,通过supervisord可以方便管理和应用linux系统下服务进程过多的问题,其支持服务异常退出自动重启,通过浏览器管理控制相 ...

  8. supervisord进程管理

    Supervisord Supervisord是一款基于Python的进程管理工具,当主机上存在多个的进程需要管理时,通过supervisor可以简化进程的管理. 再通过supervisor提供的rp ...

  9. Supervisord管理

    原文地址:http://blog.csdn.net/fyh2003/article/details/6837970 学习笔记 Supervisord可以通过sudo easy_install supe ...

最新文章

  1. 简析ThinkSNS+ 计算字符显示长度的方法!【社交系统研发日记】
  2. python 统计文件top IP
  3. Bourbon: 让你的sass更简洁
  4. 机械系统计算机控制试卷及答案,机械系统设计试题及答案
  5. How to Simulate the Price Order or Price Line Function using API QP_PREQ_PUB.PRICE_REQUEST Includes
  6. 氢气露点和湿度换算_如何创建氢气鼓组以获取乐趣和收益
  7. Nginx学习总结(4)——负载均衡session会话保持方法
  8. 6.1Python文件的操作(一)
  9. SpringMVC 统一异常处理
  10. CF949D Curfew solution
  11. 小龙女,杨过跳崖真相
  12. 不规则多边形重心求解
  13. 浮点数到整数的快速转换
  14. linux 内核链表
  15. ChatGPT微信小程序搭建总结
  16. 硬件电子开发常用工具
  17. 传统责任链模式和变种责任链模式
  18. 如何借助企业微信运营管理用户?
  19. mysql sql dateadd函数_SQL DATEADD函数 (sqlserver 只更新表中年份,不改其他时间)...
  20. HTC手机鉴别终极宝典

热门文章

  1. 2018中国自动驾驶市场专题分析
  2. 自然语言处理(NLP)前沿进展报告
  3. Yoshua Bengio团队通过在网络「隐藏空间」中使用降噪器以提高深度神经网络的「鲁棒性」
  4. DeepMind集成AI智能体架构「MERLIN」:基于目标导向智能体中的无监督预测记忆
  5. 李开复:AI巨头是有史以来最难以打破的垄断
  6. 英国再推人工智能报告: 四方面发力打造AI强国
  7. 官宣:程序员被纳入新生代农民工!
  8. 雷军哽咽:我愿押上人生全部声誉,为小米汽车而战!
  9. 太慢不能忍!CPU又拿硬盘和网卡开刀了!
  10. RSA解密时javax.crypto.BadPaddingException: Data must start with zero