1. 下载
到redis下载页面https://redis.io/download下载对应版本的reids安装包,如:redis-${version}.tar.gz 。

2. 安装
redis的详细安装步骤在安装包中的README.md文件中有详细说明,请详细阅读。
以安装redis-4.0.1.tar.gz为例说明。

[root@centosx64]# tar xvf redis-4.0.1.tar.gz
[root@centosx64]# cd redis-4.0.
[root@centosx64 redis-4.0.]# make
cd src && make all
make[1]: Entering directory `/root/redis-4.0.1/src'
CC Makefile.dep
make[1]: Leaving directory `/root/redis-4.0.1/src'
make[1]: Entering directory `/root/redis-4.0.1/src'
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html Makefile.dep dict-benchmark
(cd ../deps && make distclean)
make[2]: Entering directory `/root/redis-4.0.1/deps'
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
(rm -f .make-*)
make[2]: Leaving directory `/root/redis-4.0.1/deps'
(rm -f .make-*)
echo STD=-std=c99 -pedantic -DREDIS_STATIC='' >> .make-settings
echo WARN=-Wall -W -Wno-missing-field-initializers >> .make-settings
echo OPT=-O2 >> .make-settings
echo MALLOC=jemalloc >> .make-settings
echo CFLAGS= >> .make-settings
echo LDFLAGS= >> .make-settings
echo REDIS_CFLAGS= >> .make-settings
echo REDIS_LDFLAGS= >> .make-settings
echo PREV_FINAL_CFLAGS=-std=c99 -pedantic -DREDIS_STATIC='' -Wall -W -Wno-missing-field-initializers -O2 -g -ggdb -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -DUSE_JEMALLOC -I../deps/jemalloc/include >> .make-settings
echo PREV_FINAL_LDFLAGS= -g -ggdb -rdynamic >> .make-settings
(cd ../deps && make hiredis linenoise lua jemalloc)
make[2]: Entering directory `/root/redis-4.0.1/deps'
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
(rm -f .make-*)
(echo "" > .make-ldflags)
(echo "" > .make-cflags)
MAKE hiredis
cd hiredis && make static
make[3]: Entering directory `/root/redis-4.0.1/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]: Leaving directory `/root/redis-4.0.1/deps/hiredis'
make[2]: *** [hiredis] 错误 2
make[2]: Leaving directory `/root/redis-4.0.1/deps'
make[1]: [persist-settings] 错误 2 (忽略)
CC adlist.o
/bin/sh: cc: command not found
make[1]: *** [adlist.o] 错误 127
make[1]: Leaving directory `/root/redis-4.0.1/src'
make: *** [all] 错误 2

显然,gcc没有安装。
说明:在进行linux系统安装时,尤其是进行linux服务器安装时,系统工程师往往会最小化安装相应的linux系统。
那么,在这样的linux系统上进行源码文件编译安装时,通常都会出现cc: Command not found,这说明系统上没有安装C语言环境,需要安装。
在linux系统上的C环境是gcc,因此需要安装gcc。

[root@centosx64 redis-4.0.]# yum install gcc -y

安装完毕gcc之后,继续安装redis。

[root@centosx64 redis-4.0.1]# make
cd src && make all
make[1]: Entering directory `/root/redis-4.0.1/src'
CC adlist.o
在包含自 adlist.c:34 的文件中:
zmalloc.h:50:31: 错误:jemalloc/jemalloc.h:没有那个文件或目录
zmalloc.h:55:2: 错误:#error "Newer version of jemalloc required"
make[1]: *** [adlist.o] 错误 1
make[1]: Leaving directory `/root/redis-4.0.1/src'
make: *** [all] 错误 2

原因:redis默认使用内存分配器jemalloc,在未安装jemalloc时就会报错:jemalloc/jemalloc.h:没有那个文件或目录。
在README中存在如下描述:

