基于Linux环境安装Redis 6.2.9

基于Linux环境安装Redis 6.2.9

安装Redis

下载

找到对应的版本

https://download.redis.io/releases/

安装依赖

yum install -y gcc tcl jemalloc-devel

解压

tar -zxvf redis-6.2.9.tar.gz -C /opt

运行编译命令

cd redis-6.2.9
make && make install

耐心等待一段时间,没有明显的出错的话应该就安装成功了,其默认安装路径是/usr/local/bin/目录,所以我们需要到该目录检查一下

[root@localhost redis-6.2.9]# cd /usr/local/bin/
[root@localhost bin]# ll
total 18928
-rwxr-xr-x. 1 root root 4830064 Jun  7 23:04 redis-benchmark
lrwxrwxrwx. 1 root root      12 Jun  7 23:04 redis-check-aof -> redis-server
lrwxrwxrwx. 1 root root      12 Jun  7 23:04 redis-check-rdb -> redis-server
-rwxr-xr-x. 1 root root 5004176 Jun  7 23:04 redis-cli
lrwxrwxrwx. 1 root root      12 Jun  7 23:04 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 9542008 Jun  7 23:04 redis-server

该目录已经默认配置到环境变量,因此可以在任意目录下运行这些命令,其中:

  • redis-cli: 是redis提供的命令行客户端
  • redis-server: 是redis的服务端启动脚本
  • redis-sentinel: 是redis的哨兵启动脚本

启动Redis

启动Redis有很多种方式,在这里介绍以下三种:

  • 默认启动
  • 指定配置启动
  • 开机自启

默认启动:

安装完成后,可在任意目录下运行redis-server命令启动Redis:

redis-server

出现redis的日志界面,运行成功:

[root@localhost bin]# redis-server
26071:C 07 Jun 2024 23:08:23.763 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
26071:C 07 Jun 2024 23:08:23.763 # Redis version=6.2.9, bits=64, commit=00000000, modified=0, pid=26071, just started
26071:C 07 Jun 2024 23:08:23.763 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
26071:M 07 Jun 2024 23:08:23.767 * Increased maximum number of open files to 10032 (it was originally set to 1024).
26071:M 07 Jun 2024 23:08:23.767 * monotonic clock: POSIX clock_gettime
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 6.2.9 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                  
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 26071
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           https://redis.io       
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

26071:M 07 Jun 2024 23:08:23.769 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
26071:M 07 Jun 2024 23:08:23.769 # Server initialized
26071:M 07 Jun 2024 23:08:23.769 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
26071:M 07 Jun 2024 23:08:23.769 * Ready to accept connections

这种方式为前台启动,会阻塞整个会话窗口,此时需要打开另一个窗口进行连接,窗口关闭或者按下【ctrl+c】则Redis停止。此种方式不推荐使用。

指定配置文件启动

若要让Redis以后台方式启动,则需要修改redis的配置文件,复制文件至redis-server命令下

cd /usr/local/bin
cp /opt/redis-6.2.9/redis.conf ./
修改配置文件
vi redis.conf
  • 监听的地址,默认是127.0.0.1,会导致只能在本地访问,改为0.0.0.0表示任何ip都可以访问,生产环境不要设置成0.0.0.0
# 原本是bind 127.0.0.1 -::1, 需要注释掉,加上bind 0.0.0.0
bind 0.0.0.0  
  • 守护进程,修改为yes后可后台进行
daemonize yes
  • 密码,设置后访问redis必须输入密码
requirepass 123321(密码可以随意)
Redis的其他常用配置
# 设置redis的日志文件,有错误会往里面放,没有设置路径,所以会放在打开redis服务的文件夹下
logfile "redis.log" 

# 监听的端口
port 6379

# 工作目录,默认是当前目录,也就是运行redis-server时的命令,日志、持久化等文件会保存在这个目录
dir .

# 数据库数量,设置为1,代表只使用1个库,默认有16个库,编号0~15
databases 1

# 设置redis能够使用的最大内存
maxmemory 512mb

修改保存后,启动Redis,加上配置文件的全路径,这里若是在redis安装目录下,可省去全路径。

redis-server redis.config

可查看redis 的进程。

ps -ef | grep redis

开机自启:

1、将redis加入开机自启服务,在/etc/systemd/system创建redis.service文件并加入内容

内容如下

[Unit]
Description=redis-server
After=network.target
 
[Service]
Type=forking
ExecStart=/usr/local/bin/redis-server /usr/local/bin/redis.conf
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

2、重新加载配置

systemctl daemon-reload

3、启动Redis

systemctl start redis

4、查看Redis状态

systemctl status redis

5、设置开机自启

systemctl enable redis
  • 20
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 是的,Redis 6.2.9 在官方发布的版本中是有适用于 Windows 操作系统的版本的。在过去,Redis 的 Windows 版本相对不稳定和不完善,但自 Redis 3.2 版本开始,官方就开始积极改进 Windows 版本,并不断地提供修复和更新。Redis 的 Windows 版本可通过官方网站下载,下载页面会提供最新的可用版本和相关的安装说明。同时,Redis 在 Windows 上的使用和配置与 Linux 和其他操作系统上基本相同,在 Windows 中使用 Redis 时需要注意一些特定的配置和使用方法,例如路径设置和配置文件的编写。总体来说,Redis 6.2.9 在 Windows 上是可用的,并且可以正常使用其提供的功能和特性,但用户仍然需要关注官方发布的最新版本和文档以获得最佳的使用体验。 ### 回答2: 是的,Redis 6.2.9 有适用于 Windows 的版本。Redis 是一款开源的高性能键值存储系统,最初是为 Linux 环境设计的,但现在也提供了适用于 Windows 的版本。 在过去,Redis 在 Windows 下的支持并不完善,但随着时间的推移,Redis 团队对 Windows 支持进行了改进,并逐渐提供了更稳定和可靠的 Windows 版本。Redis 官方网站上可以下载到适用于 Windows 的 Redis 安装包,用户可以根据自己的需求选择 32 位或者 64 位版本,以及不同的安装模式。 安装 Redis 的 Windows 版本与在 Linux 下的安装方式略有不同,用户可以按照官方文档提供的指导进行安装和配置。在安装完成后,用户可以像在 Linux 环境下一样使用 Redis,运行 Redis 服务器、存储和获取数据等操作。 需要注意的是,由于 Windows 和 Linux 之间的操作系统差异,Windows 版本的 Redis 在性能方面可能会略有不同。同时,Windows 版本的 Redis 还在不断改进和迭代,用户在使用时应及时关注官方发布的更新和维护信息,以获取最佳的性能和稳定性。 总之,Redis 6.2.9 是存在适用于 Windows 操作系统的版本的,用户可以根据自己的需求选择合适的版本,并按照官方文档进行安装和配置。 ### 回答3: 是的,Redis 6.2.9 有针对 Windows 操作系统的版本。Redis 官方团队提供了官方的 Windows 版本,以便 Windows 用户能够轻松地在其平台上使用 Redis。官方版本通过解决 Windows 操作系统与 Redis 的特定兼容性问题,确保运行环境稳定和可靠。用户可以从 Redis 官方网站上下载并安装适用于 Windows 的 Redis 6.2.9 版本。有了这个版本,Windows 用户就可以享受到 Redis 提供的高性能、高可用性和高可扩展性的优势。同时,Redis 6.2.9 版本包含了各种新功能、改进和bug修复,确保用户获得更好的性能和功能体验。因此,如果您是 Windows 用户,您可以从官方网站上获得适用于 Windows 的 Redis 6.2.9 版本,并开始在您的 Windows 环境中使用 Redis

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值