本文中的两个配置文件可在这里找到

操作系统:Linux

Linux发行版:Centos7

安装

  1. 下载地址,点这里Redis4.0.0.tar.gz

    或者使用命令:

    wget http://download.redis.io/releases/redis-4.0.0.tar.gz

  2. 然后执行make编译源码:

    $ tar xzf redis-4.0.0.tar.gz
    $ cd redis-4.0.0
    $ make
  3. 编译完成后启动

    $ src/redis-server

  4. 测试效果:

    $ src/redis-cli ping
    PONG
    $ src/redis-cli
    redis> set foo bar
    OK
    redis> get foo
    "bar"

    make命令执行完成后,会在src目录下生成6个可执行文件,分别是redis-server、redis-cli、redis-benchmark、redis-check-aof、redis-check-dump、redis-sentinel

  • redis-server is the Redis Server itself.(Redis服务器本身)
  • redis-sentinel is the Redis Sentinel executable (monitoring and failover).(Redis集群的管理工具)
  • redis-cli is the command line interface utility to talk with Redis.(与Redis进行交互的命令行客户端)
  • redis-benchmark is used to check Redis performances.(Redis性能测试工具)
  • redis-check-aof and redis-check-dump are useful in the rare event of corrupted data files.(AOF文件修复工具和RDB文件检查工具)

可以使用如下命令,把redis-server和redis-cli拷贝到合适的位置(/usr/local/bin/):

sudo cp src/redis-server /usr/local/bin/
sudo cp src/redis-cli /usr/local/bin/

或者,使用 sudo make install可以把6个文件都拷贝过去;

这样的话,只要/usr/local/bin/在PATH环境变量里,

我们就可以直接使用redis-server和redis-cli而不需要指定全路径了。比如:

[root@localhost ~]# redis-server
12408:C 16 Jul 21:30:29.657 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
12408:C 16 Jul 21:30:29.657 # Redis version=4.0.0, bits=64, commit=00000000, mod                                                                             ified=0, pid=12408, just started
12408:C 16 Jul 21:30:29.657 # Warning: no config file specified, using the defau                                                                             lt config. In order to specify a config file use redis-server /path/to/redis.con                                                                             f
12408:M 16 Jul 21:30:29.658 * Increased maximum number of open files to 10032 (i                                                                             t was originally set to 1024).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 4.0.0 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 12408
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

12408:M 16 Jul 21:30:29.663 # WARNING: The TCP backlog setting of 511 cannot be                                                                              enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
12408:M 16 Jul 21:30:29.663 # Server initialized
12408:M 16 Jul 21:30:29.663 # WARNING overcommit_memory is set to 0! Background                                                                              save may fail under low memory condition. To fix this issue add 'vm.overcommit_m                                                                             emory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.ove                                                                             rcommit_memory=1' for this to take effect.
12408:M 16 Jul 21:30:29.664 # WARNING you have Transparent Huge Pages (THP) supp                                                                             ort enabled in your kernel. This will create latency and memory usage issues wit                                                                             h Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transpar                                                                             ent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to reta                                                                             in the setting after a reboot. Redis must be restarted after THP is disabled.
12408:M 16 Jul 21:30:29.664 * Ready to accept connections
$ redis-cli
redis 127.0.0.1:6379> ping
PONG
redis 127.0.0.1:6379> set mykey somevalue
OK
redis 127.0.0.1:6379> get mykey
"somevalue"

关闭redis服务

使用如下命令可以关闭redis服务

$ redis-cli shutdown

