`

Linux上安装Redis-3.0.7详细过程

阅读更多

第一部分:安装redis 

      安装环境:系统centos 6.4 

      安装目录:

/usr/local/redis

     首先到Redis官网下载安装包,或者直接使用如下命令下载:

wget http://download.redis.io/releases/redis-3.0.7.tar.gz

    解压到安装目录后执行 make命令:

 

 

[root@ser211 local]# tar -vxzf redis-3.0.7.tar.gz
[root@ser211 redis]# make

    测试是否安装成功,执行一下命令:

   

[root@ser211 redis]# ./usr/local/redis/src/redis-server
[root@ser211 init.d]# redis-server 
1074:C 03 Feb 16:34:16.941 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1074:M 03 Feb 16:34:16.943 * Increased maximum number of open files to 10032 (it was originally set to 1024).
1074:M 03 Feb 16:34:16.943 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now.
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.0.7 (00000000/0) 32 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 1074
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

1074:M 03 Feb 16:34:16.944 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1074:M 03 Feb 16:34:16.944 # Server started, Redis version 3.0.7
1074:M 03 Feb 16:34:16.944 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1074:M 03 Feb 16:34:16.944 * The server is now ready to accept connections on port 6379

   到这步,Redis安装成功!

第二部分:配置redis并添加到服务 

     将/usr/local/redis/utils/redis_init_script脚本拷贝到/etc/init.d/redis

    

[root@ser211 init.d]# cp /usr/local/redis/utils/redis_init_script /etc/init.d/redis

    将脚本文件做如下修改:

#!/bin/sh
#chkconfig: 2345 80 90
# 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

   根据脚本文件中的配置,创建数据目录/var/redis/6379,将redis-server、redis-cli移动到/usr/local/bin下,将/usr/local/redis/redis.conf移动到/etc/redis/6379.conf,并做如下修改:

daemonize yes //由no改为yes,以后台方式运行
dir /var/redis/6379 //配置数据库文件存放目录

 最后将redis添加为服务:

[root@ser211 init.d]#  chkconfig --add redis
[root@ser211 redis]# service redis start
Starting Redis server...
[root@ser211 redis]# redis-cli
127.0.0.1:6379> get a 
"1"
127.0.0.1:6379> 
[root@ser211 init.d]# service redis stop
Stopping ...
Redis stopped

   好了,配置完成!!!

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics