Redis 环境的安装与测试

     Redis 是 key-value 的NOSQL、独爱那些 小而热 的数据、典型"萝莉控"
     至于啥叫 key-value 呢?用RDBMS的观点、一言以辟之:
     所谓 key:主键列
     所谓 value:其他列
     Redis 近几年很火、火到抬头不见、低头见
     抬头望国外:著名成人网站 youporn 采用 100% Redis 每天 1亿 PV、解决了无数屌丝 YY 问题
     低头思国内:新浪微博走的 Redis 之路、那叫一把眼泪一把辛酸呀
     

     千里之行、始于安装、Let's 谈谈一次简单的安装步骤

 

     ㈠ 安装 Redis

 

 

# wget https://redis.googlecode.com/files/redis-2.6.13.tar.gz
# tar -zxv -f redis-2.6.13.tar.gz
# cd redis-2.6.13
# cd src
# make 
# mkdir /etc/redis/
# cp redis.conf /etc/redis/redis.conf
# echo "1" > /proc/sys/vm/overcommit_memory
# make install 


 

     ㈡ 设置 Redis 为后台守护进程

 

 

# cat /etc/redis/redis.conf | grep -in --color=auto 'daemonize'

16:# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
17:daemonize yes


 

     ㈢ 启动 Redis

 

 

# redis-server /etc/redis/redis.conf
# ps aux | grep redis

root     32111  0.0  0.0  31496  1500 ?        Ssl  16:38   0:00 redis-server /etc/redis/redis.conf
root     32122  0.0  0.0   5128   676 pts/2    R+   16:39   0:00 grep redis


 

     ㈣ 测试 Redis

 

 

# redis-cli

redis 127.0.0.1:6379> set name "David Lin"
OK
redis 127.0.0.1:6379> get name
"David Lin"
redis 127.0.0.1:6379> hset 192.168.1 David David@redis
(integer) 1
redis 127.0.0.1:6379> hget 192.168.1 David
"David@redis"
redis 127.0.0.1:6379> hset 192.168.1 root root@redis
(integer) 1
redis 127.0.0.1:6379> hget 192.168.1 root
"root@redis"
redis 127.0.0.1:6379> hkeys 192.168.1
1) "David"
2) "root"
redis 127.0.0.1:6379> hvals 192.168.1
1) "David@redis"
2) "root@redis"
redis 127.0.0.1:6379> hgetall 192.168.1
1) "David"
2) "David@redis"
3) "root"
4) "root@redis"
redis 127.0.0.1:6379> type name
string
redis 127.0.0.1:6379> type 192.168.1
hash
redis 127.0.0.1:6379> quit


 

     ㈤ 关闭 Redis 

 

 

# redis-cli shutdown


 

     ㈥ 可能的错误


        
        安装过程、或许您可能会有幸遇见:

 

 

zmalloc.o: In function `zmalloc_used_memory':
/root/redis/redis-2.6.13/src/zmalloc.c:223: undefined reference to `__sync_add_and_fetch_4'
collect2: ld 返回 1
make[1]: *** [redis-server] 错误 1
make[1]: Leaving directory `/root/redis/redis-2.6.13/src'
make: *** [all] 错误 2


 

     大概是内核有点老了、跟不上最新的Redis

 

 

[root@odd ~]# uname -r
2.6.18-308.el5xen


 

     解决方案:
     安装最新版的Tcl

 

# wget http://nchc.dl.sourceforge.net/project/tcl/Tcl/8.6.0/tcl8.6.0-src.tar.gz    
# tar -zxv -f tcl8.6.0-src.tar.gz 
# cd tcl8.6.0
# cd unix
# ./configure 
# make
# make test
# make install 


 

     之后再做 2 件事:

     ① 在src/Makefile开头加 CFLAGS= -march=i686
     ② 编辑src/.make-settings里的OPT,改为OPT=-O2 -march=i686

 

     行文至此、接近尾声、安装过程并不复杂、至于测试的命令嘛、下回更精彩 +_+


     
     Good Luck

     2013-05-30
     By David Lin 

 

posted @ 2013-05-30 20:30  javawebsoa  Views(160)  Comments(0Edit  收藏  举报