2015-02-24 19 views
14

Tôi đang cố gắng để người giám sát làm việc để đảm bảo hệ thống xếp hàng của tôi luôn chạy.Thiết lập Giám sát trên máy chủ AWS AMI Linux

Dưới đây là các bước tôi đã, mà tôi chắp ghép từ nhiều nguồn khác nhau: (Ran như là người chủ hoặc siêu người dùng)

1) $ easy_install giám sát

2) $ echo_supervisord_conf>/etc /supervisord.conf

3) $ sudo vi supervisord.conf

4) dán các follo cánh đến cuối file:

command =/usr/bin/php/path/to/AppName/nghệ nhân --env = sản xuất --timeout = 240 đợi: nghe

5) $ supervisord -c /etc/supervisord.conf

6) $ supervisorctl

7) giám sát> Tình trạng

giám sát>

Nó không hiển thị bất cứ điều gì.

Trả lời

16

Đây là giải pháp tôi đã thực hiện. AWS AMI bao gồm pip để cài đặt các ứng dụng Python. Dưới đây là các lệnh thiết lập:

$ sudo pip install supervisor 
$ echo_supervisord_conf 
$ sudo su - 
$ echo_supervisord_conf > /etc/supervisord.conf 

Sau khi bạn cài đặt giám sát, bạn sẽ cần xây dựng kịch bản khởi động theo cách thủ công để bật và tắt dịch vụ.

Điều này sẽ khác với bản phân phối Linux của bạn, Ubuntu sẽ tạo tập lệnh init cho bạn khi bạn cài đặt, các bản phân phối khác như AMI sẽ không. Dưới đây là một nguồn lực lớn cho nhiều distro Linux init script-up:

https://github.com/Supervisor/initscripts

Sau đó bạn có thể thêm người giám sát để chkconfig để bắt đầu tự động trên hệ thống khởi động lại.

Dưới đây là một trong đó làm việc cho tôi:

Đường dẫn

/etc/init.d/supervisord 

Ví dụ Init Script cho AWS-AMI hoặc RedHat Linux

#!/bin/bash 
# 
# supervisord Startup script for the Supervisor process control system 
# 
# Author:  Mike McGrath <[email protected]> (based off yumupdatesd) 
#    Jason Koppe <[email protected]> adjusted to read sysconfig, 
#     use supervisord tools to start/stop, conditionally wait 
#     for child processes to shutdown, and startup later 
#    Erwan Queffelec <[email protected]> 
#     make script LSB-compliant 
# 
# chkconfig: 345 83 04 
# description: Supervisor is a client/server system that allows \ 
# its users to monitor and control a number of processes on \ 
# UNIX-like operating systems. 
# processname: supervisord 
# config: /etc/supervisord.conf 
# config: /etc/sysconfig/supervisord 
# pidfile: /var/run/supervisord.pid 
# 
### BEGIN INIT INFO 
# Provides: supervisord 
# Required-Start: $all 
# Required-Stop: $all 
# Short-Description: start and stop Supervisor process control system 
# Description: Supervisor is a client/server system that allows 
# its users to monitor and control a number of processes on 
# UNIX-like operating systems. 
### END INIT INFO 

# Source function library 
. /etc/rc.d/init.d/functions 

# Source system settings 
if [ -f /etc/sysconfig/supervisord ]; then 
    . /etc/sysconfig/supervisord 
fi 

# Path to the supervisorctl script, server binary, 
# and short-form for messages. 
supervisorctl=/usr/local/bin/supervisorctl 
supervisord=${SUPERVISORD-/usr/local/bin/supervisord} 
prog=supervisord 
pidfile=${PIDFILE-/tmp/supervisord.pid} 
lockfile=${LOCKFILE-/var/lock/subsys/supervisord} 
STOP_TIMEOUT=${STOP_TIMEOUT-60} 
OPTIONS="${OPTIONS--c /etc/supervisord.conf}" 
RETVAL=0 

start() { 
    echo -n $"Starting $prog: " 
    daemon --pidfile=${pidfile} $supervisord $OPTIONS 
    RETVAL=$? 
    echo 
    if [ $RETVAL -eq 0 ]; then 
     touch ${lockfile} 
     $supervisorctl $OPTIONS status 
    fi 
    return $RETVAL 
} 

