首页
✨运维
🎉安装
👀踩坑
🤷‍♂️学习
😊关于
  • 分类
  • 标签
  • 归档
GitHub

Summer

运维界的小白
首页
✨运维
🎉安装
👀踩坑
🤷‍♂️学习
😊关于
  • 分类
  • 标签
  • 归档
GitHub
  • K8s

  • shell

    • 自动重启应用脚本
      • 1.脚本介绍
      • 2.Autorestart.sh
      • 3.添加定时任务
    • 自动重启docker脚本
    • 安装java脚本
    • 安装mysql脚本
    • 安装elasticsearch脚本
    • 安装redis脚本
    • 清理docker日志脚本
    • 钉钉报警脚本
    • 彩色进度条脚本
    • 奇数行和偶数行合并
    • 备份mysql脚本
    • cpu硬盘报警脚本
    • 安装node-exporter脚本
  • Zabbix

  • Python

  • Redis

  • Elasticsearch

  • prometheus

  • Mysql

  • 学习
  • shell
summer
2020-10-27

自动重启应用脚本

# 1.脚本介绍

  • 脚本用到lsof命令注意yum一下

yum install -y lsof

  • 结合定时任务可每分钟检索运行的nginx,elasticsearch,redis,mysql;如果应用挂掉则尝试重启

# 2.Autorestart.sh

#!/bin/bash
#log文件
MonitorLog=/home/summer/autostart.log 
user=summer 

#检测nginx80端口
curtime=$(date "+%Y-%m-%d %H:%M:%S")
checkNginx=`echo "summer" | sudo -S lsof -i:80 |grep 'nginx' |grep -v grep |grep -v agent|sort | tail -1 | cut -f 1 -d ' '`
if [[ $checkNginx != 'nginx' ]]; then
    echo "$curtime 系统检测到nginx,已挂掉,启动中...." >> $MonitorLog;
    /home/$user/nginx/sbin/nginx 
    if [ $? -eq 0 ]; then
        echo "$curtime nginx启动完成" >> $MonitorLog;
    else
        echo "$curtime nginx启动失败" >> $MonitorLog;
    fi
else
    echo "$curtime 系统检测到nginx运行正常" >> $MonitorLog;
fi

#检测Redis
#checkRedis=`echo "summer" | sudo -S lsof -i:6379 |grep 'redis-ser' |grep -v grep |grep -v agent|sort | tail -1 | cut -f 1 -d ' '`
checkRedis=`lsof -i:27000 |grep 'redis-ser' |grep -v grep |grep -v agent|sort | tail -1 | cut -f 1 -d ' '`
if [[ $checkRedis != 'redis-ser' ]]; then
    echo "$curtime 系统检测到Redis已挂掉,启动中...." >> $MonitorLog;
    #单节点6379(注意改lsof端口)
    #/home/$user/redis-5.0.8/src/redis-server /etc/redis.conf
    #多节点2700(注意改lsof端口)
    /home/summer/redis-5.0.8/utils/create-cluster/create-cluster start
    if [ $? -eq 0 ]; then
        echo "$curtime Redis启动完成" >> $MonitorLog;
    else
        echo "$curtime Redis启动失败" >> $MonitorLog;
    fi
else
    echo "$curtime 系统检测到Redis运行正常" >> $MonitorLog;
fi

#检测mysql
checkMysql=`echo "summer" | sudo -S lsof -i:23306 |grep 'mysql' |grep -v grep |grep -v agent|sort | tail -1 | cut -f 1 -d ' '`
if [[ $checkMysql != 'mysqld' ]]; then
    echo "$curtime 系统检测到Mysql已挂掉,启动中...." >> $MonitorLog;
    mysqld start 
    if [ $? -eq 0 ]; then
        echo "$curtime Mysql启动完成" >> $MonitorLog;
    else
        echo "$curtime Mysql启动失败" >> $MonitorLog;
    fi
else
    echo "$curtime 系统检测到Mysql运行正常" >> $MonitorLog;
fi

#检测elasticsearch
ESPID=`ps -ef | grep elasticsearch | grep -w 'elasticsearch' | grep -v 'grep' | awk '{print $2}' | head -n 1` &>/dev/null
if [[ $ESPID ]] ; then
    echo "$curtime 系统检测到Elasticsearch运行正常" >> $MonitorLog
else
    echo "$curtime 系统检测到Elasticsearch已挂掉,启动中...." >> $MonitorLog
    # /home/summer/elasticsearch-7.6.0/bin/elasticsearch -d 
    /home/$user/elasticsearch-6.3.1/bin/elasticsearch -d
    if [ $? -eq 0 ]; then
        echo "$curtime Elasticsearch启动完成" >> $MonitorLog;
    else
        echo "$curtime Elasticsearch启动失败" >> $MonitorLog;
    fi
fi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

# 3.添加定时任务

crontab -e
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=""
*/1 * * * * cd /home/summer && ./Autorestart.sh >/dev/null 2>&1
1
2
3
4
5
pv和pvc
自动重启docker脚本

← pv和pvc 自动重启docker脚本→

最近更新
01
redis持久化
12-08
02
redis为什么这么快
12-08
03
redis的优缺点
12-08
更多文章>
Theme by Vdoing | Copyright © 2019-2020 Evan Xu | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式