linux-tutorial/codes/linux/ops/soft/elk/boot-elk.sh

74 lines
2.2 KiB
Bash
Raw Normal View History

2018-02-23 15:42:53 +08:00
#!/usr/bin/env bash
2018-01-26 17:31:20 +08:00
# 检查脚本输入参数
checkInput() {
2018-02-02 15:59:55 +08:00
if [ "${app}" == "" ] || [ "${oper}" == "" ]; then
2018-01-26 17:31:20 +08:00
echo "请输入脚本参数name"
2018-02-02 15:59:55 +08:00
echo " app: 要启动的进程关键字必填。可选值elasticsearch|logstash|kibana|filebeat"
echo " oper: 执行操作必填。可选值start|stop"
echo "例:./boot-elk.sh logstash start"
2018-01-26 17:31:20 +08:00
exit 0
fi
if [ "${app}" != "elasticsearch" ] && [ "${app}" != "logstash" ] && [ "${app}" != "kibana" ] && [ "${app}" != "filebeat" ]; then
echo "name 输入错误"
echo "可选值elasticsearch|logstash|kibana|filebeat"
exit 0
fi
}
# 检查文件是否存在,不存在则退出脚本
checkFileExist() {
if [ ! -f "$1" ]
then
echo "关键文件 $1 找不到,脚本执行结束"
exit 0
fi
}
startup() {
if [ "${app}" == "elasticsearch" ]; then
checkFileExist ${ELASTICSEARCH_BIN_PATH}/elasticsearch
nohup sh ${ELASTICSEARCH_BIN_PATH}/elasticsearch >>${ELASTICSEARCH_BIN_PATH}/nohup.out 2>&1 &
elif [ "${app}" == "logstash" ]; then
checkFileExist ${LOGSTASH_BIN_PATH}/logstash
2018-02-02 15:59:55 +08:00
nohup sh ${LOGSTASH_BIN_PATH}/logstash -f ${LOGSTASH_BIN_PATH}/logstash.conf >>${LOGSTASH_BIN_PATH}/nohup.out 2>&1 &
2018-01-26 17:31:20 +08:00
elif [ "${app}" == "kibana" ]; then
checkFileExist ${KIBANA_BIN_PATH}/kibana
nohup sh ${KIBANA_BIN_PATH}/kibana >> ${KIBANA_BIN_PATH}/nohup.out 2>&1 &
elif [ "${app}" == "filebeat" ]; then
checkFileExist ${FILEBEAT_PATH}/filebeat
touch ${FILEBEAT_PATH}/nohup.out
nohup ${FILEBEAT_PATH}/filebeat -e -c ${FILEBEAT_PATH}/filebeat.yml -d "publish" >> ${FILEBEAT_PATH}/nohup.out 2>&1 &
fi
}
2018-02-02 15:59:55 +08:00
shutdown() {
pid=`ps -ef | grep java | grep ${app} | awk '{print $2}'`
kill -9 ${pid}
}
2018-01-26 17:31:20 +08:00
##############################__MAIN__########################################
2018-02-02 15:59:55 +08:00
app=$1
oper=$2
version=6.1.1
2018-09-29 10:16:24 +08:00
ELASTICSEARCH_BIN_PATH=/opt/elastic/elasticsearch-${version}/bin
LOGSTASH_BIN_PATH=/opt/elastic/logstash-${version}/bin
KIBANA_BIN_PATH=/opt/elastic/kibana-${version}-linux-x86_64/bin
FILEBEAT_PATH=/opt/elastic/filebeat-${version}-linux-x86_64
2018-02-02 15:59:55 +08:00
2018-01-26 17:31:20 +08:00
checkInput
2018-02-02 15:59:55 +08:00
case ${oper} in
start)
echo "启动 ${app}"
startup
;;
stop)
echo "终止 ${app}"
shutdown
;;
* ) echo "${oper} is invalid oper";;
esac