stop() { 
    echo -n $"Stopping $prog: " 
    killproc -p ${pidfile} -d ${STOP_TIMEOUT} $supervisord 
    RETVAL=$? 
    echo 
    [ $RETVAL -eq 0 ] && rm -rf ${lockfile} ${pidfile} 
} 

reload() { 
    echo -n $"Reloading $prog: " 
    LSB=1 killproc -p $pidfile $supervisord -HUP 
    RETVAL=$? 
    echo 
    if [ $RETVAL -eq 7 ]; then 
     failure $"$prog reload" 
    else 
     $supervisorctl $OPTIONS status 
    fi 
} 

restart() { 
    stop 
    start 
} 

case "$1" in 
    start) 
     start 
     ;; 
    stop) 
     stop 
     ;; 
    status) 
     status -p ${pidfile} $supervisord 
     RETVAL=$? 
     [ $RETVAL -eq 0 ] && $supervisorctl $OPTIONS status 
     ;; 
    restart) 
     restart 
     ;; 
    condrestart|try-restart) 
     if status -p ${pidfile} $supervisord >&/dev/null; then 
      stop 
      start 
     fi 
     ;; 
    force-reload|reload) 
     reload 
     ;; 
    *) 
     echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload}" 
     RETVAL=2 
    esac 

    exit $RETVAL 

Sau khi bạn đóng và tiết kiệm, làm cho nó thực thi bởi tất cả người dùng:

chmod a+x /etc/init.d/supervisord 

Bạn tiếp theo sẽ muốn xác nhận rằng quá trình supervisord là trong thực tế chạy bằng cách chạy lệnh sau:

ps -fe | grep supervisor 

Nếu bạn không xem/usr/bin/supervisord như một quá trình đang chạy thì bạn cần phải bắt đầu nó lên theo cách thủ công:

sudo service supervisord start 

Giám sát cần được khởi động bất cứ lúc nào máy chủ khởi động lại. Điều này có thể được thực hiện tương tự như cách apache được bật sau khi khởi động lại bằng chkconfig.

Đầu tiên thêm nó vào chkconfig, bắt đầu của bạn lên quá trình danh sách

sudo chkconfig --add supervisord 

Sau đó nói với chkconfig để bật tính năng này sau khi khởi động

sudo chkconfig supervisord on 
+0

Tôi đã tạo tệp "/etc/init.d/supervisord" và sau đó chạy "sudo service supervisord start" nhưng tôi đã nhận được "env: /etc/init.d/supervisord: Quyền bị từ chối" .... bất kỳ ý tưởng nào? Tôi đang sử dụng ec2 Amazon AIM với centos 7 – llioor

+1

'chmod a + x/etc/init.d/supervisord' để làm cho nó thực thi được một bước mất tích trong câu trả lời rất chi tiết này :) –

+0

Cảm ơn Filipe, tôi sẽ cập nhật câu trả lời . –

4

người giám sát không biết rằng bạn đã thêm chương trình. This is answered on serverfault, làm như sau:

supervisorctl reread 
supervisorctl update 

Bằng cách này, nó dễ dàng hơn để duy trì các file cấu hình bằng cách sử dụng cú pháp conf.d. Nói cách khác, hãy tạo một tệp có tên là /etc/supervisor/conf.d/artisan.conf. Mọi thứ khác đều giống nhau, nhưng phiên bản kiểm soát tệp cấu hình của bạn dễ dàng hơn và đồng bộ hóa chúng với máy khi thiết lập.

+0

Hey nhờ trả lời nhanh chóng của bạn! Tôi không thể chờ đợi để có được ra và thử nghiệm này ra! –

+0

Tôi đã thử và có một số lỗi. Tôi nhận thấy rằng tôi không thể có được người giám sát để bắt đầu, khi chạy như su $ service supervisord bắt đầu tôi nhận được giám sát: dịch vụ không được công nhận. Tôi có cần một tập lệnh khởi động như thế này không? http://translate.google.com/translate?hl=vi&sl=ja&u=http://d.hatena.ne.jp/massat/20111013/1318484253&prev=search –

+0

cách bạn cài đặt người giám sát? Tôi cho rằng bạn đang sử dụng AWI Linux AMI? (chỉnh sửa câu hỏi gốc của bạn, thêm nội dung đó, sau đó thêm nhận xét ở đây. Tôi sẽ cố gắng tạo lại.) – tedder42

Các vấn đề liên quan