安装
1 2 sudo apt-get install supervisor
启动,否则会报 unix:///tmp/supervisor.sock no such file
1 2 service supervisor start
或者
1 2 supervisord -c /etc/supervisor/supervisord.conf
生成配置文件
1 2 echo_supervisord_conf > /etc/supervisor/supervisord.conf
注意里面的注释去掉
1 2 3 4 5 [inet_http_server] ; inet (TCP) server disabled by default port=127.0.0.1:9001 ; (ip_address:port specifier, *:port for all iface) username=user ; (default is no username (open server)) password=123 ; (default is no password (open server))
配置文件路径
1 2 3 [include] files = /etc/supervisor/conf.d/*.conf
查看状态
1 2 3 4 5 supervisorctl status #查看supervisorctl状态 supervisorctl start openfalcon #启动子进程 supervisorctl stop openfalcon #关闭子进程 supervisorctl restart openfalcon #重启子进程
比如
1 2 3 lintong@master:~$ supervisorctl status openfalcon RUNNING pid 10759, uptime 0:18:46
配置文件在 /etc/supervisor 目录下
1 2 3 lintong@master:/etc/supervisor$ ls conf.d start_openfalcon.conf supervisord.conf
内容
1 2 3 4 5 6 7 8 [program:openfalcon] command = cd ~/software/open-falcon-v0.2.1 & open-falcon start user = lintong autostart = true autoresart = true stderr_logfile = /var/log/supervisor/openfalcon.stderr.log stdout_logfile = /var/log/supervisor/openfalcon.stdout.log
重启supervisor
重新加载配置
web界面,账号密码参考 /etc/supervisord.conf
下面是几个例子
1 2 3 lintong@master:/etc/supervisor/conf.d$ ls es.conf hadoop.conf hive.conf redis.conf
hadoop
1 2 3 4 5 6 7 8 9 [program:hadoop] directory=/home/lintong/software/apache/hadoop-2.9.1 command = bash ./sbin/start-all.sh user = lintong autostart = true autoresart = false stderr_logfile = /var/log/supervisor/hadoop.stderr.log stdout_logfile = /var/log/supervisor/hadoop.stdout.log
hive
1 2 3 4 5 6 7 8 9 [program:hive] directory=/home/lintong/software/apache/apache-hive-2.3.3-bin command = bash ./bin/hiveserver2 start user = lintong autostart = true autoresart = true stderr_logfile = /var/log/supervisor/hive.stderr.log stdout_logfile = /var/log/supervisor/hive.stdout.log
es
1 2 3 4 5 6 7 8 9 [program:es] directory=/home/lintong/software/apache/elasticsearch-6.2.4 command = bash ./bin/elasticsearch user = lintong autostart = true autoresart = true stderr_logfile = /var/log/supervisor/es.stderr.log stdout_logfile = /var/log/supervisor/es.stdout.log
kafka_manager
其中的/bin/bash -c ‘source “$0” && exec “$@”‘是为了解决cant find command问题
1 2 3 4 5 6 7 8 9 [program:kafka-manager] directory=/home/lintong/software/apache/kafka-manager-1.3.3.17/bin command = /bin/bash -c 'source "$0" && exec "$@"' kafka-manager -Dconfig.file=/home/lintong/software/apache/kafka-manager-1.3.3.17/conf/application.conf -Dhttp.port=7778 user = lintong autostart = true autoresart = false stderr_logfile = /var/log/supervisor/kafka_manager.stderr.log stdout_logfile = /var/log/supervisor/kafka_manager.stdout.log
kibana
1 2 3 4 5 6 7 8 9 [program:kibana] directory=/home/lintong/software/apache/kibana-6.2.4-linux-x86_64 command = bash ./bin/kibana user = lintong autostart = false autoresart = true stderr_logfile = /var/log/supervisor/kibana.stderr.log stdout_logfile = /var/log/supervisor/kibana.stdout.log
zkui
1 2 3 4 5 6 7 8 9 [program:zkui] directory=/home/lintong/software/zkui/target command = java -jar zkui-2.0-SNAPSHOT-jar-with-dependencies.jar user = lintong autostart = false autorestart = true stderr_logfile = /var/log/supervisor/zkui.stderr.log stdout_logfile = /var/log/supervisor/zkui.stdout.log
kafka-manager
1 2 3 4 5 6 7 8 9 [program:kafka-manager] directory=/home/lintong/software/kafka-manager-1.3.3.17 command = bash ./bin/kafka-manager -Dconfig.file=/home/lintong/software/kafka-manager-1.3.3.17/conf/application.conf -Dhttp.port=7778 user = lintong autostart = false autorestart = true stderr_logfile = /var/log/supervisor/kafka-manager.stderr.log stdout_logfile = /var/log/supervisor/kafka-manager.stdout.log
如果supervisor启动的进程使用了虚拟环境,则可以使用environment来配置虚拟环境,如下
1 2 environment=PATH="/home/xxx/envs/airflow/bin"
如果遇到xxxx: ERROR (no such file)的报错,需要把airflow的完整启动路径写到command的配置当中
supervisor的默认配置,比如日志文件最大为50MB,日志文件backup为10个,参考:supervisor配置文件详解