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. JLOI2016 简要题解

    「JLOI2016」侦查守卫 题意 有一个 \(n\) 个点的树,有 \(m\) 个关键点需要被监视.可以在其中一些点上插眼,在 \(i\) 号点上放眼需要花费 \(w_i\) 的代价,可以监视距离 ...

  2. Hdoj 1176.免费馅饼 题解

    Problem Description 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁 ...

  3. Dynamic CRM 2015学习笔记(4)修改开发人员资源(发现服务、组织服务和组织数据服务)url地址及组织名

    在azure vm上安装了CRM 2015后 Dynamic CRM 2015学习笔记(1)Azure 上安装 CRM 2015, 发现了一个问题,那就是在设置 ->自定义项 –> 开发人 ...

  4. ST算法(倍增)(用于解决RMQ)

    ST算法 在RMQ(区间最值问题)问题中,我了解到一个叫ST的算法,实质是二进制的倍增. ST算法能在O(nlogn)的时间预处理后,用O(1)的时间在线回答区间最值. f[i][j]表示从i位起的2 ...

  5. Ubuntu下redis数据库的安装和配置详细过程

    Redis 安装 当前redis最新稳定版本是4.0.9 当前ubuntu虚拟机中已经安装好了redis,以下步骤可以跳过 最新稳定版本下载链接:http://download.redis.io/re ...

  6. CodeFroces--Joseph’s Problem

    题目意思:给出n k 求  k%1 + k%2 +k%3+...+k%n 的和 利用分块的思想 我们知道 k%i ==k-k/i*i 同时 一段连续的区间的 k/i 是相等的 #include< ...

  7. P1972 HHのnecklace 离线+树状数组

    此题莫队可过 然而太难了...... 我在胡雨菲那看的解法,然后自己打了一波,调了一个错,上交,自信AC. 做法:离线,对于L排序. 每种颜色可能出现很多次,那么我们如何不算重复呢? 只需把[L,n] ...

  8. Mybatis 批量插入时得到插入的id(mysql)

    前言: 在开发中,我们可能很多的时候可能需要在新增时得到刚才新增的id,后续的逻辑需要用到这个id. 在插入单条记录的情况下,这个是很简单的问题.多条记录时有个坑在里面. 单条记录的代码如下 < ...

  9. 第三十三篇-TabLayout的使用

    效果图: 最上方是一个TabLayout,有三个部分,新闻.财经.娱乐,下方是一个ViewPaper,里面包含三个fragment,分别对应三个xml和java class. 第一个Fragment里 ...

  10. GUI制作仿qq窗口

    使用工具:python3.6,   pycharm 使用模块: tkinter模块:("Tk 接口")是Python的标准Tk GUI工具包的接口,位Python的内置模块,直接i ...