脚本
#!/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
自动启动
给创建的脚本设置可执行权限
[root@manager flume-1.8.0]# chmod +x start.sh
编辑/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
文件
[root@manager conf]# cp flume-env.sh.template flume-env.sh
修改内容,填上JAVA_HOME
(根据自己的填写)
export JAVA_HOME=/opt/java-1.8.0_121
保存退后,再重启可以验证flume-agent
自启动成功。