1. 启动elastic ,shell脚本如下
#!/bin/bash
a=$(lsof -i:9200)
if [[ -z $a ]];then
a=$(lsof -i:9200)
if [[ -z $a ]];then
su admin
su admin sh -c '
cd /home/es/elasticsearch-7.17.2/bin/
echo `pwd`
# 获取当前时间
now=$(date +%Y%m%d%H%M)
echo $now
# 拼接日志文件名称
logfile=elasticsearch-$now.log
echo $logfile
nohup ./elasticsearch > $logfile 2>&1 & '
else
echo '程序运行正常 '
fi
else
1.2.效果如下
![在这里插入图片描述](https://img-blog.csdnimg.cn/5ce1437a881f4a5a9bbf7db54b3a5750.png)
2. 启动logstash,shell脚本如下
a=$(ps -aux|grep Logstash| grep -v grep | awk '{print $2}')
if [[ -z $a ]];then
su root
read -s 'yundun123'
su root sh -c '
cd /home/es/logstash-7.17.2/bin/
now=$(date +%Y%m%d%H%M)
# 拼接日志文件名称
logfile=kibana-$now.log
touch $logfile
nohup ./logstash -f ../config/mysql.conf >$logfile 2>&1 &
echo '正在启动'
'
else
echo "运行正常"
fi
3. 启动logstash,shell脚本如下
a=$(lsof -i:5601)
if [[ -z $a ]];then
su admin
whoami
su admin sh -c '
whoami
cd /home/es/kibana-7.17.2/bin/
# 获取当前时间
now=$(date +%Y%m%d%H%M)
# 拼接日志文件名称
logfile=kibana-$now.log
touch $logfile
nohup ./kibana --allow-root > $logfile 2>&1 &
'
echo $logfile
else
echo '程序运行正常 '
fi
![在这里插入图片描述](https://img-blog.csdnimg.cn/2170a60669134c2ca62fab10b0a8ffd4.png)
4.kinaba
#!/bin/bash
a=$(lsof -i:5601)
if (lsof -i:5601 | grep LISTEN) then
logfile="/home/es/kibana-7.17.2/bin/kibana-$(date +%Y%m%d%H%M).log"
su admin -c "
whoami
cd /home/es/kibana-7.17.2/bin/
nohup ./kibana --allow-root > $logfile 2>&1 &
"
echo $logfile
else
echo '程序运行正常'
fi