红联Linux门户
Linux帮助

SUSE 10.1下安装supervisord进程管理工具

发布时间:2014-08-19 14:58:19来源:linux网站作者:juven

1. 安装 python-2.7

cd /usr/src/
wget http://www.python.org/ftp/python/2.7/Python-2.7.tar.bz2
tar jxvf Python-2.7.tar.bz2
cd /usr/src/Python-2.7/
./configure
make
make install
 
做软链接
ln -sf /usr/local/bin/python /usr/bin/
 
显示版本已经是新安装的2.7版本了,但有报错如下:
[root@10.204.140.127 bin]# python
Python 2.7 (r27:82500, Sep 12 2012, 19:00:00)
[GCC 4.1.2 20070115 (prerelease) (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
File "/etc/pythonstart", line 7, in <module>
import readline
ImportError: No module named readline
>>>

 
2. 安装 readline
装 readline 之前,需要先安装 setuptools
cd /usr/src/
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e
tar zxvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11/
python setup.py install
 
出现"
Installed /usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
Processing dependencies for setuptools==0.6c11
Finished processing dependencies for setuptools==0.6c11
"      表示安装成功
 
然后,安装 readline-devel ,从SuSe系统自带的DVD光盘拷贝对应rpm包.
rpm -ivh readline-devel-5.1-24.13.x86_64.rpm
rpm -ivh readline-devel-32bit-5.1-24.13.x86_64.rpm
装完这两个依赖包,就可以开始安装 readline 了
cd /usr/src/
wget ftp://ftp.cwru.edu/pub/bash/readline-5.2.tar.gz
tar zxvf readline-5.2.tar.gz
cd readline-5.2/
CFLAGS="-O3 -fPIC" ./configure
(一定要加"-O3 -fPIC",不然会报错:"libreadline.a: could not read symbols: Bad value")
make CFLAGS=-fPIC
make CFLAGS=-fPIC install

 
3. 安装 python 的 readline 模块
cd /usr/src/
wget http://ipython.scipy.org/dist/readline-2.5.1.tar.gz
tar zxvf readline-2.5.1.tar.gz
cd /usr/src/readline-2.5.1
cp /usr/local/lib/{libreadline.a,libhistory.a} readline/
python setup.py install
 
出现"
Installed /usr/local/lib/python2.7/site-packages/readline-2.5.1-py2.7-linux-x86_64.egg
Processing dependencies for readline==2.5.1
Finished processing dependencies for readline==2.5.1
"      表示安装成功
 
然后再敲python就不会出现"ImportError: No module named readline"的提示了
 
[root@10.204.140.127 readline-2.5.1]# python
Python 2.7 (r27:82500, Sep 12 2012, 19:00:00)
[GCC 4.1.2 20070115 (prerelease) (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
 
 
4. 安装 meld3(如果服务器可以从公网下载文件,可直接跳至第5步)
cd /usr/src/
wget http://pypi.python.org/packages/source/m/meld3/meld3-0.6.8.tar.gz#md5=94b1591e518909e239fc17777db3c852
tar zxvf meld3-0.6.8.tar.gz
cd /usr/src/meld3-0.6.8/
python setup.py install

 
5. 安装 Supervisord
cd /usr/src/
tar zxvf supervisor-3.0a10.tar.gz
cd supervisor-3.0a10/
python setup.py install
 
出现
"Installed /usr/local/lib/python2.7/site-packages/supervisor-3.0a10-py2.7.egg
Processing dependencies for supervisor==3.0a10
Searching for meld3==0.6.8
Best match: meld3 0.6.8
Adding meld3 0.6.8 to easy-install.pth file
 
Using /usr/local/lib/python2.7/site-packages
Finished processing dependencies for supervisor==3.0a10", 恭喜,安装完成.

 
6. 配置 Supervisord
生成一个默认的配置文件,
echo_supervisord_conf > /etc/supervisord.conf
下面是我的配置范例:
[root@10.204.140.127 supervisor-3.0a10]# grep -v "^;" /etc/supervisord.conf
[unix_http_server]
file=/var/run/supervisor.sock   ; (the path to the socket file)
chmod=0777                 ; sockef file mode (default 0700)
chown=root:root       ; socket file uid:gid owner
 
## WEB管理 配置
[inet_http_server]         ; inet (TCP) server disabled by default
port=127.0.0.1:8010        ; (ip_address:port specifier, *:port for all iface)
username=admin              ; (default is no username (open server))
password=supper               ; (default is no password (open server))
 
## 全局配置
[supervisord]
logfile=/var/log/supervisord/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=true              ; (start in foreground if true;default false)
minfds=1024                 ; (min. avail startup file descriptors;default 1024)
minprocs=200                ; (min. avail process descriptors;default 200)
user=root                 ; (default is current user, required if root)
 
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
 
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket
 
## 配置监控对象
[program:monitor_cron]
command=/data/sh/monitor/f4_monitor_cron.sh              ; the program (relative uses PATH, can take args)
autostart=true                ; start at supervisord start (default: true)
startsecs=10                  ; number of secs prog must stay running (def. 1)
redirect_stderr=true          ; redirect proc stderr to stdout (default false)
stdout_logfile=/var/log/supervisord/monitorCron.log        ; stdout log path, NONE for none; default AUTO
 
其中command配置有三种写法,官网上是这样写的:
The command that will be run when this program is started. The command can be either absolute
1). (e.g. /path/to/programname) or relative (e.g. programname). If it is relative, the supervisord’s
 environment $PATH will be searched for the executable. Programs can accept arguments,
2). e.g. /path/to/program foo bar. The command line can use double quotes to group arguments with
spaces in them to pass to the program, e.g. /path/to/program/name -p "foo bar". Note that the
value of command may include Python string expressions,
3). e.g. /path/to/programname --port=80%(process_num)02d might expand to /path/to/programname --port=8000
at runtime. String expressions are evaluated against a dictionary containing the keys group_name,
host_node_name, process_num, program_name, here (the directory of the supervisord config file),
and all supervisord’s environment variables prefixed with ENV_. Controlled programs should
themselves not be daemons, as supervisord assumes it is responsible for daemonizing its subprocesses
 (see Nondaemonizing of Subprocesses).
 
鄙人E文很烂,就不翻译给大家献丑了,大家自由发挥吧,哈哈.
 
 
7. Supervisord 管理
Supervisord安装完成后有两个可用的命令行supervisor和supervisorctl,命令使用解释如下:
 
supervisord,初始启动Supervisord,启动、管理配置中设置的进程。
supervisorctl stop programxxx,停止某一个进程(programxxx),programxxx为[program:chatdemon]里配置的值,
这个示例就是"monitor_cron"
supervisorctl start programxxx,启动某个进程
supervisorctl restart programxxx,重启某个进程
supervisorctl stop all,停止全部进程,注:start、restart、stop都不会载入最新的配置文件。
supervisorctl reload,载入最新的配置文件,并按新的配置启动、管理所有进程。