centos7 安装redis教程

本文详细介绍了在CentOS7系统中如何下载、编译、安装Redis,并解决编译过程中遇到的依赖问题,如gcc和tcl。接着,文章演示了如何启动Redis服务,包括正常启动和后台启动,以及如何通过修改配置文件实现后台运行。最后,讲解了关闭Redis服务的方法和注意事项,如查看进程、使用kill命令结束进程。
摘要由CSDN通过智能技术生成

centos7 安装redis教程

  1. 下载 redis
wget http://download.redis.io/releases/redis-6.2.6.tar.gz
  1. 解压压缩包
tar -zxvf redis-6.2.6.tar.gz
  1. yum安装gcc依赖
    因为redis是c编写的,gcc编译c的,所以我们先安装下gcc
// 检查是否已经安装了gcc(如果提示未找到命令即表示没有安装)
gcc -v
//没有的话安装
yum install gcc
  1. 编译安装Redis
// 跳转到redis解压目录下
cd redis-6.2.6
//安装redis
make MALLOC=libc
// 将/usr/local/redis-6.2.6/src目录下的文件加到/usr/local/bin目录
cd src && make install
  1. make test存在报错,需要安装tcl
[jinjia523@localhost src]$ make test
You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] 错误 1
  1. 安装tcl
wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
tar xzvf tcl8.6.1-src.tar.gz -C /usr/local/
cd /usr/local/tcl8.6.1/unix/
./configure
make
make install
  1. 启动redis
    进入redis-6.2.6/src目录中
./redis-server

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

40206:M 24 Nov 2021 21:31:08.772 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
40206:M 24 Nov 2021 21:31:08.772 # Server initialized
40206:M 24 Nov 2021 21:31:08.772 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. 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.
40206:M 24 Nov 2021 21:31:08.772 * Ready to accept connections

如上所示:redis启动成功,但是这种启动方式需要一直打开窗口,不能进行其他操作,不太方便。
按 ctrl + c可以关闭窗口。
8. 以后台进程方式启动redis
修改redis.conf文件

vi redis.conf
daemonize no 修改为 daemonize yes
//指定redis.conf文件启动
./redis-server /home/jinjia523/redis-6.2.6/redis.conf
  1. 关闭redis
// 首先使用ps -aux | grep redis查看redis进程
[jinjia523@localhost src]$ ps -aux | grep redis
jinjia5+  40822  0.0  0.1 144040  2044 ?        Ssl  21:51   0:00 ./redis-server 127.0.0.1:6379
jinjia5+  40838  0.0  0.0 112728   972 pts/0    R+   21:51   0:00 grep --color=auto redis
//  kill redis 进程
kill 40822
  1. 修改redis.conf
vi redis.conf
//端口
port 6379
//密码
requirepass redis1314
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值