Allocator
--------- Selecting a non-default memory allocator when building Redis is done by setting
the `MALLOC` environment variable. Redis is compiled and linked against libc
malloc by default, with the exception of jemalloc being the default on Linux
systems. This default was picked because jemalloc has proven to have fewer
fragmentation problems than libc malloc. To force compiling against libc malloc, use: % make MALLOC=libc To compile against jemalloc on Mac OS X systems, use: % make MALLOC=jemalloc

解决办法:
1. 安装时明确指定分配器类型:make MALLOC=libc。
2. 先安装jemalloc之后再安装redis。

[root@centosx64 redis-4.0.1]# make MALLOC=libc
[root@centosx64 redis-4.0.1]# make test
cd src && make test
make[1]: Entering directory `/root/redis-4.0.1/src'
You need tcl 8.5 or newer in order to run the Redis test
make[1]: *** [test] 错误 1
make[1]: Leaving directory `/root/redis-4.0.1/src'
make: *** [test] 错误 2

执行make test时提示需要安装tcl 8.5及以上版本:You need tcl 8.5 or newer in order to run the Redis test

[root@centosx64 redis-4.0.1]# yum install tcl -y
[root@centosx64 redis-4.0.1]# make test
[root@centosx64 redis-4.0.1]# make install
cd src && make install
make[1]: Entering directory `/root/redis-4.0.1/src' Hint: It's a good idea to run 'make test' ;) INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
make[1]: Leaving directory `/root/redis-4.0.1/src' [root@centosx64 redis-4.0.1]# cd utils
[root@centosx64 utils]# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server Please select the redis port for this instance: [6379] [回车]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] [回车]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] [回车]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] [回车]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server] [回车]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort. [回车]
Copied /tmp/.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels !
Starting Redis server...
Installation successful!

安装完毕!注意,蓝色字体部分即为对应的redis安装配置。
并且redis服务器已经启动了!

[root@centosx64 utils]# cd ..
[root@centosx64 redis-4.0.]#

3. 查看状态/启动/停止redis

[root@centosx64 redis-4.0.]# /etc/init.d/redis_6379 status | start | stop

除了可以通过服务脚本启动redis,还可以直接使用redis-server。

[root@centosx64 redis-4.0.1]# cd src
[root@centosx64 src]# ./redis-server /path/to/redis.conf                     # 指定配置文件,redis配置参数在配置文件中
[root@centosx64 src]# ./redis-server /etc/redis/6379.conf --loglevel debug   # 指定redis配置文件,同时指定日志级别
[root@centosx64 src]# ./redis-server --port 9999 --slaveof 127.0.0.1 6379    # redis配置参数通过启动参数设置

4. 与redis服务器交互
可以直接使用redis提供的客户端工具访问本地redis服务器。

[root@centosx64 redis-4.0.1]# cd src
[root@centosx64 src]# ./redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> get foo
"bar"
127.0.0.1:6379> incr mycounter
(integer) 1
127.0.0.1:6379> get mycounter
"1"
127.0.0.1:6379> incr mycounter
(integer) 2
127.0.0.1:6379> get mycounter
"2"
127.0.0.1:6379> quit

5. 配置
(1)redis默认配置不带任何认证信息,不需要密码即可访问!

[root@centosx64 ~]# vim /etc/redis/.conf

打开如下注释:

requirepass foobared(默认密码为:foobared,应该设置为一个具备足够复杂度的认证密码)

注意:
redis在开启访问认证之后,在使用redis-cli客户端访问时必须进行认证,否则在执行操作时报错:(error) NOAUTH Authentication required.
redis-cli认证有2种方式:
方式一:先登录redis-cli客户端,在执行操作之前进行认证。

[root@centosx64 src]# ./redis-cli
127.0.0.1:6379> auth password

方式二:在登录redis-cli客户端时就进行认证,这样登录成功之后就直接可以执行操作。

[root@centosx64 src]# ./redis-cli -a password

在认证方式二中,如果传递的认证密码错误,会登录redis-cli成功,但是在执行操作时会提示报错:(error) NOAUTH Authentication required.
此时就回到认证方式一的情形了。

另外,redis开启访问认证之后,停止redis服务时也需要认证,否则报错:

