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

网站的redis服务经常会因为缓存问题而停止,显示错误代码:代码语言:javascript代码运行次数:0运行复制Error establishing a Redis connection我们可以在宝塔面板设置shell命令。代码语言:ja

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

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

代码语言:javascript代码运行次数:0运行复制
Error establishing a Redis connection

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

代码语言:javascript代码运行次数:0运行复制
#!/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=";  # 替换为你要检测的网站 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 删除redis服务脚本网站shell

发布者:admin,转转请注明出处:http://www.yc00.com/web/1755044521a5232260.html

相关推荐

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

    网站的redis服务经常会因为缓存问题而停止,显示错误代码:代码语言:javascript代码运行次数:0运行复制Error establishing a Redis connection我们可以在宝塔面板设置shell命令。代码语言:ja

    1月前
    160

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信