redis安装与配置

redis安装与配置

  • 安装

    cd /usr/local
    wget http://download.redis.io/redis-stable.tar.gz
    tar xvzf redis-stable.tar.gz
    ln -s redis-stable redis
    cd redis
    make
    cd src
    make install PREFIX=/usr/local/redis
    
  • 配置环境变量

    export REDIS_HOME=/usr/local/redis
    PATH=$PATH:$REDIS_HOME/bin
    
  • 配置redis.conf、开启远程访问

    • 修改 $REDIS_HOME/redis.conf文件
      • 注释掉所有: 127.0.0.1
      • 修改:protected-mode no
  • 创建管理脚本

    • 启动脚本 start-redis
      #!/bin/bash
      if [[ `ps -fe | grep redis | head -1 | awk '{print $8}' | rev | cut -c 1-12 | rev` == 'redis-server' ]]
      then
          echo 'the redis is running... ;you can restart or stop it'
      else
          $REDIS_HOME/bin/redis-server $REDIS_HOME/etc/redis.conf
          wait
      fi
      
    • 停止脚本 stop-redis
      #!/bin/bash
      if [[ `ps -fe | grep redis | head -1 | awk '{print $8}' | rev | cut -c 1-12 | rev` == 'redis-server' ]]
      then
          $REDIS_HOME/bin/redis-cli shutdown
          wait
      else
         echo 'the redis is not running;You do not need to stop it'
      fi
      
    • 重启脚本 restart-redis
      #!/bin/bash
      if [[ `ps -fe | grep redis | head -1 | awk '{print $8}' | rev | cut -c 1-12 | rev` == 'redis-server' ]]
      then
          $REDIS_HOME/bin/redis-cli shutdown
          wait
      fi
      $REDIS_HOME/bin/redis-server $REDIS_HOME/etc/redis.conf
      wait
      
  • 测试redis是否安装成功

    • 启动服务器
      start-redis
      
    • 启动客户端连接redis服务器
      redis-cli -h service -p 6379 -n 0
      

你可能感兴趣的:(redis)