CentOS7安装部署Redis,SpringBoot连接CentOS7环境中中的Redis,Redis资料分享

Redis资料文件分享:

「Redis.pdf」https://www.aliyundrive.com/s/br2GrTtyWDT 提取码: 1m0l
「Redis6.docx」https://www.aliyundrive.com/s/cBwwrSR5KfB 提取码: x18k

一、CentOS7 部署 Redis

注意Redis安装部署到时候,会出现权限不够,无法复制拷贝文件,所以在一开始的时候使用root用户登录即可。
Redis是基于C语言编写的,因此首先需要安装Redis所需要的gcc依赖

yum install -y gcc tcl

yum install gcc

1. 下载 Redis

Redis官方网站 http://redis.io
Redis中文官方网站 http://redis.cn/
redis下载

2. 拷贝下载的 Redis 到 CentOS7 指定的文件夹

新建文件夹:/usr/az/redis/ 将下载的 redis-6.2.6.tar.gz 拷贝到该文件夹
也可在终端使用命令行直接下载 Redis :

wget -P /usr/az/redis  https://download.redis.io/releases/redis-6.2.6.tar.gz

打开终端,cd 到该文件夹
打开终端

cd /usr/az/redis

3. 解压文件

cd 到 /usr/az/redis文件后,使用如下命令解压:

tar -zxvf redis-6.2.6.tar.gz

4. 进入 redis 目录

cd redis-6.2.6

5. 编译 redis

在 /usr/az/redis/redis-6.2.6 目录下 执行make命令进行编译

make

然后可以选择执行

make test

接着执行

make install

耐心等待,如果没有出错,应该就安装成功了。

5. 测试是否安装成功

默认的安装路径是: /usr/local/bin
使用 cd /usr/local/bin 跳转到该目录,包含redis-server等文件
Redis默认安装路径
执行命令 redis-server,前台启动 Redis(不推荐,但可以用做测试)
redis-server
弹出上面的界面,说明Redis安装成功。这种启动属于前台启动,会阻塞整个会话窗口,窗口关闭或者按下CTRL + C则Redis停止。不推荐使用。

6. 后台启动 (指定配置启动)

如果要让Redis以后台方式启动,则必须修改Redis配置文件,就在我们之前解压的
redis安装包下(cd /usr/az/redis/redis-6.2.6/),名字叫redis.conf:
redis.conf
拷贝一份redis.conf,复制到指定安装目录 /usr/local/bin

cp  /usr/az/redis/redis-6.2.6/redis.conf  /usr/local/bin
或
cp redis.conf redis.conf.bck

修改配置文件:
后台启动设置daemonize no改成yes
修改配置文件
然后修改redis.conf文件中的一些配置:

# 允许访问的地址,默认是127.0.0.1,会导致只能在本地访问。修改为0.0.0.0则可以在任意IP访问,生产环境不要设置为0.0.0.0
bind 0.0.0.0
# 守护进程,修改为yes后即可后台运行
daemonize yes
# 密码,设置后访问Redis必须输入密码
requirepass 123321
# 监听的端口
port 6379
# 工作目录,默认是当前目录,也就是运行redis-server时的命令,日志、持久化等文件会保存在这个目录
dir .
# 数据库数量,设置为1,代表只使用1个库,默认有16个库,编号0~15
databases 1
# 设置redis能够使用的最大内存
maxmemory 512mb
# 日志文件,默认为空,不记录日志,可以指定日志文件名
logfile "redis.log"

7. 测试后台启动

确保redis-server 与 redis-cli 在一个文件目录下:
bin目录
使用以下命令进行启动:

redis-server redis.conf

8. 利用客户端 redis-cli 访问测试

测试安装的Redsi
出现上图结果说明成功后台启动,并可以客户端redis-cli访问

9. 停止 Redis服务

# 利用redis-cli来执行 shutdown 命令,即可停止 Redis 服务,
# 因为之前配置了密码,因此需要通过 -u 来指定密码
redis-cli -u 123321 shutdown
# 若没有设置密码,则可以用下面的命令来停止 redis 服务
redis-cli shutdown

shutdown
出现上述界面说你给终止 redis 服务成功。

二、Windows10 下连接 CentOS7 环境中的 Redis

需要注意的事项

  • 确保C唔tOS7有IP
  • 确保windows能够ping通linux,linux能够ping通windows。
  • 开放CentOS7的端口6379 。
  • 关闭Redis的保护模式
  • 设置bind=0.0.0.0
  • 需要设置密码

否则会报以下错误:
DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command ‘CONFIG SET protected-mode no’ from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent.2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to ‘no’, and then restarting the server. 3) If you started the server manually just for testing, restart it with the ‘–protected-mode no’ option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

1. 确保IP存在

CentOS7 使用ifconfig命令行查看是否存在IP,如下所示:
CentOS7 ip地址为:192.168.50.132
查看CentOS7 IP

2. 确保windows和centos7能ping

windows ping centos7
centos7 ping windows
出现上述界面说明windows和centos7网络是通的。

3. 开放CentOS7的端口6379

使用以下命令开发centos7的6379的端口:

firewall-cmd --add-port=6379/tcp --permanent

4. 关闭 redis 保护模式、设置 bind 与密码

编辑redis.conf文件:

# 关闭保护模式
protected-mode no 
# 绑定IP地址,看业务开放
bind 0.0.0.0
requirepass yourpassword
# Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程,设置为no
daemonize no

按上述方式进行设计即可。

5. windows测试连接

可以使用客户端先进行测试,然后再在利用SpringBoot测试。
推荐几款可视化的工具:https://blog.csdn.net/qq_34272760/article/details/120694581
本人暂时使用这款:RedisInsight: The best Redis GUI
客户端下载

6. 使用RedisInsight测试连接

连接的本地Redis连接本地Redis
连接CentOS7环境中的Redis,首先开启CentOS7环境中的Redis
开启CentOS7的Redis服务
ip: 192.168.50.132
port: 6379
password:yourpassword
连接Redis按钮
信息填写框
Add Redis Database
连接成功


Redis包含的内容:在这里插入图片描述
Keys *

参考文献

Redis在linux上安装教程,超级详细-1

Redis在linux上安装教程,超级详细-2

使用SpringBoot 连接CentOS 7环境下的Redis

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值