Redis3.0.7安裝

1、安裝redis

   環境:centos7/redis3.0.7(其它版本安裝方法一致)java

#mkdir /usr/local/redis

進入此文件夾,解壓官網下載的redis-3.0.7.tar.gz 或是使用下面命令在線下載,redis

wget http://download.redis.io/releases/redis-3.0.7.tar.gz
#tar -zxvf redis-3.0.7.tar.gz(解壓)
#make(編譯,編譯結束後src文件夾下會多出redis-server,redis-cli等腳本)

測試一下:數據庫

[root@ser211 redis]# ./usr/local/redis/src/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 po

此時redis安裝成功。centos

2、配置redis並添加到服務

將/usr/local/redis/utils/redis_init_script腳本拷貝到/etc/init.d/redisruby

cp -r /usr/local/redis/redis-3.0.7/utils/redis_init_script /etc/init.d
mv redis_init_script redis(將redis_init_script重命名爲redis)

打開腳本並修改爲下面這樣:測試

#!/bin/sh  
#chkconfig: 2345 80 90  (加了這一行是後面要把redis添加成系統服務的標識,不加的話後面會報服務 redis 不支持 chkconfig)
# 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.pid (保持跟conf裏面的pid一張,否則開和關pid不同,會出現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,並作以下修改:this

daemonize yes //由no改成yes,之後臺方式運行  
dir /var/redis/6379 //配置數據庫文件存放目錄

最後將redis添加爲服務:centos7

#  chkconfig --add redis

測試:spa

# service redis start
Starting Redis server...

打開客戶端:code

[root@run]# service redis start
Starting Redis server...
[root@run]# redis-cli
127.0.0.1:6379> set hi hello
OK
127.0.0.1:6379> get hi
"hello"
127.0.0.1:6379>

關閉:

[root@run]# service redis stop
Stopping ...
Redis stopped

到此安裝配置完成

相關文章
相關標籤/搜索