zoukankan      html  css  js  c++  java
  • Redis 学习之简介及安装

    该文使用centos6.5 64位 redis-3.2.8

    NSQL:Not Only SQL 以key-value 形式存储和传统的关系型数据库不一样,不一定遵循传统数据库的一些基本要求,比如说遵循SQL标准、ACID属性、表结构等,这类数据库主要具有以下特点:非关系型的、分布式的、开源的、水平可扩展的。

    名称解释:

    1、key-value :js中的对象,json数据格式、java中的map,java中的javabean

    2、SQL标准:insert、delete、update、select 等标准的SQL语句

    3、ACID属性:事务 ,redis中也存在事务,但很简单。

    4、表结构:通过已经建立的表向表中添加数据,redis可以在表不存在的情况下直接添加数据

    NSQL 特点:

    1、处理超大量数据能力强

    2、可以运行在便宜的PC服务器集群上

    4、对数据的高并发读写能力强(mysql在上万数据的写入对磁盘IO消耗很大)

    5、对海量数据的高效存储和访问。

    6、对数据的高可靠扩展性和高可用性

    一、redis简介

    Redis是一个开源的,先进的key-value存储。它通常被称为数据结构服务器,因为键可以包含字符串、哈希、链表、集合和有序集合。

    支持的数据类型:string(字符串)、list(集合)、set(集合)、zset(有序集合)。

    支持的操作:这些数据类型支持push/pop、add/remove 等丰富的数据操作。支持不同方式的排序。

    缓存:redis为了保证效率数据都是缓存在内存中的,为了防止系统突然崩溃从而导致内存中的数据丢失,它也可以周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件。

    redis用户:新浪微博是redis最大的用户,200多台物理机。

    redis在新浪微博中的使用场景:

    1、应用程序直接访问redis数据库

      该方式与传统应用程序访问mysql类似,但该方式不安全。

    2、应用程序直接访问Redis,只有当Redis访问失败后才访问Mysql

    a、应用程序先访问redis server,redis与mysql集群进行数据同步

    b、如果redis集群宕机后应用程序直接访问mysql集群

    3、redis使用场景:

    a、区最新N个数据的操作

    b、排行榜应用、取TOP N操作

    c、需要精确设定过期时间的应用

    d、计数器应用

    e、uniq操作、获取某段时间所有数据排重值

    f、实时系统、反垃圾系统

    g、Pub/Sub构建实时消息系统

    h、构建队列系统

    i、redis缓存

    三、redis的安装

    1、下载 https://redis.io/download  稳定版(stable)

    a、解压:[root@localhost tools]# tar  -zxvf redis-3.2.8.tar.gz 

    b、编译:[root@localhost redis-3.2.8]# make

    如果出现错误 gcc:命令未找到   则安装gcc   yum install -y gcc g++ gcc-c++ make

    如果出现 tcl 问题 则安装tcl  yum install tcl 

    c、安装 [root@localhost src]# make install

    在src下将出现redis的相关命令

    -rwxr-xr-x. 1 root root 5707211 2月 17 22:33 redis-cli    进入redis客户端命令

    -rwxr-xr-x. 1 root root 7827978 2月  17 22:33 redis-server 启动redis服务命令

    2、配置redis

    (1)[root@localhost src]# mkdir -p /usr/local/redis/bin   创建文件夹用户存储redis命令
    (2)[root@localhost src]# mkdir -p /usr/local/redis/etc   创建文件夹用户存储redis配置文件

    (3)将/tools/redis-3.2.8下的  redis.conf移动到/usr/local/redis/etc下 

        [root@localhost redis-3.2.8]# mv ./redis.conf /usr/local/redis/etc

    (4)将/tools/redis-3.2.8/src下的  mkreleasehdr.sh、redis-benchmark、redis-check-aof、redis-check-rdb、redis-cli、redis-server移动到/usr/local/redis/bin下 

    (5)启动redis服务:进入redis   bin目录下  /usr/local/redis/bin

       [root@localhost bin]# ./redis-server

       如果出现   -bash: ./redis-server: 权限不够

          查看权限:[root@localhost bin]# ls -l | grep -i redis-server   

       赋予xr权限 [root@localhost bin]# chmod 755 redis-server

    [root@localhost bin]# ls -l | grep -i redis-server
    -rw-rw-r--. 1 root root 7827978 2月  17 22:52 redis-server
    [root@localhost bin]# chmod 755 redis-server
    [root@localhost bin]# ls -l | grep -i redis-server
    -rwxr-xr-x. 1 root root 7827978 2月  17 22:52 redis-server

     提示信息

    [root@localhost bin]# ./redis-server
    5322:C 17 Feb 23:18:39.086 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
    5322:M 17 Feb 23:18:39.087 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                    _._                                                  
               _.-``__ ''-._                                             
          _.-``    `.  `_.  ''-._           Redis 3.2.8 (00000000/0) 64 bit
      .-`` .-```.  ```/    _.,_ ''-._                                   
     (    '      ,       .-`  | `,    )     Running in standalone mode
     |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
     |    `-._   `._    /     _.-'    |     PID: 5322
      `-._    `-._  `-./  _.-'    _.-'                                   
     |`-._`-._    `-.__.-'    _.-'_.-'|                                  
     |    `-._`-._        _.-'_.-'    |           http://redis.io        
      `-._    `-._`-.__.-'_.-'    _.-'                                   
     |`-._`-._    `-.__.-'    _.-'_.-'|                                  
     |    `-._`-._        _.-'_.-'    |                                  
      `-._    `-._`-.__.-'_.-'    _.-'                                   
          `-._    `-.__.-'    _.-'                                       
              `-._        _.-'                                           
                  `-.__.-'                                               
    
    5322:M 17 Feb 23:18:39.113 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
    5322:M 17 Feb 23:18:39.113 # Server started, Redis version 3.2.8
    5322:M 17 Feb 23:18:39.114 # 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.
    5322:M 17 Feb 23:18:39.114 # 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.
    5322:M 17 Feb 23:18:39.114 * The server is now ready to accept connections on port 6379

    安装成功端口 6379 

    使用指定的配置文件启动redis服务器

    [root@localhost bin]# ./redis-server /usr/local/redis/etc/redis.conf

    四、redis后台运行

    ################################# GENERAL #####################################

    # By default Redis does not run as a daemon. Use 'yes' if you need it.
    # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
    daemonize no 

    daemonize no:默认启动方式该方式占用一个窗口,一旦ctrl+c redis服务器就关闭

    daemonize yes:将redis的启动方式改为后台运行

    进入:redis 客户端 

    [root@localhost bin]# pwd
    /usr/local/redis/bin
    [root@localhost bin]# ./redis-cli
    127.0.0.1:6379>

    关闭redis服务器:

    [root@localhost bin]# pkill redis-serve (通过进程的方式)

    [root@localhost bin]# ./redis-cli shutdown(通过redis命令)

  • 相关阅读:
    hadoop-2.7.3安装kafka_2.11-2.1.0
    HBase数据快速导入之ImportTsv&Bulkload
    hbase shell 基本操作
    SQLplus命令中删除键和翻页键不能用的问题
    SQL*Loader 的使用sqlldr和sqluldr2方法详解
    python连接oracle导出数据文件
    python零碎知识点一
    用Python输出一个Fibonacci数列
    问题总结——window平台下gruntower安装后无法运行的问题
    JavaScript学习笔记——浅拷贝、深拷贝
  • 原文地址:https://www.cnblogs.com/jalja/p/6409680.html
Copyright © 2011-2022 走看看