Redis 3.0.1 安装和配置

Redis 3.0.1 安装和配置

 

一、下载,解压和编译Redis

 

# cd /tmp   
# wget http://download.redis.io/releases/redis-3.0.1.tar.gz    
# tar xzf redis-3.0.1.tar.gz    
# cd redis-3.0.1    
# make

 

二、下载、安装tclsh

 

测试编译:

# make test


得到如下错误信息: 

cd src && make test    
make[1]: Entering directory `/tmp/redis-3.0.1/src'    
You need tcl 8.5 or newer in order to run the Redis test    
make[1]: *** [test] Error 1    
make[1]: Leaving directory `/tmp/redis-3.0.1/src'    
make: *** [test] Error 2


Redis在make test有使用到tclsh对Redis进行测试,所有需要将tclsh安装好。

tclsh下载可以直接从官网http://www.tcl.tk/software/tcltk/download.html下载其最新版

# cd /tmp    
# wget http://prdownloads.sourceforge.net/tcl/tcl8.6.4-src.tar.gz    
# tar xzvf tcl8.6.4-src.tar.gz    
# cd tcl8.6.4/unix     #windows进入tcl8.6.4/win    
# ./configure --prefix=/usr/local/tcl8.6.4 --enable-64bit  #enable-64bit对64系统生效    
# make && make install


安装完成之后需要将tclsh添加到PATH中,并使其生效  
   

# vim /etc/profile

  
PATH=/usr/local/tcl8.6.4/bin:$PATH    
export PATH    
  

# source /etc/profile

这样tclsh就已经安装完成了。

 

三、再次测试编译

# cd /tmp/redis-3.0.1    
# make test

将会收到信息:  
All tests passed without errors!

 

四、简单试用(生产环境略过)

 

在src目录下,编译后的二进制文件可用。运行Redis服务端:

# src/redis-server

你可以用内置的客户端与Redis交互:

# src/redis-cli

 
redis> set foo bar    
OK    
redis> get foo    
"bar"

 

五、安装redis到指定目录

 

也可以将redis安装到指定的/usr/local/redis目录下:

# make PREFIX=/usr/local/redis install

 

六、配置redis

 

为redis配置PATH:

#vi /etc/profile #添加下行内容


PATH=$PATH:/usr/local/redis/bin

export PATH

 

#source /etc/profile
#cp redis.conf /etc/
#vi /etc/sysctl.conf #添加vm.overcommit_memory=1,否则出现如下警告
# WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then
reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.


#vi /etc/redis.conf  #对应行修改为下面内容    
daemonize yes    
logfile /var/log/redis.log

 

七、编写服务管理脚本

 

#vi /etc/init.d/redis
#!/bin/sh   
#chkconfig: 345 86 14    
#description: Startup and shutdown script for Redis    
  
PROGDIR=/usr/local/redis #安装路径    
PROGNAME=redis-server    
DAEMON=$PROGDIR/$PROGNAME    
CONFIG=/etc/redis.conf    
PIDFILE=/var/run/redis.pid    
DESC="redis daemon"    
SCRIPTNAME=/etc/rc.d/init.d/redis    
  
start()    
{    
         if test -x $DAEMON    
         then    
        echo -e "Starting $DESC: $PROGNAME"    
                   if $DAEMON $CONFIG    
                   then    
                            echo -e "OK"    
                   else    
                            echo -e "failed"    
                   fi    
         else    
                   echo -e "Couldn't find Redis Server ($DAEMON)"    
         fi    
}    
  
stop()    
{    
         if test -e $PIDFILE    
         then    
                   echo -e "Stopping $DESC: $PROGNAME"    
                   if kill `cat $PIDFILE`    
                   then    
                            echo -e "OK"    
                   else    
                            echo -e "failed"    
                   fi    
         else    
                   echo -e "No Redis Server ($DAEMON) running"    
         fi    
}    
  
restart()    
{    
    echo -e "Restarting $DESC: $PROGNAME"    
    stop    
         start    
}    
  
list()    
{    
         ps aux | grep $PROGNAME    
}    
  
case $1 in    
         start)    
                   start    
        ;;    
         stop)    
        stop    
        ;;    
         restart)    
        restart    
        ;;    
         list)    
        list    
        ;;    
  
         *)    
        echo "Usage: $SCRIPTNAME {start|stop|restart|list}" >&2    
        exit 1    
        ;;    
esac    
exit 0
#chmod +x /etc/init.d/redis

 

八、设置开机启动

 

#chkconfig --add redis   
#chkconfig --level 35 redis on    
#chkconfig --list redis


九、启动、关闭服务


前台以配置文件启动:

# redis-server /etc/redis.conf #默认情况下redis前端运行,并把日志输出到屏幕上


生产环境直接以服务启动:

# service redis start
# netstat -tnlp |grep 6379


以命令关闭服务:

# redis-cli shutdown


生产环境直接以服务关闭:

# service redis stop


十、测试


# redis-cli
127.0.0.1:6379> info
# Server
redis_version:3.0.1
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:6d627ecdac18555f
redis_mode:standalone
os:Linux 2.6.32-358.el6.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.4.7
process_id:6173
run_id:aedc790ab2d0eb75f3d5afe10c6af937d16955b0
tcp_port:6379
uptime_in_seconds:706
uptime_in_days:0
hz:10
lru_clock:6829896
config_file:/etc/redis.conf

...

...


参见:http://redis.io/download

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值