首页 > 代码库 > ELK相关启动脚本

ELK相关启动脚本

elasticsearch启动脚本

#!/bin/bash
# Description:Elasticsearch ORS SERVER
ES_HOME=/usr/local/elasticsearch-5.0.0
PID=$(jps | grep Elasticsearch | awk ‘{print $1}‘)
ES_STOP=$ES_HOME/bin/shutdown.sh
ES_START=$ES_HOME/bin/startup.sh

#Necessary environment variables
ES_USER=hadoop

case $1 in
        start)
        if [ -n "$PID" ]
        then
            echo "elasticsearch process is already running."
        else
        echo -n "Starting elasticsearch Server..."
        /bin/su - $ES_USER -s /bin/bash -c $ES_START
        echo " done"
        fi
        ;;
        stop)
        if [ -z "$PID" ]
        then
                echo "elasticsearch process is not running."
        else
                echo -n "Stopping elasticsearch Server..."
        /bin/su - $ES_USER -s /bin/bash -c $ES_STOP
        echo " done"
        fi
        ;;
        restart)
        $0 stop
        $0 start
        ;;
        *)
        echo "Usage: service $0 {start|stop|restart}" >&2
        exit 1
esac


elasticsearch相关子脚本

cat > /usr/local/elasticsearch-5.0.0/bin/shutdown.sh <<EOF
#!/bin/bash
PID=\$(jps | grep Elasticsearch | awk ‘{print \$1}‘)
if [ -n "\$PID" ]; then
    kill -9 \$PID > /dev/null 2>&1
fi
EOF
cat > /usr/local/elasticsearch-5.0.0/bin/startup.sh <<EOF
#!/bin/bash
/usr/local/elasticsearch-5.0.0/bin/elasticsearch -d
EOF


kibana启动脚本

#!/bin/bash
# Description:kibana ORS SERVER
KB_HOME=/usr/local/kibana-5.0.0-linux-x86_64
PID=$(ps -ef|grep node|grep -v grep|awk ‘{print $2}‘)
KB_LOG="/data/kibana_logs"
KB_START=$KB_HOME/bin/startup.sh
KB_STOP=$KB_HOME/bin/shutdown.sh
#Necessary environment variables
KB_USER=hadoop
KB_GROUP=hadoop

[ ! -d "$KB_LOG" ] && mkdir "$KB_LOG"
chown -R "$KB_USER":"$KB_GROUP" "$KB_LOG"
chmod 755 "$KB_LOG"

case $1 in
        start)
        if [ -n "$PID" ]
        then
            echo "Kibana process is already running."
        else
        echo -n "Starting Kibana Server..."
        /bin/su - $KB_USER -s /bin/bash -c $KB_START
        echo " done"
        fi
        ;;
        stop)
        if [ -z "$PID" ]
        then
                echo "Kibana process is not running."
        else
                echo "Stopping Kibana Server..."
        /bin/su - $KB_USER -s /bin/bash -c $KB_STOP
                echo "Kibana Server has been stopped."
        fi
        ;;
        restart)
        $0 stop
        $0 start
        ;;
        *)
        echo "Usage: service $0 {start|stop|restart}" >&2
        exit 1
esac

kibana相关子脚本

cat >/usr/local/kibana-5.0.0-linux-x86_64/bin/startup.sh<<EOF
#!/bin/bash
nohup sh /usr/local/kibana-5.0.0-linux-x86_64/bin/kibana >> /data/kibana_logs/kibana.stdout 2>> /data/kibana_logs/kibana.stderr &
EOF
cat >/usr/local/kibana-5.0.0-linux-x86_64/bin/shutdown.sh<<EOF
#!/bin/bash
ps -ef|grep node|grep -v grep|awk ‘{print \$2}‘|xargs kill -9
EOF


本文出自 “运维人生” 博客,请务必保留此出处http://jinyan2049.blog.51cto.com/881440/1914597

ELK相关启动脚本