redis安装

原文:http://my.oschina.net/xinxingegeya/blog/212348#OSC_h2_6

安装准备:redis2.8.7,redhat

    只供参考

1.解压

    [root@dell1 soft]# tar -xzvf redis-2.8.7.tar.gz

2.进入解压后的目录,直接执行make命令

    [root@dell1 soft]# cd redis-2.8.7

    [root@dell1 redis-2.8.7]# pwd

    /home/soft/redis-2.8.7

    [root@dell1 redis-2.8.7]# make

3.执行make test

    执行成功make命令后,会提示执行make test,如果没有安装tcl,则会报错

    报错,提示没有You need 'tclsh8.5' in order to run the Redis test,

    所以接下来应该安装tcl,这个不清楚是什么东西。下载tcl8.6.1

    #cd tcl8.6.1/unix/

    #./configure

    #make

    #make test

    #make install

    这样应该完成安装完tcl了

4.回到redis的安装目录重新执行make test

    \o/ All tests passed without errors!

    make test执行成功

    Cleanup: may take some time... OK

    make[1]: Leaving directory `/home/soft/redis-2.8.7/src'

5.执行make install

    [root@dell1 redis-2.8.7]# make install

6.执行install_server.sh文件

    [root@dell1 redis-2.8.7]# cd utils/

    [root@dell1 utils]# ls

    build-static-symbols.tcl redis-copy.rb         speed-regression.tcl

    generate-command-help.rb redis_init_script     whatisdoing.sh

    install_server.sh        redis_init_script.tpl

    mkrelease.sh             redis-sha1.rb

    [root@dell1 utils]# ./install_server.sh

    Welcome to the redis service installer

    This script. will help you easily set up a running redis server

    Please select the redis port for this instance:[6379]

    Selecting default: 6379

    Please select the redis config file name[/etc/redis/6379.conf]

    Selected default - /etc/redis/6379.conf

    Please select the redis log file name[/var/log/redis_6379.log]

    Selected default - /var/log/redis_6379.log

    Please select the data directory for this instance[/var/lib/redis/6379]

    Selected default - /var/lib/redis/6379

    Please select the redis executable path[/usr/local/bin/redis-server]

    s#^port [0-9]{4}$#port 6379#;s#^logfile .+$#logfile /var/log/redis_6379.log#;s#^dir .+$#dir /var/lib/redis/6379#;s#^pidfile .+$#pidfile /var/run/redis_6379.pid#;s#^daemonize no$#daemonize yes#;

    Copied /tmp/6379.conf =>/etc/init.d/redis_6379

    Installing service...

    ./install_server.sh: line 178: update-rc.d: command not found

    exists, process is already running or crashed

    Installation successful!

    执行完成。这里使用了默认配置

7.启动redis服务

    [root@dell1 utils]# cd /usr/local/bin

    [root@dell1 bin]# ls

    event_rpcgen.py memcached-debug redis-check-aof  redis-cli    tclsh8.6

    memcached       redis-benchmark redis-check-dump redis-server

    [root@dell1 bin]#./redis-server /etc/redis/6379.conf

8.查看服务是否启动

    [root@dell1 bin]#ps -ef | grep 6379

    root     3206    1 0 13:06 ?       00:00:00 /usr/local/bin/redis-server *:6379

    root     7996 3294 0 13:45 pts/0   00:00:00 grep 6379

9.修改redis启动文件

    在init.d下有一个默认文件redis_6379,打开文件,修改后如下

    #/bin/sh\n

    #Configurations injected by install_server below....

    EXEC=/usr/local/bin/redis-server

    CLIEXEC=/usr/local/bin/redis-cli

    PIDFILE=/var/run/redis_6379.pid

    CONF="/etc/redis/6379.conf"

    REDISPORT="6379"

    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

    ;;

    stop)

    if [ ! -f $PIDFILE ]

    then

    echo "$PIDFILE does not exist, process is not running"

    else

    PID=$(cat $PIDFILE)

    echo "Stopping ..."

    $CLIEXEC -p $REDISPORT shutdown

    while [ -x /proc/${PID} ]

    do

    echo "Waiting for Redis to shutdown ..."

    sleep 1

    done

    echo "Redis stopped"

    fi

    ;;

    *)

    echo "Please use start or stop as first argument"

    ;;

    esac

    保存退出

10更改redis_6379的名字

    [root@dell1 init.d]# mv redis_6379 redis

11.刚才已经启动服务,现在使用service关闭服务,开启服务

    [root@dell1 bin]# service redis stop

    Stopping ...

    Redis stopped

    [root@dell1 bin]# service redis start

    Starting Redis server...

12.使用redis-cli登录

    [root@dell1 bin]# cd /usr/local/bin

    [root@dell1 bin]# ls

    event_rpcgen.py memcached-debug redis-check-aof  redis-cli    tclsh8.6

    memcached       redis-benchmark redis-check-dump redis-server

    [root@dell1 bin]# ./redis-cli

    127.0.0.1:6379> set key 122

    OK

    127.0.0.1:6379> get key

    "122"

    127.0.0.1:6379> exists key

    (integer) 1

posted @ 2014-09-30 00:12  一束光  阅读(359)  评论(0编辑  收藏  举报

友情链接

CFC4N