centos redis 安装过程,解决办法

第一步:下载并编译

wget http://download.redis.io/redis-stable.tar.gz

tar xvzf redis-stable.tar.gz

cd redis-stable

make

报错:

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

解决:

  1. wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz  
  2. sudo tar xzvf tcl8.6.1-src.tar.gz  -C /usr/local/  
  3. cd  /usr/local/tcl8.6.1/unix/  
  4. sudo ./configure  
  5. sudo make  
  6. sudo make install  

第二步:执行make test


说明可进行安装


第三步:make install



第四步:安装成功后,修改运行环境


在make成功以后,会在src目录下多出一些可执行文件:redis-server,redis-cli等等。

方便期间用cp命令复制到usr目录下运行。

cp redis-server /usr/local/bin/

cp redis-cli /usr/local/bin/

然后新建目录,存放配置文件

mkdir /etc/redis

mkdir /var/redis

mkdir /var/redis/log

mkdir /var/redis/run

mkdir /var/redis/6379

 

在redis解压根目录中找到配置文件模板,复制到如下位置。

cp redis.conf  /etc/redis/6379.conf

通过vi命令修改

daemonize yes

pidfile /var/redis/run/redis_6379.pid

logfile /var/redis/log/redis_6379.log

dir /var/redis/6379

最后运行redis:

$ redis-server /etc/redis/6379.conf

查看是否跑起来:ps -aux | grep redis


第五步:配置启动脚本

mkdir /etc/init.d/reids

vi /etc/init.d/redis

放入以下内容:

###########################  
PATH=/usr/local/bin:/sbin:/usr/bin:/bin  
   
REDISPORT=6379  
EXEC=/usr/local/bin/redis-server  
REDIS_CLI=/usr/local/bin/redis-cli  
   
###PIDFILE=/var/run/redis.pid
PIDFILE=/var/redis/run/redis_6379.pid

###CONF="/etc/redis.conf" 
CONF="/etc/redis/6379.conf" 
   
case "$1" in  
    start)  
        if [ -f $PIDFILE ]  
        then  
                echo "$PIDFILE exists, process is already running or crashed"  
        else  
                echo "Starting Redis server..."  
                $EXEC $CONF  
        fi  
        if [ "$?"="0" ]  
        then  
              echo "Redis is running..."  
        fi  
        ;;  
    stop)  
        if [ ! -f $PIDFILE ]  
        then  
                echo "$PIDFILE does not exist, process is not running"  
        else  
                PID=$(cat $PIDFILE)  
                echo "Stopping ..."  
                $REDIS_CLI -p $REDISPORT SHUTDOWN  
                while [ -x ${PIDFILE} ]  
               do  
                    echo "Waiting for Redis to shutdown ..."  
                    sleep 1  
                done  
                echo "Redis stopped"  
        fi  
        ;;  
   restart|force-reload)  
        ${0} stop  
        ${0} start  
        ;;  
  *)  
    echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2  
        exit 1  
esac  
##############################

执行文件属性

chmod +x /etc/init.d/redis  


第六步:启动和测试redis


 启动服务:    /etc/init.d/redis start


 启动客户端:  redis-cli


  测试:

127.0.0.1:6379> set 1 1
OK
127.0.0.1:6379> get 1
"1"
127.0.0.1:6379>










posted @ 2016-11-20 00:04  172257861  阅读(86)  评论(0编辑  收藏  举报