首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >使用shell脚本设置自动重启redis

使用shell脚本设置自动重启redis

作者头像
半夜喝可乐
发布2024-09-30 17:43:25
发布2024-09-30 17:43:25
6390
举报
文章被收录于专栏:小轻论坛小轻论坛

网站的redis服务经常会因为缓存问题而停止,显示错误代码:

代码语言:javascript
复制
Error establishing a Redis connection

我们可以在宝塔面板设置shell命令。

代码语言:javascript
复制
#!/bin/bash

# 检测 Redis 是否在运行
redis_status=$(systemctl is-active redis.service)

if [ "$redis_status" != "active" ]; then
    echo "Redis is not running. Restarting Redis..."
    systemctl start redis.service
    echo "Redis restarted."
fi

# 检测网站是否可访问
website_url="http://example.com"  # 替换为你要检测的网站 URL
http_status=$(curl -s -o /dev/null -w "%{http_code}" $website_url)

if [ "$http_status" != "200" ]; then
    echo "Website is not accessible. Restarting Redis..."
    systemctl restart redis.service
    echo "Redis restarted."
fi

设置时间为每5分钟检测一次,保证网站能正常访问,当然也可以设置其他时间。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-07-19,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档