青蛙学Linux—Redis

1、Redis是什么?

Redis(Remote Dictionary Server),远程字典服务,是一个使用ANSI C语言编写的、支持网络、可基于内存亦可持久化的日志型、Key-Value型No SQL内存数据库,并提供多种语言的API。

Redis与memcached类似,不过其支持数据持久化,且支持的数据类型非常丰富。Redis支持的数据类型有字符串、链表、哈希、集合和有序集合5种,支持在服务器端计算集合的并、交、补集,还支持多种排序功能。Redis的所有数据均保存于内存中,并可通过不定期的异步方式(半持久化模式)或把每次数据变化都写入Append Only File(AOF,全持久化模式)将数据写入到硬盘。

Redis官网:https://redis.io/

2、Redis的安装和启动

2.1、获取Redis

访问Redis的官网可获取Redis的源码包,通过源码包进行Redis的安装。

这里下载Redis的5.0.8版本进行安装:

[root@localhost app]# wget -c http://download.redis.io/releases/redis-5.0.8.tar.gz

2.2、安装Redis

由于源码包中自带Makefile文件,所以Redis的安装非常简单,仅需要执行make即可。解压Redis源码包后,进入源码目录,执行:

[root@localhost redis-5.0.8]# make

命令执行完成后,会在源码目录下的src目录中生成以下可执行文件:

redis-benchmark  # Redis的性能测试工具,测试在当前系统下的读写性能
redis-check-aof  # Redis AOF的数据修复工具
redis-check-rdb  # Redis RDB的文件检查工具
redis-cli        # Redis命令行工具
redis-sentinel   # Redis哨兵
redis-server     # Redis服务器启动程序

为了方便使用,我们可以将这些可执行文件复制到系统的PATH变量目录下,如/usr/bin。

2.3、启动Redis服务

运行源码目录下的src/redis-server文件即可启动Redis服务:

[root@localhost redis-5.0.8]# src/redis-server

此时将显示Redis的启动信息,默认情况Redis将在前台启动:

9688:C 01 May 2020 21:23:06.077 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
9688:C 01 May 2020 21:23:06.077 # Redis version=5.0.8, bits=64, commit=00000000, modified=0, pid=9688, just started
9688:C 01 May 2020 21:23:06.077 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
9688:M 01 May 2020 21:23:06.078 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 5.0.8 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 9688
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

9688:M 01 May 2020 21:23:06.078 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
9688:M 01 May 2020 21:23:06.078 # Server initialized
9688:M 01 May 2020 21:23:06.078 # 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.
9688:M 01 May 2020 21:23:06.078 # WARNING you have Transparent Huge Pages (THP) support 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.
9688:M 01 May 2020 21:23:06.078 * Ready to accept connections

通过ps命令可以看到Redis已经成功启动:

[root@localhost ~]# ps -ef|grep redis
root      9698  1724  0 21:29 pts/0    00:00:00 src/redis-server *:6379
root      9720  9704  0 21:30 pts/1    00:00:00 grep --color=auto redis
posted @ 2020-05-01 16:43  青蛙学Linux  阅读(192)  评论(0编辑  收藏  举报