admin管理员组文章数量:1794759
使用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本文标签: 使用shell脚本设置自动重启redis
版权声明:本文标题:使用shell脚本设置自动重启redis 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1755044524a1709814.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论