[root@centosx64 redis-4.0.]# /etc/init.d/redis_6379 stop
Stopping ...
(error) NOAUTH Authentication required.
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...

此时,redis服务进程是无法正常退出的。
有3种解决办法:

方式一:通过ps命令查看redis进程,然后直接kill掉。
这种方式如果redis运行在deamon下还需要去删除pid文件,有点繁琐,不推荐使用。

方法二:通过redis-cli客户端登录,然后执行SHUTDOWN命令,推荐使用。

[root@centosx64 src]# ./redis-cli -a password
127.0.0.1:6379> SHUTDOWN
not connected> quit
[root@centosx64 src]# ./redis-cli -h 127.0.0.1 -p 6379 shutdown # 或者使用这种方式停止

方法三:修改redis服务脚本,加入如下所示的蓝色授权信息:

[root@centosx64 ~]# vim /etc/init.d/redis_6379
$CLIEXEC -a "password" -p $REDISPORT shutdown

虽然这种方式看似很方便,但是需要将认证信息配置在服务脚本中,更加容易导致认证信息泄露,不推荐使用!

(2)redis默认配置仅允许本地访问,只允许redis-cli在本地访问,其他应用程序客户端无法从外部访问。

bind 127.0.0.1

如果希望redis允许通过指定IP地址访问,则修改为绑定到指定IP地址。如:绑定redis只允许通过192.168.80.135访问。

bind 192.168.80.135

如果配置为绑定指定IP地址,那么通过redis-cli访问时必须携带-h参数,如:

[root@centosx64 src]# ./redis-cli -a password -h 192.168.80.135
192.168.80.135:6379>

此时,redis服务只能通过redis-cli停止,如果直接通过服务脚本停止,报错:

[root@centosx64 ~]# /etc/init.d/redis_6379 stop
Stopping ...
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...

如果需要一定要通过服务脚本停止redis服务,需要在服务脚本中加入如下所示的主机信息:

[root@centosx64 ~]# vim /etc/init.d/redis_6379
$CLIEXEC -a password -p $REDISPORT -h 192.168.80.135 shutdown

但是,不推荐这样操作!最好是通过redis-cli停止服务。

如果允许redis既可以通过本地访问,外部应用程序也可以访问,最直接方式就是不绑定任何IP地址,即:

#bind 127.0.0.1

总结,
1. 安装redis时注意如下组件的安装情况:
(1) gcc
(2) jemalloc
(3) tcl
2. 配置redis时注意2个方面:
(1) 配置访问认证密码
(2) 是否需要绑定到指定IP地址

【参考】
http://blog.csdn.net/bugall/article/details/45914867 Redis 安装报错 error: jemalloc/jemalloc.h: No such file or directory解决方法
http://www.ywnds.com/?p=6957 Redis安装报错error:jemalloc/jemalloc.h:No such file or directory解决方法

