CentOS7.2下安装Redis

1、切换到/usr/src 目录

如果你安装在别的目录,注意后面要一些路径也要修改,下载Redis,目前最新的是2.8.13版本

[[email protected] ~]# cd /usr/src
[[email protected] src]# wget http://download.redis.io/releases/redis-2.8.13.tar.gz

返回:

--2016-08-17 06:45:26--  http://download.redis.io/releases/redis-2.8.13.tar.gz
Resolving download.redis.io (download.redis.io)... 109.74.203.151
Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1227538 (1.2M) [application/x-gzip]
Saving to: ‘redis-2.8.13.tar.gz’

100%[======================================>] 1,227,538   47.8KB/s   in 30s    

2016-08-17 06:45:57 (40.5 KB/s) - ‘redis-2.8.13.tar.gz’ saved [1227538/1227538]

2、解压,切换目录到redis-2.8.13

[[email protected] src]# tar xzf redis-2.8.13.tar.gz
[[email protected] src]# cd redis-2.8.13
[[email protected] redis-2.8.13]# 

3、编译

[[email protected] redis-2.8.13]# make

返回:

...
Hint: To run 'make test' is a good idea ;)

make[1]: Leaving directory `/usr/src/redis-2.8.13/src'

4、编译安装

[[email protected] redis-2.8.13]# make

返回:

cd src && make install
make[1]: Entering directory `/usr/src/redis-2.8.13/src'

Hint: To run 'make test' is a good idea ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
make[1]: Leaving directory `/usr/src/redis-2.8.13/src'

5、打开redis.conf 修改配置文件

最关键是下面几行,其他的设置参考官方文档:

daemonize yes
loglevel notice
logfile /var/log/redis.log
dir ./

6、设置系统的overcommit_memory,执行

vi /etc/sysctl.conf

在文件中添加一行,保存:

vm.overcommit_memory = 1

执行:

sysctl vm.overcommit_memory=1

7、添加启动脚本,执行:

vi /etc/init.d/redis

写入下面的代码,保存:

#!/bin/sh
#
# redis        Startup script for Redis Server
#
# chkconfig: - 90 10
# description: Redis is an open source, advanced key-value store. 
#
# processname: redis-server
# config: /etc/redis.conf
# pidfile: /var/run/redis.pid
 
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
 
PIDFILE=/var/run/redis.pid
CONF="/usr/src/redis-2.8.13/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

8、设置权限和开机启动:

chmod +x /etc/init.d/redis
chkconfig --add redis
chkconfig redis on

启动redis使用service redis start 或者/etc/init.d/redis start ,停止redis的命令service redis stop 或者/etc/init.d/redis stop 。

windows下安装使用redis可以参考:WordPress使用Redis缓存加速|511遇见强烈推荐


发布日期:

所属分类: Linux/Centos/Os 标签: