redis 数据库


安装步骤

1 下载源码包

下载地址:https://www.redis.net.cn/

2 将下载的源码包上传到Linux

[root@centos8 yuanmabao]# ll
-rw-r--r--   1 root  root    1966337 May  8 13:27 redis-5.0.4.tar.gz

3 将上传的源码包解压到指定的目录,我是解压到/usr/src

[root@centos8 yuanmabao]# tar zxf redis-5.0.4.tar.gz -C /usr/src

4 进入到解压目录,执行make

[root@centos8 yuanmabao]# cd /usr/src/redis-5.0.4/
[root@centos8 redis-5.0.4]# ll
total 252
-rw-rw-r--  1 root root 99445 Mar 19  2019 00-RELEASENOTES
-rw-rw-r--  1 root root    53 Mar 19  2019 BUGS
-rw-rw-r--  1 root root  1894 Mar 19  2019 CONTRIBUTING
-rw-rw-r--  1 root root  1487 Mar 19  2019 COPYING
drwxrwxr-x  6 root root   124 Mar 19  2019 deps
-rw-rw-r--  1 root root    11 Mar 19  2019 INSTALL
-rw-rw-r--  1 root root   151 Mar 19  2019 Makefile
-rw-rw-r--  1 root root  4223 Mar 19  2019 MANIFESTO
-rw-rw-r--  1 root root 20555 Mar 19  2019 README.md
-rw-rw-r--  1 root root 62155 Mar 19  2019 redis.conf
-rwxrwxr-x  1 root root   275 Mar 19  2019 runtest
-rwxrwxr-x  1 root root   280 Mar 19  2019 runtest-cluster
-rwxrwxr-x  1 root root   281 Mar 19  2019 runtest-sentinel
-rw-rw-r--  1 root root  9710 Mar 19  2019 sentinel.conf
drwxrwxr-x  3 root root  4096 Mar 19  2019 src
drwxrwxr-x 10 root root   167 Mar 19  2019 tests
drwxrwxr-x  8 root root  4096 Mar 19  2019 utils

[root@centos8 redis-5.0.4]# make -j 4
[root@centos8 redis-5.0.4]# ls
00-RELEASENOTES  COPYING  Makefile   redis.conf       runtest-sentinel  tests
BUGS             deps     MANIFESTO  runtest          sentinel.conf     utils
CONTRIBUTING     INSTALL  README.md  runtest-cluster  src
[root@centos8 redis-5.0.4]# cd src
[root@centos8 src]# make install
  INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install

如此,redis安装成功

安装目录说明

[root@centos8 local]# ls /usr/local/bin
redis-benchmark  redis-check-rdb  redis-sentinel
redis-check-aof  redis-cli        redis-server
  • redis-benchmark:性能测试工具,可以在自己本子运行,看看自己本子性能如何

  • redis-check-aof:修复有问题的AOF文件,rdb和aof后面讲

  • redis-check-dump:修复有问题的dump.rdb文件

  • redis-sentinel:Redis集群使用

  • redis-server:Redis服务器启动命令

  • redis-cli:客户端,操作入口

5 进行配置

创建两个新目录

[root@centos8 local]# mkdir -p /usr/local/redis/bin		##放置可执行程序

[root@centos8 local]# mkdir -p /usr/local/redis/etc		##放置配置文件

[root@centos8 local]# mv /usr/src/redis-5.0.4/redis.conf /usr/local/redis/etc/

[root@centos8 src]# cp mkreleasehdr.sh redis-benchmark redis-check-aof redis-server redis-cli /usr/local/redis/bin
[root@centos8 src]# ls /usr/local/redis/bin
mkreleasehdr.sh  redis-benchmark  redis-check-aof  redis-cli  redis-server

6 配置环境变量

配置环境变量是为了方便执行/usr/local/redis/bin下的可执行文件,如果不配置,就只能到/usr/local/redis/bin目录下执行,不能在当前目录执行,不太方便

[root@centos8 src]# echo "PATH=$PATH:/usr/local/redis/bin" >> /etc/profile
[root@centos8 src]# . /etc/profile

7 前台启动redis

[root@centos8 ~]# redis-server
[root@centos8 ~]# redis-server 
8860:C 09 May 2022 22:39:08.659 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
8860:C 09 May 2022 22:39:08.659 # Redis version=5.0.4, bits=64, commit=00000000, modif
ied=0, pid=8860, just started8860:C 09 May 2022 22:39:08.659 # Warning: no config file specified, using the default
 config. In order to specify a config file use redis-server /path/to/redis.conf8860:M 09 May 2022 22:39:08.659 * Increased maximum number of open files to 10032 (it 
was originally set to 1024).                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 5.0.4 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 8860
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

8860:M 09 May 2022 22:39:08.660 # WARNING: The TCP backlog setting of 511 cannot be en
forced because /proc/sys/net/core/somaxconn is set to the lower value of 128.8860:M 09 May 2022 22:39:08.660 # Server initialized
8860:M 09 May 2022 22:39:08.660 # WARNING overcommit_memory is set to 0! Background sa
ve 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.8860:M 09 May 2022 22:39:08.660 # WARNING you have Transparent Huge Pages (THP) suppor
t enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.8860:M 09 May 2022 22:39:08.660 * Ready to accept connections

8 修改配置文件,启动守护进程

在配置文件中找到daemonize ,将后面的no改成yes,意思是启动守护进程,这样就可以在后台启动运行redis

启动redis,后面加上配置文件路径

[root@centos8 ~]# redis-server /usr/local/redis/etc/redis.conf 
9039:C 09 May 2022 22:52:20.793 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
9039:C 09 May 2022 22:52:20.793 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=9039, just started
9039:C 09 May 2022 22:52:20.793 # Configuration loaded
[root@centos8 ~]# netstat -anlpt |grep redis
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      9040/redis-server 1 

关闭服务

root@centos8 ~]# pkill redis-server
[root@centos8 ~]# netstat -anlpt |grep redis