👉 Elasticsearch启动脚本 💎
编写启动脚本 elasticsearch.sh
#!/bin/sh
export JAVA_HOME=/opt/software/java11/jdk-11.0.11
export PATH=$JAVA_HOME/bin:$PATH
export ES_HOME=/opt/software/elasticsearch/elasticsearch-7.6.1
export PATH=$ES_HOME/bin:$PATH
if [ $# -lt 1 ]
then
echo "No Args Input..."
exit ;
fi
case $1 in
start)
su - es -c "$ES_HOME/bin/elasticsearch -d -p pid"
echo "elasticsearch is started"
;;
stop)
pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
kill -9 $pid
echo "elasticsearch is stopped"
;;
restart)
pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
kill -9 $pid
echo "elasticsearch is stopped"
sleep 1
su - es -c "$ES_HOME/bin/elasticsearch -d -p pid"
echo "elasticsearch is started"
;;
*)
echo "start|stop|restart"
;;
esac
exit 0
赋予执行权限:
chmod +x elasticsearch.sh
参数说明:
su - es -c “命令”, 这个表示脚本内切换es用户一次并执行 -c 后面的命令,然后退出es普通用户到当前用户。