redis简介及部署

简介

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

  • redis的出现时间并不长,是NoSQL中的一种,基于键-值型的存储,与memcache类似,但是memcache中只是内存的缓存,而redis不仅是内存中的缓存,还提供持久存储。

  • 官网:https://redis.io/commands

redis 的优势

1、性能极高 -- SQL语句的读写量: 读取速度 11W/s,写的速度8.1W/s

2、数据类型

3、原子性,所有的语句是一个整体,要么执行成功,要么失败

redis与mamcache不同之处:

数据结构:Memcache仅能支持简单的K-V形式,Redis支持的数据更多
多线程:Memcache支持多线程,Redis支持单线程,CPU利用Memcache利用率更高
持久化:Redis支持持久化,Memcache不支持持久化
分布式:Redis做主从结构,而Memcache服务器需要通过hash一致化来支撑主从结构
虚拟内存:Redis当物理内存使用完时,会将一些很久没有用的内存交换到磁盘,而Memcache采取的LUR策略,将一部分数据刷新掉

与其他key-value缓存产品的区别

在这里插入图片描述

Redis各种数据类型应用和实现方式

    String:数据结构是简单的K-V类型,v可以是数据,也可以是数字(常用操作:set,get,decr,incr,mget)
    set:sadd,spop,smembers,sunion,sinter
    list :lpush/rpush,lpop/rpop,lpoprpush,lrange
    hash:hset,hgetall,hget
    zset:zadd,zrank,zrange,zrem,zcard

部署

  • 部署环境
操作系统 ip地址
CentOS Linux release 7.5.1804 192.168.10.11 /24
  • 下载 redis 安装包
[root@localhost ~]# wget  http://download.redis.io/releases/redis-2.8.17.tar.gz

  • 解压
[root@localhost ~]# tar zvxf redis-2.8.17.tar.gz

  • 安装好编译环境
[root@localhost ~]# yum -y install gcc c++ 

  • 编译
[root@localhost ~]# cd redis-2.8.17
[root@localhost redis-2.8.17]# ls
00-RELEASENOTES  deps       README            sentinel.conf
BUGS             INSTALL    redis.conf        src
CONTRIBUTING     Makefile   runtest           tests
COPYING          MANIFESTO  runtest-sentinel  utils
[root@localhost redis-2.8.17]# make

这里因为有makefile,所以直接make,若果make 出现一下错误,则解决办法:
[root@localhost redis-2.8.17]# make   MALLOC=libc
cd src && make all
make[1]: Entering directory `/root/redis-2.8.17/src'
    CC adlist.o
In file included from adlist.c:34:0:
zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory
 #include <jemalloc/jemalloc.h>
                               ^
compilation terminated.
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/root/redis-2.8.17/src'
make: *** [all] Error 2
[root@localhost redis-2.8.17]# ls

请在make后面加上MALLOC=libc,出现下一界面就ok

在这里插入图片描述

  • 测试下编译环境
[root@localhost ~]# cd redis-2.8.17/src/
[root@localhost src]# make test
You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] Error 1
[root@localhost src]# 

解决方法:
[root@localhost src]# yum -y install tcl
接着等着编译……

\o/ All tests passed without errors!

Cleanup: may take some time... OK
这里似乎没有出错,but……=如果已近安装mysql,报错了,考虑修改一下内容:

[root@localhost redis-2.8.17]# ls
00-RELEASENOTES  COPYING  Makefile   redis.conf        sentinel.conf  utils
BUGS             deps     MANIFESTO  runtest           src
CONTRIBUTING     INSTALL  README     runtest-sentinel  tests

[root@localhost redis-2.8.17]# vi tests/integration/replication-2.tcl 
搜索after 将原有的1000 改大一点,比如:10000 即可
after 1000---------->10000
  • 启动
[root@localhost src]# ./redis-server 
[14813] 30 Oct 23:02:17.786 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
[14813] 30 Oct 23:02:17.787 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 2.8.17 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in stand alone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 14813
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

[14813] 30 Oct 23:02:17.788 # Server started, Redis version 2.8.17
[14813] 30 Oct 23:02:17.789 # 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.
[14813] 30 Oct 23:02:17.789 * The server is now ready to accept connections on port 6379


ok!步骤到这里,安装基本就完成了

发布了60 篇原创文章 · 获赞 3 · 访问量 2083

猜你喜欢

转载自blog.csdn.net/weixin_42313749/article/details/102828097