Redis 环境搭建详解(Windows / Linux 安装、启动、停止、开机自启)

发布时间:2026/7/22 0:18:21

Redis 环境搭建详解(Windows / Linux 安装、启动、停止、开机自启) 一、环境准备本文覆盖 Windows 开发环境、Linux 生产环境完整搭建流程包含安装、启动、停止、重启、开机自启全套实操命令。默认 Redis 端口6379默认无密码二、Windows 环境安装与使用开发调试首选1. 安装方式免压缩版简单快捷1. 下载 Windows 版 Redis 压缩包推荐 Redis7.0 稳定版2. 解压至纯英文路径无中文、无空格3. 文件夹核心文件redis-server.exe服务端、redis-cli.exe客户端、redis.windows.conf配置文件2. 启动、停止命令前台启动临时使用关闭窗口即停止双击 redis-server.exe 即可启动默认本地 6379 端口运行后台启动安装为系统服务开机自启cmd 进入 Redis 解压目录执行redis-server --service-install redis.windows.conf启动服务redis-server --service-start停止服务redis-server --service-stop卸载服务redis-server --service-uninstall3. 客户端连接双击 redis-cli.exe 直接连接本地 Redis输入 PING返回 PONG 即启动成功三、Linux 环境安装CentOS / Ubuntu 通用生产环境推荐源码编译安装版本可控、稳定性更强适配所有 Linux 发行版。1. 安装依赖yum install -y gcc gcc-c make tcl # CentOSapt install -y gcc make tcl # Ubuntu2. 下载编译安装wget http://download.redis.io/releases/redis-7.0.15.tar.gztar -zxvf redis-7.0.15.tar.gzcd redis-7.0.15make make install3. 基础启停命令前台启动redis-server后台启动指定配置文件redis-server /etc/redis/redis.conf停止服务redis-cli shutdown强制停止kill -9 进程ID不推荐可能丢失数据四、Linux 配置开机自启生产必备1. 新建系统服务文件vim /etc/systemd/system/redis.service2. 写入配置内容[Unit]DescriptionRedis ServerAfternetwork.target[Service]TypeforkingExecStart/usr/local/bin/redis-server /etc/redis/redis.confExecStop/usr/local/bin/redis-cli shutdownRestartalways[Install]WantedBymulti-user.target3. 生效自启配置systemctl daemon-reloadsystemctl start redissystemctl enable redis # 开机自启4. 常用服务命令systemctl status redis # 查看运行状态systemctl restart redis # 重启systemctl stop redis # 停止五、安装验证redis-cli ping返回 PONG 代表环境搭建成功

相关新闻