shell启动elasticsearch

方法一:

1.创建脚本文件(以.sh结尾)

# vi elasticsearch.sh

#!/bin/bash
# kconfig: 2345 91 11
# description: elasticsearch
#定义变量
PORT=9200
NAME=elasticsearch
ID=`ps -aux | grep "$NAME" | grep -v "grep" | awk '{print $2}'`
CHECK_PORT=`netstat -tnlp|grep "$PORT"`
ELASTICSEARCH_SERVER=/usr/software/elasticsearch-6.5.4/bin/elasticsearch
RETAVL=0
#检查shelk公共函数库是否存在,存在就加载
FUNCTIONS_PATH=/etc/init.d/functions
[ -f $FUNCTIONS_PATH ]&& source $FUNCTIONS_PATH
#检查文件是否存在并可执行
[ -x $ELASTICSEARCH_SERVER ]|| exit 0

#定义函数
#检查是否执行成功
check(){
	RETAVL=$?
	if 
		[[ "$RETAVL" = 0 ]];then
		action "elasticsearch is $1" /bin/true
	else
		action "elasticsearch is $1" /bin/false	
	fi
}
#启动服务
start(){
	if
		[[ "$CHECK_PORT" != "" ]];then
		echo "elasticsearch already running"
	else
	su - es <<!
		$ELASTICSEARCH_SERVER -d
exit
!
		check Started				
	fi


	
}
#停止服务
stop(){
	if
		[[ "$CHECK_PORT" = "" ]];then
		echo "elasticsearch is not running."
	else
		kill -9 $ID
		check Stopped
	fi

}

#重启服务
restart(){
	stop
	sleep 2
	start
	

}

#判断
case "$1" in
start)
		start
		;;
stop)
		stop
		;;
restart)
		restart
		;;
*)
		echo $"Usage:$0{start|stop|restart|help}"
esac
exit $RETAVL



2.增加脚本可执行权限

# chmod +x elasticsearch.sh

 

3.将脚本移动到/etc/rc.d/init.d目录下

# mv elasticsearch.sh /etc/rc.d/init.d

 

4.将脚本添加进开机启动

# cd /etc/rc.d/init.d

# chkconfig –add nginx.sh

# chkconfig nginx.sh on

 

5.查看开机启动列表

# chkconfig --list

方法二:

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值