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. Linux iptables设置

    先举例子说明,若服务器网卡: eth0 10.10.0.100 eth0:0 10.10.0.200 eth0:1 10.10.0.201 eth0:2 10.10.0.202 只允许10.10.0. ...

  2. Manacher (最长回文序列)

    https://www.cnblogs.com/grandyang/p/4475985.html 思路是学习的是上面博客的想法,思路很清晰 优化的方法和exkmp有异曲同工的地方 博客里的内容我在这里 ...

  3. 课后选做题:MyCP

    目录 CP命令了解 MyCP实现 CP命令了解 作用:cp指令用于复制文件或目录,如同时指定两个以上的文件或目录,且最后的目的地是一个已经存在的目录,则它会把前面指定的所有文件或目录复制到此目录中.若 ...

  4. redis健康检查与故障转移

    哨兵三个定时监控任务 每隔10s每隔sentinel节点会向主节点和从节点发送info命令获取最新的拓扑结构 每隔2S,每个sentinel节点会向redis数据节点的__sentiel__:hell ...

  5. rxjs学习笔记

    api List Rx.Observable.amb(...args) -存在竞争关系,amb里的流只能触发一个,并且忽略其他未处理的流. eq: <body> <input id= ...

  6. 用lemon测交互题

    题目类型:传统. 答案比较类型:逐行比较类型(忽略多余空格和制表符). 配置:交互. 编译器参数: -o %s %s.* ..\..\data\%s\judge.cpp -Wl,--stack= ju ...

  7. 斯坦福大学公开课机器学习:machine learning system design | data for machine learning(数据量很大时,学习算法表现比较好的原理)

    下图为四种不同算法应用在不同大小数据量时的表现,可以看出,随着数据量的增大,算法的表现趋于接近.即不管多么糟糕的算法,数据量非常大的时候,算法表现也可以很好. 数据量很大时,学习算法表现比较好的原理: ...

  8. python logging日志模块

    一.logging模块的简介 logging模块是Python内置的标准模块,主要用于输出运行日志,可以设置输出日志的等级.日志保存路径.日志文件回滚等:相比print,具备如下优点: 可以通过设置不 ...

  9. C++基础知识--DAY2

    昨天我们主要是讲的C++相对于C语言的变化,结尾讲述了一点引用的基础知识,要明白,引用就是对一个变量取别名,在C++中需要用指针的都可以思考是否可以用引用来代替. 1. 常引用 常引用(const s ...

  10. c#中委托和事件区别

    委托和事件相同的功能 class Dem5 { public Action deHandler; public event Action eveHa; public Dem5() { deHandle ...