Files
2026-01-14 08:37:21 +08:00

110 lines
1.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Redis连接问题修复指南
## 问题描述
应用无法连接到Redis服务器 `192.168.200.130:6379`,导致任务调度服务异常。
## 解决步骤
### 1. 检查Redis服务状态
#### 在Linux服务器上检查
```bash
# 检查Redis进程
ps aux | grep redis
# 检查Redis端口是否监听
netstat -tlnp | grep 6379
# 或
ss -tlnp | grep 6379
```
#### 在Windows服务器上检查
```powershell
# 检查Redis进程
Get-Process | Where-Object {$_.ProcessName -like "*redis*"}
# 检查端口
netstat -ano | findstr 6379
```
### 2. 启动Redis服务
#### Linux:
```bash
# 如果使用systemd
sudo systemctl start redis
sudo systemctl enable redis # 设置开机自启
# 或直接启动
redis-server /path/to/redis.conf
```
#### Windows:
```powershell
# 如果Redis作为服务安装
net start redis
# 或直接运行
redis-server.exe
```
### 3. 验证Redis连接
```bash
# 测试连接
redis-cli -h 192.168.200.130 -p 6379 ping
# 应该返回: PONG
```
### 4. 检查防火墙
确保防火墙允许6379端口
```bash
# Linux
sudo firewall-cmd --add-port=6379/tcp --permanent
sudo firewall-cmd --reload
# 或使用iptables
sudo iptables -A INPUT -p tcp --dport 6379 -j ACCEPT
```
### 5. 检查Redis配置
确保Redis配置文件 `redis.conf` 中:
```conf
# 允许外部连接(如果需要)
bind 0.0.0.0
# 或
bind 192.168.200.130
# 保护模式(如果只允许本地,需要关闭)
protected-mode no
```
### 6. 检查网络连通性
从应用服务器测试:
```bash
# 测试网络连通性
ping 192.168.200.130
# 测试端口连通性
telnet 192.168.200.130 6379
# 或
nc -zv 192.168.200.130 6379
```
## 临时解决方案
如果Redis暂时无法启动可以考虑
1. 使用本地Redis修改配置文件中的Redis地址
2. 使用Docker运行Redis
```bash
docker run -d -p 6379:6379 redis:latest
```
## 验证修复
修复后重启应用服务观察日志中不再出现Redis连接错误。