/usr/lib/systemd/system/flume.service
#[unit]配置了服务的描述,规定了在network启动之后执行。
#[service]配置服务的pid,服务的启动,停止,重启。
#[install]配置了使用用户。
[Unit]
Description=Flume
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
#Type=forking
#Type=simple
Restart=on-failure
PIDFile=/usr/local/apache-flume-1.9.0-bin/bin/flume.pid
#ExecStart=/usr/local/apache-flume-1.9.0-bin/bin/flume.sh start >> /dev/null 2>&1 &
ExecStart=/usr/local/apache-flume-1.9.0-bin/bin/monitor.sh
#ExecReload=/usr/local/apache-flume-1.9.0-bin/bin/monitor.sh
#ExecStop=/usr/local/apache-flume-1.9.0-bin/bin/flume.sh stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
monitorh
#!/bin/sh
while :
do
procnum=` ps -ef|grep java |grep flume|grep -v grep|wc -l`
if [ $procnum -eq 0 ]; then
sh /usr/local/apache-flume-1.9.0-bin/bin/flume.sh start
fi
sleep 60
done
flume.s
#!/bin/bash
#日期:20170925
#用户:Jerome
#参数:start|stop|restart
#功能:flume 启动停止重启
#使用方法:
#./execflume.sh start flume_cmbc.conf(配置文件,自己修改) Cobub(代理名称,自己修改)
#./execflume.sh stop
#./execflume.sh restart flume_cmbc.conf(配置文件,自己修改) Cobub(代理名称,自己修改)
#path=$(cd `dirname $0`; pwd)
FLUME_HOME=/usr/local/apache-flume-1.9.0-bin
export JAVA_HOME=/usr/local/jdk
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
echo $FLUME_HOME
#path=$FLUME_HOME/conf
#echo $path
#conf-file=$2
#AgentName=$3
conf_file=flume-kafka-sink-product.conf
#conf_file=flume-kafka-sink-test.conf
AgentName="a1"
JAR="flume"
function start(){
echo "开始启动 ...."
num=`ps -ef|grep java|grep $JAR|wc -l`
echo "进程数:$num"
if [ "$num" = "0" ] ; then
#eval nohup java -Xmx512m -jar -DplanNames=$planNames -DconfigPath=$CONFIG_PATH $jarpath/$JAR `echo $@|cut -d " " -f3-$#` >> /dev/null 2>&1 &
# 请自行修改启动的所需要的参数
nohup $FLUME_HOME/bin/flume-ng agent -c $FLUME_HOME/conf -f $FLUME_HOME/conf/$conf_file --name $AgentName >> /dev/null 2>&1 &
echo "启动成功...."
echo "日志路径: $FLUME_HOME/logs/flume.log"
else
echo "进程已经存在,启动失败,请检查....."
exit 0
fi
}
function stop(){
echo "开始stop ....."
num=`ps -ef|grep java|grep $JAR|wc -l`
if [ "$num" != "0" ] ; then
#ps -ef|grep java|grep $JAR|awk '{print $2;}'|xargs kill -9
# 正常停止flume
ps -ef|grep java|grep $JAR|awk '{print $2;}'|xargs kill
echo "进程已经关闭..."
else
echo "服务未启动,无需停止..."
fi
}
function restart(){
echo "begin stop process ..."
stop
# 判断程序是否彻底停止
num=`ps -ef|grep java|grep $JAR|wc -l`
while [ $num -gt 0 ]; do
sleep 1
num=`ps -ef|grep java|grep $JAR|wc -l`
done
echo "process stoped,and starting ..."
start
echo "started ..."
}
case "$1" in
"start")
start $@
exit 0
;;
"stop")
stop
exit 0
;;
"restart")
restart $@
exit 0
;;
*)
echo "用法: $0 {start|stop|restart}"
exit 1
;;
esac
systemctl status flume
service flume status