天天看點

Linux下多個flume-agent自動啟動腳本腳本自動啟動

文章目錄

  • 腳本
  • 自動啟動

腳本

#!/bin/bash

# to start flume for minute 15min and hour!


flume_home="/opt/flume-1.8.0"
flume_log_dir="/var/log/flume"
if [ ! -d "$flume_log_dir" ];then
  mkdir $flume_log_dir
fi

ps_minute=`ps -ef | grep flume | grep '\-n a1'`
if [ ! -n "$ps_minute" ];then
  echo "ready to start flume-agent a1 for minute..."
  nohup ${flume_home}/bin/flume-ng agent -c ${flume_home}/conf -f ${flume_home}/conf/mysqlsinkminute.singleagent.linux.conf -n a1 -Dflume.root.logger=INFO,console >> ${flume_log_dir}/minute.log &
else
  echo "flume-agent a1 for minute is running..."
fi


ps_15min=`ps -ef | grep flume | grep '\-n a2'`
if [ ! -n "$ps_15min" ];then
  echo "ready to start flume-agent a2 for 15min..."
  nohup ${flume_home}/bin/flume-ng agent -c ${flume_home}/conf -f ${flume_home}/conf/mysqlsink15min.singleagent.linux.conf -n a2 -Dflume.root.logger=INFO,console >> ${flume_log_dir}/15min.log &
else
  echo "flume-agent a2 for 15min is running..."
fi


ps_hour=`ps -ef | grep flume | grep '\-n a3'`
if [ ! -n "$ps_hour" ];then
  echo "ready to start flume-agent a3 for hour..."
  nohup ${flume_home}/bin/flume-ng agent -c ${flume_home}/conf -f ${flume_home}/conf/mysqlsinkhour.singleagent.linux.conf -n a3 -Dflume.root.logger=INFO,console >> ${flume_log_dir}/hour.log &
else
  echo "flume-agent a3 for hour is running..."
fi

           

自動啟動

給建立的腳本設定可執行權限

編輯

/etc/rc.d/rc.local

檔案

在最後增加一行

/bin/sh /opt/flume-1.8.0/start.sh
           

開機重新開機後,發現并沒有

flume

的程序

檢視系統日志

/var/log/message

發現如下,但是系統環境變量裡肯定是填了

JAVA_HOME

的,如果沒填,直接啟動

flume

程式也是失敗的

Aug  9 01:47:01 manager rc.local: ready to start flume-agent a1 for minute...
Aug  9 01:47:01 manager rc.local: Warning: JAVA_HOME is not set!
Aug  9 01:47:01 manager rc.local: Error: Unable to find java executable. Is it in your PATH?
Aug  9 01:47:02 manager rc.local: ready to start flume-agent a2 for 15min...
Aug  9 01:47:02 manager rc.local: Warning: JAVA_HOME is not set!
Aug  9 01:47:02 manager rc.local: Error: Unable to find java executable. Is it in your PATH?
Aug  9 01:47:03 manager rc.local: ready to start flume-agent a3 for hour...
           

解決辦法是進入

flume

安裝目錄下

conf

檔案夾

複制一個

flume-env.sh

檔案

修改内容,填上

JAVA_HOME

(根據自己的填寫)

export JAVA_HOME=/opt/java-1.8.0_121
           

儲存退後,再重新開機可以驗證

flume-agent

自啟動成功。

繼續閱讀