elasticsearch设置执行脚本并添加开机启动

/etc/init.d目录下新建文件elasticsearch

#!/bin/sh
#chkconfig: 2345 80 05
#description: elasticsearch
 
export JAVA_HOME=/usr/java/jdk1.8.0_112
export JAVA_BIN=/usr/java/jdk1.8.0_112/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH

case "$1" in
start)
    su lyt<<!
    cd /home/lyt/dev-repo/elk5/elasticsearch-5.6.9
    ./bin/elasticsearch -d
!
    echo "elasticsearch startup"
    ;;  
stop)
    es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
    kill -9 $es_pid
    echo "elasticsearch stopped"
    ;;  
restart)
    es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
    kill -9 $es_pid
    echo "elasticsearch stopped"
    su lyt<<!
    cd /home/lyt/dev-repo/elk5/elasticsearch-5.6.9
    ./bin/elasticsearch -d
!
    echo "elasticsearch startup"
    ;;  
*)
    echo "start|stop|restart"
    ;;  
esac

exit $?

保存退出,赋予执行权限

chmod +x elasticsearch 

添加到开机启动任务

chkconfig -add elasticsearch

如果不设置开机启动的话,也可以使用service elasticsearch start/stop/restart来操作

转载于:https://my.oschina.net/liuyuantao/blog/1798724

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是elasticsearch一键启动脚本的示例: #!/bin/bash # Elasticsearch one-click start script # Define the Elasticsearch home directory ES_HOME=/path/to/elasticsearch # Define the Elasticsearch configuration file ES_CONFIG_FILE=$ES_HOME/config/elasticsearch.yml # Define the Elasticsearch log directory ES_LOG_DIR=$ES_HOME/logs # Define the Elasticsearch data directory ES_DATA_DIR=$ES_HOME/data # Define the Elasticsearch process ID file ES_PID_FILE=$ES_HOME/elasticsearch.pid # Check if Elasticsearch is already running if [ -f $ES_PID_FILE ]; then echo "Elasticsearch is already running. Exiting." exit 1 fi # Start Elasticsearch with the specified configuration file and log directory $ES_HOME/bin/elasticsearch -d -p $ES_PID_FILE --quiet -Epath.logs=$ES_LOG_DIR -Epath.data=$ES_DATA_DIR -Epath.conf=$ES_CONFIG_FILE # Check if Elasticsearch started successfully if [ $? -eq 0 ]; then echo "Elasticsearch started successfully." else echo "Failed to start Elasticsearch." fi # Wait for Elasticsearch to start sleep 10 # Check if Elasticsearch is running if pgrep -f "$ES_HOME/bin/elasticsearch" > /dev/null; then echo "Elasticsearch is running." else echo "Failed to start Elasticsearch." fi 这个脚本启动Elasticsearch,并使用指定的配置文件、日志目录和数据目录。它还检查Elasticsearch是否已经在运行,并等待10秒钟以确保Elasticsearch已经启动。如果Elasticsearch启动成功,则脚本会输出Elasticsearch已经成功启动的消息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值