在 CentOS 上测试 Redis 是否正常运行,通常可以从 服务状态、端口、客户端连接、功能测试 几个方面来做。下面按常见场景一步步说明。
rpm -qa | grep redis
# 或
which redis-server
如果没有安装:
yum install -y redis
systemctl start redis
systemctl enable redis
systemctl status redis
正常运行应看到:
Active: active (running)
ss -lntp | grep 6379
# 或
netstat -lntp | grep 6379
看到类似:
LISTEN 0 128 127.0.0.1:6379
说明 Redis 已监听端口。
redis-cli
ping
✅ 正常返回:
PONG
set test "hello centos"
get test
✅ 返回:
"hello centos"
keys *
exit
如果 Redis 配置了密码:
redis-cli
auth 你的密码
ping
redis-cli -a 密码
⚠️ 生产环境不建议在命令行直接写密码
vi /etc/redis.conf
确认或修改为:
bind 0.0.0.0
protected-mode no
systemctl restart redis
redis-cli -h redis服务器IP -p 6379 ping
redis-benchmark -q
或指定参数:
redis-benchmark -h 127.0.0.1 -p 6379 -c 10 -n 10000
journalctl -u redis -xe
firewall-cmd --add-port=6379/tcp --permanent
firewall-cmd --reload
systemctl start redis
redis-cli
ping
如果你愿意,可以告诉我:
我可以给你更精确的测试方案。