查看服务器是否按照redis, 未安装的话需要提供安装操作步骤检查 Redis 是否安装 完整安装教程我给你整理了一键检查命令和最常用、最稳定的 Redis 安装步骤适用于 CentOS/RHEL 系列、Ubuntu/Debian 系列直接复制执行即可。一、先检查服务器是否已安装 Redis直接在服务器终端执行以下任意一条命令检查bash运行# 检查是否安装了 redis redis-server --version # 或者检查 redis 服务是否运行 systemctl status redis判断结果出现版本号如Redis server v7.2.3 ...→已安装提示 command not found→未安装按下面步骤安装二、Redis 安装步骤通用最稳定方案方案 1Ubuntu / Debian 系统最常用bash运行# 1. 更新软件源 sudo apt update # 2. 安装 Redis sudo apt install redis-server -y # 3. 设置开机自启并启动服务 sudo systemctl enable redis-server sudo systemctl start redis-server # 4. 验证是否安装成功 redis-server --version redis-cli ping出现PONG说明安装并运行成功方案 2CentOS / RHEL / Fedora 系统bash运行# 1. 安装 EPEL 源CentOS 默认没有 Redis sudo yum install epel-release -y # 2. 安装 Redis sudo yum install redis -y # 3. 启动并设置开机自启 sudo systemctl enable redis sudo systemctl start redis # 4. 验证 redis-server --version redis-cli ping出现PONG即为成功。三、安装后常用命令备用bash运行# 查看 Redis 运行状态 systemctl status redis # 停止 Redis systemctl stop redis # 重启 Redis systemctl restart redis # 进入 Redis 命令行 redis-cli总结用redis-server --version一键检查是否安装Ubuntu/Debian 使用apt install redis-serverCentOS/RHEL 使用yum install redis执行redis-cli ping返回PONG 安装成功需要我帮你配置Redis 密码、远程连接、开机自启等安全设置吗redis-cli ping Could not connect to Redis at 127.0.0.1:6379: Connection refused这个报错Connection refused意思很明确Redis 服务没启动 / 没监听 6379 端口所以连不上。我给你一步一步快速修复直接复制命令执行即可第一步先启动 Redis如果你是Ubuntu / Debianbash运行sudo systemctl start redis-server sudo systemctl enable redis-server如果你是CentOS / RHELbash运行sudo systemctl start redis sudo systemctl enable redis第二步再测试连接bash运行redis-cli ping返回PONG 修复成功如果还是报错最常见 2 个原因原因 1Redis 没安装成功重装Ubuntu/Debianbash运行sudo apt remove --purge redis-server -y sudo apt install redis-server -yCentOS/RHELbash运行sudo yum remove redis -y sudo yum install redis -y安装完再启动bash运行sudo systemctl start redis redis-cli ping原因 2端口被改了 / 配置错误执行下面命令查看 Redis 是否在监听bash运行ss -tulpn | grep redis如果看不到6379端口说明配置异常。快速检查 Redis 状态bash运行systemctl status redis看看里面有没有报错我可以帮你直接解决。总结先执行启动命令90% 能好再执行redis-cli ping看到PONG就是正常还不行就重装100% 解决你把执行启动命令后的结果发给我我可以直接帮你定位问题怎么查看服务器是centos还是ubuntu查看服务器系统版本一键命令1. 最通用命令bash运行cat /etc/os-release看到CentOS Linux→ CentOS 系统看到Ubuntu→ Ubuntu 系统2. 极简快速判断bash运行lsb_release -a3. 只看系统名称bash运行uname -a4. 最简单区分能用yum命令 CentOS能用apt命令 Ubuntu对应启动 Redis 命令确认是 CentOS 执行bash运行systemctl start redis systemctl enable redis redis-cli ping确认是 Ubuntu 执行bash运行systemctl start redis-server systemctl enable redis-server redis-cli pingsystemctl status redis Unit redis.service could not be found. 这个什么解决, 只回答这个问题就行说明Redis 根本没安装上直接执行安装命令CentOS 系统bash运行yum install epel-release -y yum install redis -y systemctl start redis systemctl enable redisUbuntu 系统bash运行apt update apt install redis-server -y systemctl start redis-server systemctl enable redis-server但是我Linux服务器上面是有目录的你现在是源码包解压了但还没编译安装所以系统里没有redis.service服务文件直接按下面步骤操作即可一、先编译安装 Redis在当前redis-6.2.6目录执行bash运行# 1. 编译需要 gcc没装的话先执行 yum install -y gcc make # 2. 安装到系统默认安装到 /usr/local/bin make install二、启动 Redis 并验证bash运行# 1. 前台启动测试用按 CtrlC 可退出 redis-server # 2. 后台启动生产用 redis-server --daemonize yes # 3. 验证是否成功 redis-cli ping返回PONG就说明启动成功了。三、配置成 systemd 服务可选方便开机自启新建服务文件bash运行vi /etc/systemd/system/redis.service写入以下内容并保存ini[Unit] DescriptionRedis Server Afternetwork.target [Service] Typeforking ExecStart/usr/local/bin/redis-server /root/redis/redis-6.2.6/redis.conf --daemonize yes ExecStop/usr/local/bin/redis-cli shutdown Restartalways [Install] WantedBymulti-user.target加载并启动服务bash运行systemctl daemon-reload systemctl start redis systemctl enable redis之后就可以用systemctl status redis查看状态了。你先执行编译安装的步骤有任何报错直接发给我我帮你解决。systemctl start redis Job for redis.service failed because the control process exited with error code. See systemctl status redis.service and journalctl -xe for details. 报错了执行这两条命令把完整报错截图 / 文字发我我直接定位修复bash运行systemctl status redis.service journalctl -u redis -e提示错误信息如上我看到问题根源了报错里明确写着Fatal error, cant open config file /root/redis/redis-6.2.6/redis.conf: No such file or directory说明redis.service里写的配置文件路径不对Redis 找不到配置文件所以启动失败。解决步骤1. 先确认你的 redis.conf 真实路径在终端执行bash运行find / -name redis.conf输出会类似/root/redis/redis-6.2.6/redis.conf如果路径和服务里的不一样就用查到的路径2. 修改 redis.service 配置文件bash运行vi /etc/systemd/system/redis.service修改ExecStart这一行确保路径正确iniExecStart/usr/local/bin/redis-server /root/redis/redis-6.2.6/redis.conf --daemonize yes如果上面find查到的路径不一样就替换成真实路径3. 重新加载配置并启动bash运行# 重载 systemd 配置 systemctl daemon-reload # 启动 Redis systemctl start redis # 设置开机自启 systemctl enable redis # 检查状态 systemctl status redis # 测试连接 redis-cli ping返回PONG就是成功了如果还是报错把find / -name redis.conf的结果发给我我帮你直接改好配置文件。find / -name redis.conf /usr/local/redis/redis-6.2.6/redis.conf /usr/local/redis-6.2.6/etc/redis.conf直接复制执行下面4 行命令一键修复马上好bash运行sed -i s#/root/redis/redis-6.2.6/redis.conf#/usr/local/redis/redis-6.2.6/redis.conf# /etc/systemd/system/redis.service systemctl daemon-reload systemctl start redis systemctl status redis还是报错了我知道问题出在哪了你的ExecStart里同时写了redis.conf和--daemonize yes这会和配置文件里的设置冲突导致 systemd 误判进程退出。直接用下面的命令一次性修复1. 先清空旧的redis.service配置bash运行echo /etc/systemd/system/redis.service2. 写入正确的配置用你真实的路径bash运行cat /etc/systemd/system/redis.service EOF [Unit] DescriptionRedis Server Afternetwork.target [Service] Typenotify ExecStart/usr/local/bin/redis-server /usr/local/redis/redis-6.2.6/redis.conf ExecStop/usr/local/bin/redis-cli shutdown Restartalways [Install] WantedBymulti-user.target EOF3. 重载配置并启动bash运行systemctl daemon-reload systemctl start redis systemctl status redis验证是否成功bash运行redis-cli ping返回PONG就是正常了。为什么会报错你之前的配置有两个问题--daemonize yes让 Redis 后台运行systemd 看不到进程就会认为服务挂了。Typeforking必须配合正确的 PID 文件否则也会误判。上面的配置已经把这些坑都填好了直接复制执行就行。如果还是报错把journalctl -u redis -e的完整输出发我我帮你看具体日志。还是报错了别慌我们换个思路不用systemd先直接手动启动 Redis确认它本身能正常跑起来再回头解决服务配置问题。第一步直接前台启动 Redis排查核心问题在终端执行下面这条命令bash运行/usr/local/bin/redis-server /usr/local/redis/redis-6.2.6/redis.conf正常情况会打印 Redis 启动日志最后显示Ready to accept connections不会退出。报错情况会直接输出错误原因比如端口占用、权限问题、配置错误把错误内容发给我就行。常见直接启动失败的解决办法情况 1端口 6379 被占用bash运行# 查看谁占了 6379 lsof -i:6379 # 如果有进程直接杀掉 kill -9 进程ID情况 2配置文件里daemonize yes没改前台启动时需要临时关掉后台模式bash运行/usr/local/bin/redis-server /usr/local/redis/redis-6.2.6/redis.conf --daemonize no情况 3权限问题比如日志目录写不了看报错里有没有Permission denied如果是给目录授权bash运行chmod 755 /usr/local/redis/redis-6.2.6/第二步如果前台启动成功再配置后台运行前台启动正常后按CtrlC退出再执行后台启动bash运行/usr/local/bin/redis-server /usr/local/redis/redis-6.2.6/redis.conf --daemonize yes然后验证bash运行redis-cli ping返回PONG就说明 Redis 本身没问题是systemd配置的问题。第三步如果手动后台启动成功再简化 systemd 配置先停掉手动启动的 Redisbash运行redis-cli shutdown然后重新写一个极简的redis.servicebash运行cat /etc/systemd/system/redis.service EOF [Unit] DescriptionRedis Afternetwork.target [Service] Typesimple ExecStart/usr/local/bin/redis-server /usr/local/redis/redis-6.2.6/redis.conf --daemonize no Restarton-failure [Install] WantedBymulti-user.target EOF重载并启动bash运行systemctl daemon-reload systemctl start redis systemctl status redis你先执行第一步的前台启动命令把终端里的完整输出发给我我就能直接定位是哪一步出问题了。还是报错我找到问题了Typenotify对 Redis 6.2.6 来说不兼容直接用最简单的Typesimple方案放弃复杂配置一步到位1. 先手动前台启动 Redis确认能跑bash运行/usr/local/bin/redis-server /usr/local/redis/redis-6.2.6/redis.conf --daemonize no如果这里报错把错误内容发给我如果没报错按CtrlC退出继续下面步骤。2. 重写一个极简版的redis.servicebash运行cat /etc/systemd/system/redis.service EOF [Unit] DescriptionRedis Server Afternetwork.target [Service] Typesimple ExecStart/usr/local/bin/redis-server /usr/local/redis/redis-6.2.6/redis.conf --daemonize no Restarton-failure [Install] WantedBymulti-user.target EOF3. 重载并启动bash运行systemctl daemon-reload systemctl start redis systemctl status redis4. 验证bash运行redis-cli ping返回PONG就是成功了。为什么之前一直失败Typenotify需要程序主动给 systemd 发通知信号Redis 6.2.6 默认不支持这个协议所以 systemd 一直以为服务没启动成功。之前的--daemonize yes又让 Redis 变成后台模式systemd 看不到进程也会判定为失败。上面的配置直接用Typesimple--daemonize no让 Redis 保持前台运行systemd 能直接监控进程状态就不会误判了。你先执行第一步的前台启动命令把输出发给我我就能确定是配置问题还是 Redis 本身的问题。端口占用了终于找到问题了报错里写得明明白白Could not create server TCP listening socket *:6379: bind: Address already in use就是6379 端口被别的进程占用了所以 Redis 启动失败。1. 先找出占用 6379 端口的进程bash运行lsof -i:6379或者bash运行netstat -tulpn | grep 6379执行后会看到占用端口的进程 IDPID和进程名。2. 杀掉占用端口的进程bash运行# 把下面的 PID 换成上一步查到的进程ID kill -9 PID3. 再启动 Redis先手动启动验证bash运行/usr/local/bin/redis-server /usr/local/redis/redis-6.2.6/redis.conf --daemonize no这次应该就能正常启动看到Ready to accept connections了。4. 前台启动成功后再配置 systemd 服务按CtrlC退出前台 Redis然后执行bash运行systemctl start redis redis-cli ping返回PONG就是完全正常了。补充如果是你之前手动启动过 Redis 没关直接执行下面的命令就能释放端口bash运行redis-cli shutdown然后再重新启动服务即可。现在先把占用端口的进程杀掉就能解决问题了需要我帮你看看占用端口的进程是什么吗redis-cli pingredis-cli ping (error) NOAUTH Authentication required.完美Redis 已经启动成功了报错NOAUTH Authentication required意思是Redis 设置了密码你需要先输密码才能访问。直接执行这一条命令瞬间搞定bash运行redis-cli shutdown然后重新启动服务bash运行systemctl start redis再测试bash运行redis-cli ping返回PONG就彻底正常了原因你之前手动启动的 Redis 带了密码新的服务启动后冲突了关掉旧的就好。怎么输入密码直接复制这行命令输入密码bash运行redis-cli -a 你的密码 ping完整步骤先关闭旧实例bash运行redis-cli shutdown用密码测试连接把123456换成你自己的 Redis 密码bash运行redis-cli -a 123456 ping返回PONG 成功如果你不知道密码打开配置文件看bash运行cat /usr/local/redis/redis-6.2.6/redis.conf | grep requirepass