配置初始化脚本,以服务方式启动redis

  1. 拷贝redis-4.0.0下的utils目录下的初始化脚本到/etc/init.d目录,并重命名文件为:redis_+端口号

    sudo cp utils/redis_init_script /etc/init.d/redis_6379

    确保redis_6379文件内的REDISPORT变量是你使用的端口号

  2. 新建文件夹/etc/redis/ ,并拷贝redis-4.0.0下的 redis.conf 文件到到改目录下,使用端口号作为文件名

    sudo mkdir /etc/redis
    sudo cp redis.conf /etc/redis/6379.conf
  3. 创建用来存储redis持久化文件的目录(6379为端口号)

    sudo mkdir -p /var/redis/6379

  4. 编辑6379.conf文件,修改如下几个参数:
  • Set daemonize to yes (by default it is set to no).(设置daemonize 为yes,默认为no)
  • Set the pidfile to /var/run/redis_6379.pid (modify the port if needed).(如果端口号不是6379,则需要修改)
  • Change the port accordingly. In our example it is not needed as the default port is already 6379.(如果端口号不是6379,则需要修改)
  • Set your preferred loglevel.(可以设置日志等级,注释上有说明)
  • Set the logfile to /var/log/redis/redis_6379.log(设置日志文件路径)
  • Set the dir to /var/redis/6379 (very important step!)(设置工作目录为 /var/redis/6379)
  1. 这时候就可以使用如下两条命令(任选其一)来启动redis,并测试

    [root@localhost /]# service redis_6379 start
    Starting Redis server...
    [root@localhost /]# redis-cli
    127.0.0.1:6379> ping
    PONG
    127.0.0.1:6379>
    [root@localhost /]# /etc/init.d/redis_6379 start
    Starting Redis server...

设置开机自动启动

  1. 编辑/etc/init.d/redis_6379文件,在#!/bin/bash 之后添加如下两行。

    # chkconfig: 2345 10 90
    # description: redis_6379 service manage...

    其中2345是默认启动级别,级别有0-6共7个级别。

      等级0表示:表示关机   

      等级1表示:单用户模式   

      等级2表示:无网络连接的多用户命令行模式   

      等级3表示:有网络连接的多用户命令行模式   

      等级4表示:不可用   

      等级5表示:带图形界面的多用户模式   

      等级6表示:重新启动

    10是启动优先级,90是停止优先级,优先级范围是0-100,数字越大,优先级越低

  2. 将redis_6379放入linux启动管理体系中

    chkconfig --add redis_6379

    查看redis_6379服务在各运行级状态

    chkconfig --list redis_6379

  3. 重启服务器测试效果:

    reboot

    重启完成后,直接使用redis-cli连接redis,效果如下:

    Using username "root".
    Last login: Sun Jul 16 21:30:16 2017 from 192.168.10.1
    [root@localhost ~]# redis-cli
    127.0.0.1:6379>

配置成功,完!


参考:

Redis入门指南(第2版)(顺便推荐下这本书,作为redis入门书籍非常不错)

Redis Quick Start

