当前位置:网站首页>Linux中安装Redis教程
Linux中安装Redis教程
2022-08-05 05:25:00 【技术的搬运工】
1.在CentOS7中新建一个文件夹,然后在这个文件夹中下载 Redis,执行下面的命令:
# 你也可以选择其他的包 如: redis-5.0.10.tar.gz 我用这个包安装成功了
wget http://download.redis.io/releases/redis-4.0.10.tar.gz
如果未找到 wget 命令,则需要先安装 wget
yum install wget
2.解压下载好的 redis-4.0.10.tar.gz,解压出来后就变成了了 redis-4.0.10 文件
tar -zxvf redis-4.0.10.tar.gz
3.然后 cd 命令进入到 redis-4.0.10文件夹中
cd redis-4.0.10
4.安装 gcc
yum install -y gcc
如果需要切换到 root 用户,使用 su 命令,然后输入密码:
su root
5.编译 redis,需要进入 src 目录下,执行该命令
make
6.编辑文件,首先利用 vi 命令打开要编辑的文件,如打开 redis.conf 文件
vi redis.conf
打开文件后,按 a 命令进入编辑模式,
编辑完成后,按 esc 退出编辑模式,
然后输入:wq ,保存并退出,注意不要忘记输入冒号:
7.配置 redis,主要修改 redis-4.0.10 目录下的 redis.conf 文件为下面内容:在Xshell中使用查找,就很快定位到
daemonize yes # 表示允许 Redis 在后台启动
# bind 127.0.0.1 # 注释掉这个,使用连接工具就能连接成功,否则他只能是本地连接(即虚拟机中的它自己)protected-mode no # 表示关闭保护模式# 这个可以不用设置,在 redis.conf 文件中也是被用 # 注释掉的requirepass [email protected] # 加了这个在进入redis客户端时,就是用 src/redis-cli -a [email protected] 命令进入# 密码可以设置为 root 或者 123456
8.配置CentOS,关闭CentOS防火墙(这一步很重要,不然你死活连不上redis)
systemctl status firewalld.service # 查看防火墙的状态
systemctl stop firewalld.service # 关闭防火墙
systemctl disable firewalld.service # 禁用防火墙
9.接下来启动Redis
这步的命令很重要,不然会显示 bash: redis-server: command not found... 没有找到 redis-server 命令
因为你用 make 命令编译解压出来的 redis-4.0.10 安装包后,会在 redis-4.0.10 的 src 目录下生成 redis-server 等命令,
而 redis.conf 文件又在 redis-4.0.10 目录中,所以请看下面的启动 redis 命令
# 意思就是使用 src 目录下的 redis-server 命令,执行 redis.conf 文件
src/redis-server redis.conf
# 最好是拷贝一份 redis.conf 到安装redis的目录下,修改错了,还有原始的(这步操作最好是在没有配置redis.conf之前操作)
cp redis.conf /usr/local/redis/bin
如果不确定,是否真的启动了 redis,可以通过下面的命令查看:
ps -ef | grep redis
如下图表示成功启动了
10.进入 redis 客户端
# 如果设置了 requirepass [email protected] , 就要使用 src/redis-cli -a [email protected] 命令进入 redis 客户端
src/redis-cli
如下图所示:
执行 ping 命令,看到 PONG ,表示 Redis 安装成功了
退出命令 quit 或 exit ,即 127.0.0.1:6379>quit 或 127.0.0.1:6379>exit
或者直接使用 ctrl + c 退出命令控制台
11.如果想关闭 Redis 实例,则在控制台执行 SHUTDOWN 命令,然后使用 exit 退出
或者是可以使用 pkill redis-server 退出 redis 服务,注意 很多命令有时需要 root 用户
pkill redis-server
同样可以使用命令 ps -ef | grep redis 查看 Redis 进程
ps -ef | grep redis
最强的关闭方法命令:
kill -9 12587 # 其中12587是进程号
12.还可以使用windows的可视化客户端,连接redis
连接工具:redis-desktop-manager-2019.4.0.exe
边栏推荐
猜你喜欢
随机推荐
LaTeX image captioning text column automatic line wrapping
numpy.random usage documentation
document.querySelector()方法
Passing parameters in multiple threads
Quick Start to Drools Rule Engine (1)
Cloud Computing Basics - Study Notes
unity 将Text批量替换为TextMeshProUGUI
Chengyun Technology was invited to attend the 2022 Alibaba Cloud Partner Conference and won the "Gathering Strength and Going Far" Award
邮件管理 过滤邮件
H5开发调试-Fiddler手机抓包
NACOS Configuration Center Settings Profile
The use of three parameters of ref, out, and Params in Unity3D
Network Troubleshooting Basics - Study Notes
What is Alibaba Cloud Express Beauty Station?
BIO, NIO, AIO practical study notes (easy to understand theory)
May I ask how to read the binlog of the two tables of hologres through flink sql, and then how to join?
Seven Ways to Center a Box Horizontally and Vertically
selenium学习
From "dual card dual standby" to "dual communication", vivo took the lead in promoting the implementation of the DSDA architecture
如何将.asd恢复为Word文档