歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> SUSE 10.1下安裝supervisord進程管理工具

SUSE 10.1下安裝supervisord進程管理工具

日期:2017/2/28 15:33:13   编辑:Linux教程

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版本了,但有報錯如下:
[[email protected] 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"的提示了

[[email protected] 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
下面是我的配置范例:
[[email protected] 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,載入最新的配置文件,並按新的配置啟動、管理所有進程。

Copyright © Linux教程網 All Rights Reserved