安装

  1. 通过wget直接下载redis源码安装包,目前最新半5.0的
1
wget http://download.redis.io/releases/redis-5.0.5.tar.gz
  1. 解压
1
tar -xvf redis-5.0.5.tar.gz
  1. 进入源码目录
1
cd redis-5.0.5/src
  1. 编译
1
make && make install

运行

  • 安装成功后,配置文件/etc/redis.conf

默认daemon 为no,ip:127.0.0.1直接运行

1
redis-server /etc/redis.conf

运行后出现下图,则运行成功:

redis-start

  • 访问
1
2
3
4
5
6
[root@localhost ~]# redis-cli
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> keys *
1) "foo"
127.0.0.1:6379>
  • 修改配置文件,daemon/ip,基本修改,重新运行便可启动了
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.

daemonize yes

# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 loopback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

bind 127.0.0.1

安装过程种可能出现的问题

  1. centos没有安装gcc,会出现
1
command not found: CC

安装gcc

1
yum install -y gcc
  1. make时报如下错误:
1
2
zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error "Newer version of jemalloc required"

原因是jemalloc重载了Linux下的ANSI C的malloc和free函数。解决办法:make时添加参数。

1
make MALLOC=libc
  1. make之后,会出现一句提示
1
Hint: To run 'make test' is a good idea ;)

但是不测试,通常是可以使用的。若我们运行make test ,会有如下提示

1
2
You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] Error 1

解决办法是用yum安装tcl8.5(或去tcl的官方网站http://www.tcl.tk/下载8.5版本,并参考官网介绍进行安装)

1
yum install tcl