安装Redis

1、下载redis

http://redis.io/download

 

2、解压缩、安装

[root@iZ944wsnvhcZ local]# tar -zxvf redis-3.0.1.tar.gz 
[root@iZ944wsnvhcZ local]# cd redis-3.0.1
[root@iZ944wsnvhcZ redis-3.0.1]# make
[root@iZ944wsnvhcZ redis-3.0.1]# make install

  安装完之后,可以执行以下make test,执行make test之前需要先安装tcl

[root@iZ944wsnvhcZ redis-3.0.1]# yum install tcl
[root@iZ944wsnvhcZ redis-3.0.1]# make test

 

3、配置 redis服务后台启动

[root@iZ944wsnvhcZ redis-3.0.1]# vi redis.conf 

  找到:

daemonize no

  修改为:

daemonize yes

 

4、启动redis服务器

[root@iZ944wsnvhcZ redis-3.0.1]# src/redis-server /usr/local/redis-3.0.1/redis.conf

 

5、进入命令行界面

[root@iZ944wsnvhcZ redis-3.0.1]# src/redis-cli 

 

6、关闭redis

[root@iZ944wsnvhcZ redis-3.0.1]# src/redis-cli shutdown

 

 

7、配置从redis

  redis.conf 配置文件添加 主redis的ip和端口

slaveof 192.169.0.7 6379

 

 

 

8、设置开机启动redis

  1)启动脚本 redis_init_script 位于 /usr/local/redis-3.0.1/utils/ 目录下

[root@iZ94lxgzm5yZ utils]# cat redis_init_script
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.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
        ;;
    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
[root@iZ94lxgzm5yZ utils]# 

  可以看到redis使用监听的端口作为配置文件的命名: CONF="/etc/redis/${REDISPORT}.conf"

  2)以端口号为名称将修改好的配置文件复制一份到指定目录

[root@iZ94lxgzm5yZ redis-3.0.1]# cp redis.conf  /etc/redis/6379.conf

  3)将启动脚本复制到/etc/init.d目录下,同时命名为redisd

[root@iZ94lxgzm5yZ utils]# cp redis_init_script /etc/init.d/redisd

  4)设置为开机启动

[root@iZ94lxgzm5yZ utils]# chkconfig redisd on
service redisd does not support chkconfig

  报错,解决方法,在启动脚本开头添加如下红色的两行注释以修改其运行级别:

[root@iZ94lxgzm5yZ utils]# vi /etc/init.d/redisd 
#!/bin/sh
# chkconfig:   2345 90 10
# description:  Redis is a persistent key-value database

  然后再设置开机启动

[root@iZ94lxgzm5yZ utils]# chkconfig redisd on

  5)启动redis

service redisd start

 

你可能感兴趣的:(安装Redis)