centos 6.8安装redis的更多相关文章

  1. Redis学习笔记(1)- CentOS 6.4 安装Redis

    Redis学习笔记(1)- CentOS 6.4 安装Redis 2013.10.13     学习环境 vm 10.1 + 默认.新装的干净 CentOS 6.4  64BIT系统     准备 1 ...

  2. CentOS 7.3 安装redis 4.0.2服务

    CentOS 7.3 安装redis 4.0.2服务 1.下载解压 下载地址:/home/xiaoming/ wget http://download.redis.io/releases/redis- ...

  3. centos上如何安装redis?|centos傻瓜式安装redis教程

    本文介绍centos安装redis,请不要安装2.4.3,是有问题的. 首先安装gcc yum -y install gcc yum -y install gcc-c++ yum install ma ...

  4. 如何在 CentOS 7 上安装 Redis 服务器

    大家好,本文的主题是 Redis,我们将要在 CentOS 7 上安装它.编译源代码,安装二进制文件,创建.安装文件.在安装了它的组件之后,我们还会配置 redis ,就像配置操作系统参数一样,目标就 ...

  5. CentOS 7 服务器配置--安装Redis

    #下载Redis wget -r -np -nd http://download.redis.io/releases/redis-3.2.8.tar.gz #解压文件 tar zxvf redis-3 ...

  6. [从零开始搭网站八]CentOS使用yum安装Redis的方法

    1.由于centOS官方yum源里面没有Redis,这里我们需要安装一个第三方的yum源,这里用了fedora的epel仓库 yum install epel-release 安装过程中会有让你确认的 ...

  7. CentOS 7 yum 安装redis(更简单)

    一.安装redis 1.检查是否有redis yum 源 1 yum install redis 2.下载fedora的epel仓库 1 yum install epel-release 3.安装re ...

  8. redis学习之——CentOS 6 下载安装redis

    一.检查当前环境: 安装过程中没有这些,命令,在CentOS 6,最小安装导致..如果执行完命令,Noting  to  do...字样说明环境正常. yum -y install rpm gcc w ...

  9. CentOS 7 下安装redis步骤

    1. 从redis官网下载redis源码,本例安装在/usr/opt下 [root@localhost opt]# pwd /usr/opt [root@localhost opt]# wget ht ...

  10. centos 6.5 安装 redis

    下载软件: wget wget http://download.redis.io/releases/redis-2.8.7.tar.gz 2.解压软件并编译安装: tar -zxvf redis-2. ...

随机推荐

  1. Codeforces Round #432 (Div. 1, based on IndiaHacks Final Round 2017) D. Tournament Construction(dp + 构造)

    题意 一个竞赛图的度数集合是由该竞赛图中每个点的出度所构成的集合. 现给定一个 \(m\) 个元素的集合,第 \(i\) 个元素是 \(a_i\) .(此处集合已经去重) 判断其是否是一个竞赛图的度数 ...

  2. Atcoder | AT2665 【Moderate Differences】

    又是一道思路特别清奇的题qwq...(瞪了一上午才发现O(1)的结论...差点还想用O(n)解决) 问题可以转化为是否能够由\(f_{1}=a\)通过\(\pm x \in[c,d]\)得到\(f_{ ...

  3. rt-thread是如何做到通过menuconfig配置将相应文件加入工程和从工程中除去

    @2019-01-25 [小记] 添加与删除文件的机制是: menuconifg 所显示的菜单是由一系列 Kconfig 文件构成的,这些菜单实际就是一系列的宏控制,而这些宏又控制着一系列的 SCon ...

  4. Haunted Graveyard ZOJ - 3391(SPFA)

    从点(n,1)到点(1,m)的最短路径,可以转换地图成从(1,1)到(n,m)的最短路,因为有负权回路,所以要用spfa来判负环, 注意一下如果负环把终点包围在内的话, 如果用负环的话会输出无穷,但是 ...

  5. webpack入门(三)webpack的api

    终于到了webpack api这一篇,我都等不及了0.0; webpack is fed a configuration object. Depending on your usage of webp ...

  6. 洛谷P3338 力

    题意: 解: 介绍两种方法. 首先可以把那个最后除的qi拆掉. ①分前后两部分处理. 前一部分可以看做是个卷积.下面的平方不拆开,直接看成gi-j即可. 后一部分按照套路,把循环变量改成从0开始,反转 ...

  7. 2018-2019 ACM-ICPC, Asia Nanjing Regional Contest

    https://codeforces.com/gym/101981 Problem A. Adrien and Austin 贪心,注意细节 f[x]=1:先手必赢. f[x]: 分成两部分(或一部分 ...

  8. 从 date 中取出 小时和分钟进行比较

    public class T1 { public static void main(String[] args) throws ParseException { SimpleDateFormat df ...

  9. Java多线程-详细版

    基本概念解释 并发:一个处理器处理多个任务,这些任务对于处理器来说是交替运行的,每个时间点只有一个任务在进行. 并行:多个处理器处理多个任务,这些任务是同时运行的.每个时间点有多个任务同时进行. 进程 ...

  10. JQERY EasyUI Tabs 选项卡 自适应浏览器宽度高度 解决方案

    <script type="text/javascript"> $(window).resize(function () { $('#tt').tabs({ width ...