zoukankan      html  css  js  c++  java
  • Linux下Redis的安装和部署

    Linux下Redis的安装和部署

    一、Redis介绍

    Redis是当前比较热门的NOSQL系统之一,它是一个key-value存储系统。和Memcache类似,但很大程度补偿了Memcache的不足,它支持存储的value类型相对更多,包括string、list、set、zset和hash。这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作。在此基础上,Redis支持各种不同方式的排序。 和Memcache一样,Redis数据都是缓存在计算机内存中,不同的是,Memcache只能将数据缓存到内存中,无法自动定期写入硬盘,这就表示,一断电或重启,内存清空,数据丢失。所以Memcache的应用场景适用于缓存无需持久化的数据。而Redis不同的是它会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件,实现数据的持久化。

    二、Redis的安装

    下面介绍在Linux环境下,Redis的安装与部署

    1、首先上官网下载Redis 压缩包,地址:http://redis.io/download 下载稳定版3.0.7即可。

    2、通过远程管理工具,将压缩包拷贝到Linux服务器中,执行解压操作

    [root@localhost ~]# wget http://download.redis.io/releases/redis-3.0.7.tar.gz
    --2018-08-15 14:39:52--  http://download.redis.io/releases/redis-3.0.7.tar.gz
    正在解析主机 download.redis.io (download.redis.io)... 109.74.203.151
    正在连接 download.redis.io (download.redis.io)|109.74.203.151|:80... 已连接。
    已发出 HTTP 请求,正在等待回应... 200 OK
    长度:1375200 (1.3M) [application/x-gzip]
    正在保存至: “redis-3.0.7.tar.gz”
    

    3、执行make 对Redis解压后文件进行编译

    [root@localhost ~]# tar xzf redis-3.0.7.tar.gz 
    [root@localhost ~]# cd redis-3.0.7/
    [root@localhost redis-3.0.7]# make
    ####################报错
    cd hiredis && make static
    make[3]: 进入目录“/root/redis-3.0.7/deps/hiredis”
    gcc -std=c99 -pedantic -c -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  net.c
    make[3]: gcc:命令未找到
    make[3]: *** [net.o] 错误 127
    make[3]: 离开目录“/root/redis-3.0.7/deps/hiredis”
    make[2]: *** [hiredis] 错误 2
    make[2]: 离开目录“/root/redis-3.0.7/deps”
    make[1]: [persist-settings] 错误 2 (忽略)
        CC adlist.o
    /bin/sh: cc: 未找到命令
    make[1]: *** [adlist.o] 错误 127
    make[1]: 离开目录“/root/redis-3.0.7/src”
    make: *** [all] 错误 2
    ######################
    #解决上述错误需要安装下面的插件  要等一段时间
    [root@localhost ~]# yum -y install gcc gcc-c++ libstdc++-devel
    
    

    编译完成之后,可以看到解压文件redis-3.0.7 中会有对应的src、conf等文件夹,这和windows下安装解压的文件一样,大部分安装包都会有对应的类文件、配置文件和一些命令文件。

    [root@localhost ~]# cd redis-3.0.7/
    [root@localhost redis-3.0.7]# make
    cd src && make all
    make[1]: 进入目录“/root/redis-3.0.7/src”
        CC adlist.o
    In file included from adlist.c:34:0:
    zmalloc.h:50:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录
     #include <jemalloc/jemalloc.h>
                                 ^
    编译中断。
    
    
    ####解决方案是:
    [root@localhost redis-3.0.7]# make MALLOC=libc
    
    ###成功安装如下所示:
        LINK redis-benchmark
        CC redis-check-dump.o
        LINK redis-check-dump
        CC redis-check-aof.o
        LINK redis-check-aof
    
    Hint: It's a good idea to run 'make test' ;)
    
    make[1]: 离开目录“/root/redis-3.0.7/src”
    

    4、编译成功后,进入src文件夹,执行make install进行Redis安装

    5、安装完成,界面如下

    [root@localhost src]# make install
    
    Hint: It's a good idea to run 'make test' ;)
    
        INSTALL install
        INSTALL install
        INSTALL install
        INSTALL install
        INSTALL install
    
    

    三、Redis的部署

    安装成功后,下面对Redis 进行部署

    1、首先为了方便管理,将Redis文件中的conf配置文件和常用命令移动到统一文件中

    a)创建bin和redis.conf文件

    复制代码代码如下:

    [root@localhost src]# mkdir -p /usr/local/redis/bin
    [root@localhost src]# mkdir -p /usr/local/redis/ect
    

    b)执行Linux文件移动命令:

    复制代码代码如下:

    [root@localhost redis-3.0.7]# mv /root/redis-3.0.7/redis.conf /usr/local/redis/ect/
    [root@localhost redis-3.0.7]# cd /root/redis-3.0.7/src/
    [root@localhost src]# mv mkreleasehdr.sh  redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server /usr/local/redis/bin
    

    2、执行Redis-server 命令,启动Redis 服务

    [root@localhost redis-3.0.7]# cd /usr/local/redis/bin/
    [root@localhost bin]# ./redis-server 
    21386:C 15 Aug 15:02:57.988 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
    21386:M 15 Aug 15:02:57.988 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                    _._                                                  
               _.-``__ ''-._                                             
          _.-``    `.  `_.  ''-._           Redis 3.0.7 (00000000/0) 64 bit
      .-`` .-```.  ```/    _.,_ ''-._                                   
     (    '      ,       .-`  | `,    )     Running in standalone mode
     |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
     |    `-._   `._    /     _.-'    |     PID: 21386
      `-._    `-._  `-./  _.-'    _.-'                                   
     |`-._`-._    `-.__.-'    _.-'_.-'|                                  
     |    `-._`-._        _.-'_.-'    |           http://redis.io        
      `-._    `-._`-.__.-'_.-'    _.-'                                   
     |`-._`-._    `-.__.-'    _.-'_.-'|                                  
     |    `-._`-._        _.-'_.-'    |                                  
      `-._    `-._`-.__.-'_.-'    _.-'                                   
          `-._    `-.__.-'    _.-'                                       
              `-._        _.-'                                           
                  `-.__.-'                                               
    
    21386:M 15 Aug 15:02:57.991 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
    21386:M 15 Aug 15:02:57.991 # Server started, Redis version 3.0.7
    21386:M 15 Aug 15:02:57.991 # 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.
    21386:M 15 Aug 15:02:57.991 # 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.
    21386:M 15 Aug 15:02:57.991 * The server is now ready to accept connections on port 6379
    21386:M 15 Aug 16:02:58.001 * 1 changes in 3600 seconds. Saving...
    21386:M 15 Aug 16:02:58.007 * Background saving started by pid 22459
    22459:C 15 Aug 16:02:58.015 * DB saved on disk
    22459:C 15 Aug 16:02:58.017 * RDB: 0 MB of memory used by copy-on-write
    21386:M 15 Aug 16:02:58.109 * Background saving terminated with success
    

    四、客户端redisClient

    windows下redis可视化客户端redisClient的安装及基本使用

    五、登录和密码设置

    [root@localhost ~]# redis-cli   登录redis
    127.0.0.1:6379> ping
    PONG
    127.0.0.1:6379> COMMAND KEY_NAME
    (error) ERR Unknown subcommand or wrong number of arguments.
    127.0.0.1:6379> config set requirepass test123
    OK
    127.0.0.1:6379> 
    
    [root@localhost ~]# redis-cli
    127.0.0.1:6379> auth test123
    OK
    127.0.0.1:6379> config get requirepass
    1) "requirepass"
    2) "test123"
    
  • 相关阅读:
    Unity 自制Cubemap及使用
    Exp4
    实验一 密码引擎-2-OpenEuler-OpenSSL测试
    实验一 密码引擎-3-电子钥匙功能测试
    实验一 密码引擎-1-OpenEuler-OpenSSL编译
    实验一 密码引擎-0-OpenEuler ECS构建
    商用密码企业调研(必做)
    exp3
    exp2
    exp1
  • 原文地址:https://www.cnblogs.com/zhizhao/p/9491543.html
Copyright © 2011-2022 走看看