centos 安装redis2.8.9

1没有安装gcc

  yum install gcc-c++

2. 安装tcl

   yum install -y tcl

3.安装redis

  $ wget http://download.redis.io/releases/redis-2.8.9.tar.gz
  $ tar xzf redis-2.8.9.tar.gz
  $ cd redis-2.8.9
  $ make
  $ make test
  $ make install

4.编辑redis.conf文件

   把 daemonize no 改成 yes。(redis以守护进程的方式运行

   然后把redis.cong复制到/etx

   cp redis.conf /etc

5.编写一个自启动脚本(网上摘抄)

   

###########################
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
CONF="/etc/redis.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
##############################

 把这段保存成redis,放到/etc/init.d/下面

   chmod +x /etc/init.d/redis (修改权限)

   sudo chkconfig redis on

6.启动和停止

   service redis start #或者 /etc/init.d/redis start
   service redis stop #或者 /etc/init.d/redis stop

7.测试  

   redis-cli
   redis 127.0.0.1:6379> set name fu
   OK
   redis 127.0.0.1:6379> get name
   "fu"
   redis 127.0.0.1:6379> exit

8.哦了,继续学习,加油!

 

posted @ 2015-01-30 17:13  付建超  阅读(510)  评论(0编辑  收藏  举报