CentOS 安装 Redis

  在学习RHP SessionRedis时,发现根本没有装Redis。

立马搜索安装教程,转snowolf 的http://snowolf.iteye.com/blog/1630697

1、下载和解压

wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz
tar zxvf redis-2.6.14.tar.gz

2、在/opt/redis-2.6.14/目录下,执行make时报错:/bin/sh: cc: command not found

好吧,都没有装相关的编译工具。

搜,sudo apt-get install build-essential

error 1):bash: apt-get: command not found

再搜,CentOS的软件安装工具不是apt-get  是yum,

正确的应该是sudo yum -y install gcc gcc-c++ libstdc++-devel

安装成功。

error 2)在/opt/redis-2.6.14/目录下,执行make时报错

make[1]: Entering directory `/opt/redis-2.6.14/src'
CC adlist.o
In file included from adlist.c:34:
zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/opt/redis-2.6.14/src'
make: *** [all] Error 2

好吧,继续~,发现:http://xueliang1yi.blog.163.com/blog/static/1145570162012102114635764/

好像遇到了类似的情况,文中提到了安装gcc,把他的命令也敲了一边,系统提示最新版本的已经装好了,不需要再装了。

之后执行 make MALLOC=libc 就行

error 3)执行完上面的命令后,系统提示 'Hint: To run 'make test' is a good idea'

make test 报错: You need tcl 8.5 or newer in order to run the Redis test

3.1)在上面的也是有提到的,不过还是找了一个更详细的安装tcl的方法;

下载地址:http://downloads.sourceforge.net/tcl/tcl8.5.10-src.tar.gz

安装命令:http://blog.csdn.net/makebuaa/article/details/6709140

tcl 安装
[user@localhost 桌面]$ ls tcl8.5.9-src.tar.gz
tcl8.5.9-src.tar.gz
[user@localhost 桌面]$ su
密码:
[root@localhost 桌面]# cp tcl8.5.9-src.tar.gz /usr/local/src/
[root@localhost 桌面]# cd /usr/local/src/
[root@localhost src]# tar -zxvf tcl8.5.9-src.tar.gz
[root@localhost src]# cd tcl8.5.9/
[root@localhost tcl8.5.9]# cd unix/
[root@localhost unix]# ./configure --prefix=/usr/local/tcl/ --enable-shared
[root@localhost unix]# make
[root@localhost unix]# make install
[root@localhost unix]# /usr/local/tcl/bin/tclsh8.5
% exit
[root@localhost unix]#

3.2)还是提示错误需要tcl8.5或更新的版本

  发现 sudo yum install tcl 就可以搞定,只是版本是8.5.7的。

      终于提示'o/ All tests passed without errors!'

在/opt/redis-2.6.14/目录下,执行make,OK;

4、修改配置文件目录

mkdir /etc/redis
cp redis.conf /etc/redis

5、运行

redis-server /etc/redis/redis.conf

摘自http://www.cnblogs.com/chy710/archive/2012/05/28/redis.html

redis-server.exe是Redis服务程序,命令行运行后启动服务端
[2624] 28 May 17:19:30 * Server started, Redis version 2.4.2
[2624] 28 May 17:19:30 # Open data file dump.rdb: No such file or directory
[2624] 28 May 17:19:30 * The server is now ready to accept connections on port 6379

redis-cli.exe是一个客户端程序,命令行下运行,简单的一个Set/Get

redis 127.0.0.1:6379> set mykey "this is a value"
OK
redis 127.0.0.1:6379> get mykey
"this is a value"
redis 127.0.0.1:6379>

6、写入开机自启动 echo "redis-server /etc/redis/redis.conf" >>/etc/rc.local

7、测试,参考 http://blog.csdn.net/21aspnet/article/details/6960757 

启动进程

#redis-server /etc/redis/redis.conf

查看进程有没有成功启动

#ps -ef | grep redis 
测试输入一个键值
#redis-cli set test "123456"
获取键值
#redis-cli get test

Note:

以下两文中都有链接一些另外的Redis的信息,有时间去看看...

http://blog.csdn.net/chenggong2dm/article/details/6100001

http://www.cnblogs.com/chy710/archive/2012/05/28/redis.html

原文地址:https://www.cnblogs.com/la-isla-bonita/p/3582751.html