Redis4.0.0 安装及配置 (Linux — Centos7)

Redis4.0.0 安装及配置 (Linux — Centos7)

96 x113773 关注

2017.07.17 15:04* 字数 991 阅读 3130评论 0喜欢 6

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

操作系统: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/):

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

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

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

image

image

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

1[root@localhost ~]# redis-server 212408:C 16 Jul 21:30:29.657 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 312408:C 16 Jul 21:30:29.657 # Redis version=4.0.0, bits=64, commit=00000000, mod ified=0, pid=12408, just started 412408: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 512408:M 16 Jul 21:30:29.658 * Increased maximum number of open files to 10032 (i t was originally set to 1024). 6 _._ 7 _.-``__ ''-._ 8 _.-`` `. `_. ''-._ Redis 4.0.0 (00000000/0) 64 bit 9 .-`` .-```. ```\/ _.,_ ''-._ 10 ( ' , .-` | `, ) Running in standalone mode 11 |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 12 | `-._ `._ / _.-' | PID: 12408 13 `-._ `-._ `-./ _.-' _.-' 14 |`-._`-._ `-.__.-' _.-'_.-'| 15 | `-._`-._ _.-'_.-' | http://redis.io 16 `-._ `-._`-.__.-'_.-' _.-' 17 |`-._`-._ `-.__.-' _.-'_.-'| 18 | `-._`-._ _.-'_.-' | 19 `-._ `-._`-.__.-'_.-' _.-' 20 `-._ `-.__.-' _.-' 21 `-._ _.-' 22 `-.__.-' 23 2412408: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. 2512408:M 16 Jul 21:30:29.663 # Server initialized 2612408: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. 2712408: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. 2812408:M 16 Jul 21:30:29.664 * Ready to accept connections 29 30 31$ redis-cli 32redis 127.0.0.1:6379> ping 33PONG 34redis 127.0.0.1:6379> set mykey somevalue 35OK 36redis 127.0.0.1:6379> get mykey 37"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(设置日志文件路径。需要在log下新建redis文件夹)
  • 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,数字越大,优先级越低

  1. 将redis_6379放入linux启动管理体系中
    chkconfig --add redis_6379
    查看redis_6379服务在各运行级状态
    chkconfig --list redis_6379

    image

    image

  2. 重启服务器测试效果:
    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

相关文章:
Spring Boot 1.5.4集成Redis
Spring Boot 使用Redis缓存

随笔

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )