linux 下 redis 安装
linux 下 redis 安装
1、redis下载地址
https://redis.googlecode.com/files/redis-2.6.14.tar.gz
2、安装步骤:
# tar zxvf redis-2.6.14.tar.gz
# cd redis-2.6.14
# make
在redhat 32bit机器上,会报错。错误信息:
zmalloc.o: In function `zmalloc_used_memory':
/nosql/redis/redis-2.6.14/src/zmalloc.c:223: undefined reference to `__sync_add_and_fetch_4'
collect2: ld 返回 1
make[1]: *** [redis-server] 错误 1
make[1]: Leaving directory `/nosql/redis/redis-2.6.14/src'
make: *** [all] 错误 2
解决方法如下:
编辑了下src/.make_settings里的OPT,改为:OPT=-O2 -march=i686
然后:make clean
make
还是会出现警告:
redis-cli.c: In function ‘pipeMode’:
redis-cli.c:1156: 警告:提领类型双关的指针将破坏强重叠规则
LINK redis-cli
CC redis-benchmark.o
LINK redis-benchmark
CC redis-check-dump.o
LINK redis-check-dump
CC redis-check-aof.o
LINK redis-check-aof
Hint: To run 'make test' is a good idea ;)
make[1]: Leaving directory `/nosql/redis/redis-2.6.14/src'
警告可以不管,当看到Hint: To run 'make test' is a good idea ;)说明make成功!
接着make test
[root@linux redis-2.6.14]# make test
cd src && make test
make[1]: Entering directory `/nosql/redis/redis-2.6.14/src'
You need tcl 8.5 or newer in order to run the Redis test
make[1]: *** [test] 错误 1
make[1]: Leaving directory `/nosql/redis/redis-2.6.14/src'
make: *** [test] 错误 2
解决方法如下:
按照官网 http://www.linuxfromscratch.org/blfs/view/cvs/general/tcl.html 上的安装tcl!
不过这个make test报错不影响redis的运行和使用!
待执行完之后你会看到src目录下有:redis-benchmark,redis-cli,redis-server文件,证明已经成功了;
3、为了方便调用,修改redis相关配置
我们自己新建一个目录来存放执行文件以及日志配置文件
[root@linux redis]# cd /nosql/redis/
[root@linux redis]# mkdir redis
[root@linux redis]# cd redis
[root@linux redis]# pwd
/nosql/redis/redis
[root@linux redis]# mkdir bin
[root@linux redis]# mkdir etc
[root@linux redis]# mkdir var
[root@linux redis]# ls
bin etc var
拷贝执行文件和配置文件到相应目录
[root@linux redis]# pwd
/nosql/redis/redis
[root@linux redis]# cp /nosql/redis/redis-2.6.14/src/redis-benchmark ./bin/
[root@linux redis]# cp /nosql/redis/redis-2.6.14/src/redis-cli ./bin/
[root@linux redis]# cp /nosql/redis/redis-2.6.14/src/redis-server ./bin/
[root@linux redis]# cp /nosql/redis/redis-2.6.14/redis.conf ./etc/
修改配置文件准备启动redis,激动人心的时刻即将来临了
# vi /nosql/redis/redis/etc/redis.conf
daemonize yes
logfile /nosql/redis/redis/var/redis.log
dir /nosql/redis/redis/var/
4、测试redis:
启动redis
[root@linux /]# cd /nosql/redis/redis/bin/
[root@linux bin]# ./redis-server ../etc/redis.conf
[root@linux bin]# ps aux | grep redis
root 16412 0.0 0.0 31368 1492 ? Ssl 23:16 0:00 ./redis-server ../etc/redis.conf
root 16421 0.0 0.0 5196 692 pts/0 S+ 23:17 0:00 grep redis
测试:
[root@linux bin]# telnet 127.0.0.1 6379
Trying 127.0.0.1...
Connected to linux (127.0.0.1).
Escape character is '^]'.
set test zhagnsan
+OK
get test
$8
zhagnsan
quit
+OK
Connection closed by foreign host.