Redis4.0.0 安装及配置 (Linux — Centos7)的更多相关文章

  1. Linux下Redis4.0.12安装、配置、优化

    一.安装 1.检查gcc环境 执行命令,如果Linux系统没有安装gcc编译器,会提示“Command not found” # gcc -v 安装gcc # yum -y install gcc 以 ...

  2. CentOS-7.0.中安装与配置Tomcat-7的方法

    安装说明 安装环境:CentOS-7.0.1406安装方式:源码安装 软件:apache-tomcat-7.0.29.tar.gz 下载地址:http://tomcat.apache.org/down ...

  3. Yii2.0的安装与配置教程

    版权声明:本文为博主原创文章,未经博主允许不得转载. PHP版本需求:PHP5.4.0以上,因为Yii2.0基于PHP5.4以上版本进行了完全重写. 目前有两种方法可以安装Yii2.0,一种是安装Co ...

  4. MySQL8.0.12 安装及配置、读写分离,主从复制

    一.安装 1.从网上下载MySQL8.0.12版本,下载地址:https://dev.mysql.com/downloads/mysql/ 2. 下载完成后解压 我解压的路径是:D:\Java\mys ...

  5. 学习 Hadoop3.0 一、Hadoop3.0的安装与配置

    一.JDK1.8的安装 添加ppa sudo add-apt-repository ppa:webupd8team/java sudo apt-get update 安装Oracle-java-ins ...

  6. mongodb 3.0下载安装、配置及mongodb最新特性、基本命令教程详细介绍

    mongoDB简介(本文由www.169it.com搜集整理) MongoDB是一个高性能,开源,无模式的文档型数据库,是目前在IT行业非常流行的一种非关系型数据库(NoSql).它在许多场景下可用于 ...

  7. Emgucv3.0的安装与配置

    环境:vs2015+Emgucv3.0 Emgu Cv简介: Emgu CV 是.NET平台下对OpenCV图像处理库的封装.也就是OpenCV的.NET版.它运行在.NET兼容的编程语言下调用Ope ...

  8. 【Redmine】Redmine 3.0.1 安装与配置

    Redmine安装 VM安装Linux 安装Bitnami Redmine 配置环境 1.VM安装Linux 使用虚拟机安装Linux 本文使用的是Centos(CentOS-6.3-x86_64-b ...

  9. zabbix4.0的安装与配置

    #安装zabbix监控首先的先安装LNMP环境,在这里我采用事先准备好的脚本进行安装LNMP环境 脚本内容如下: #!/bin/bash # DATE:Wed Jan # hw226234@126.c ...

  10. Solr(5.1.0) 与Tomcat 从0开始安装与配置

    1.什么是Solr? Solr是一个基于Lucene的Java搜索引擎服务器.Solr 提供了层面搜索.命中醒目显示并且支持多种输出格式(包括 XML/XSLT 和 JSON 格式).它易于安装和配置 ...

随机推荐

  1. shell的EOF用法

    将命令输出的结果给一个循环处理,常用的方式如下: [root@etch171 guosong]# ls |while read line;do echo $line;done processlist ...

  2. mysql数据库常用命令笔记

    连接数据库:mysql -h localhost -u root -p 000000 退出:exit;    \q;    quit; SET foreign_key_checks = 0; 禁用外键 ...

  3. 翻译连载 | 附录 A:Transducing(下)-《JavaScript轻量级函数式编程》 |《你不知道的JS》姊妹篇

    原文地址:Functional-Light-JS 原文作者:Kyle Simpson-<You-Dont-Know-JS>作者 关于译者:这是一个流淌着沪江血液的纯粹工程:认真,是 HTM ...

  4. Web App适配iPhoneX

    前言 Iphone每次退出新尺寸的手机都会掀起一番适配风波,这次没有下巴但有刘海的iPhoneX更是如此,网传横屏下的适配动画更是令不少人汗颜. 其实对于Native App来说,适配并不算困难(当然 ...

  5. Regasm

      程序集注册工具(Regasm.exe) 读取程序集中的元数据,并将所需的项添加到注册表中.注册表允许COM 客户程序以透明方式创建.NET Framework类.类一经注册,任何COM 客户程序都 ...

  6. [翻译]Python List Comprehensions: Explained Visually || Python列表解析式

    原文1地址: http://treyhunner.com/2015/12/python-list-comprehensions-now-in-color/ 原文2地址: http://blog.tea ...

  7. js监听浏览器离开页面操作

    序言 大家是否经常遇到在关闭网页的时候,会看到一个确定是否离开当前页面的提示框?想一些在线测试系统.信息录入系统等就经常会有这一些提示,避免用户有意或者无意中关掉了页面,导致数据丢失.这里面的实现过程 ...

  8. php命令执行脚本

    php -f jiaoben.php &  读入并解释指明的文件.

  9. 负载均衡之nginx

    什么是负载均衡负载均衡(Load Balance)是分布式系统架构设计中必须考虑的因素之一,它通常是指,将请求/数据[均匀]分摊到多个操作单元上执行,负载均衡的关键在于[均匀].在使用nginx负载均 ...

  10. webMagic解析淘宝cookie 提示Invalid cookie header

    webMagic解析淘宝cookie 提示Invalid cookie header 在使用webMagic框架做爬虫爬取淘宝极又家页面时候一直提醒cookie设置不可用如下图 淘宝的验证特别严重,c ...