无论你是正在搭建个人项目,还是维护企业级应用,一个高性能的缓存与数据库解决方案都至关重要。Redis,作为风靡全球的开源内存数据结构存储,以其闪电般的速度和灵活的数据类型,成为了提升应用性能的不二之选。
本篇教程让我们通过几个简单的步骤,分别在Windows和Linux系统上完成Redis的安装,开始吧!
01Linux 系统安装(CentOS 7)
下载解压
[root@server ~]# wget https://download.redis.io/releases/redis-5.0.5.tar.gz
[root@server ~]# tar -zvxf redis-5.0.5.tar.gz -C /usr
[root@server ~]# mv /usr/redis-5.0.5 /etc/redis
编译安装
[root@server ~]# yum install gcc(若存在则无需安装)
[root@server ~]# cd /usr/redis
[root@server /usr/redis]# make #编译 成功提示[Hint: It's a good idea to run 'make test' ;)]
[root@server /usr/redis]# make install #安装 成功提示[Hint: It's a good idea to run 'make test' ;)]
更新配置
[root@server /usr/redis]# vi redis.conf
bind 0.0.0.0(可任意IP访问)
daemonize yes(需要在后台运行-守护进程)
requirepass 123456(设置密码为123456)
配置脚本
[root@server ~]# cp /usr/redis/utils/redis_init_script /etc/rc.d/init.d/redis # 如果redis.conf配置了访问密码,需要修改停止stop命令,添加 -a password
[root@server ~]# vi /etc/rc.d/init.d/redis #拷贝redis_init_script.tpl中status / restart命令
[root@server ~]# mkdir -p /etc/redis && cp /usr/redis/redis.conf /etc/redis/6379.conf
服务注册
[root@server ~]# chkconfig --add redis #注册服务
[root@server ~]# chkconfig --level 2345 redis on #开机自启
服务管理
[root@server ~]# service redis start #启动服务
[root@server ~]# service redis stop #停止服务
[root@server ~]# service redis status #服务状态
[root@server ~]# service redis restart #服务重启
02Windows 系统安装(Win11)
Redis官方并未提供原生的Windows版本。目前最可靠、稳定、可用的Windows版本是由微软开源技术团队维护和发布的,非常适合在Windows环境下进行开发、学习和测试。该项目的最终发布版本为3.0.504,远落后于Linux上最新的稳定版,这意味着它不支持Redis后续版本的许多新特性与优化。
下载地址 https://github.com/microsoftarchive/redis > zip包
解压缩
Microsoft Windows [版本 10.0.22631.6060]
(c) Microsoft Corporation。保留所有权利。
D:Downloads>tar zxf Redis-x64-3.0.504.zip -C D:/Software/DevEnv/RedisServer/3.0.504
服务注册管理
## 注册为window服务,服务名默认为Redis
D:SoftwareDevEnvRedisServer.0.504>redis-server --service-install redis.windows-service.conf
## 服务列表删除Redis
D:SoftwareDevEnvRedisServer.0.504>redis-server --service-uninstall
[12656] 25 Oct 21:10:15.178 # Redis service successfully uninstalled.
服务管理
## 启动Redis服务
D:SoftwareDevEnvRedisServer.0.504>redis-server --service-start
[14132] 25 Oct 21:00:10.197 # Redis service successfully started.
## 停止Redis服务
D:SoftwareDevEnvRedisServer.0.504>redis-server --service-stop
[4252] 25 Oct 21:03:53.134 # Redis service successfully stopped.
环境配置是动手实践的第一步,现在你已成功在本地搭建好Redis服务,接下来真正的学习始于应用——不妨立即开始探索Redis丰富的数据结构,尝试将它作为你下一个项目的缓存层,在实践中感受其强大魅力。
上一条:Redis8.2从入门到精通
下一条:Redis集群搭建入门