deles 发表于 2018-5-21 07:04:14

Linux安装Redis服务

  

  tar xf /home/source/redis-3.0.6.tar.gz

  cd redis-3.0.6
  make PREFIX=/usr/local/redis install
  mkdir /etc/redis
  /bin/cp -f redis.conf /etc/redis/redis.conf
  sed -i 's@^daemonize no@daemonize yes@'    /etc/redis/redis.conf
  

  

  redis服务脚本
  #!/bin/sh
  #
  # chkconfig : 2345 45 90
  # as it does use of the /proc filesystem.
  
REDISPORT=6379
  EXEC=/usr/local/redis/bin/redis-server
  CLIEXEC=/usr/local/redis/bin/redis-cli
  
PIDFILE=/var/run/redis.pid
  CONF="/etc/redis/redis.conf"

  

  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
  }

  
case "$1" in
  start)
  start
  ;;
  stop)
  stop
  ;;
  restart)
  stop
  start
  ;;
  *)
  echo "Please use start or stop as first argument"
  ;;
  esac
  

  启动redis
  # /etc/init.d/redis start
  连接redis

  # /usr/local/redis/bin/redis-cli -h 127.0.0.1
127.0.0.1:6379>

  获取redis中所有的key
  127.0.0.1:6379> keys *

  

  

  

  

  

  
页: [1]
查看完整版本: Linux安装Redis服务