leonheart 发表于 2018-11-4 10:35:03

redis2.8安装小试

  安装环境:
  CentOS 6.5
  Redis redis-2.8.13
  下载安装:
  1、切换至/usr/local/src/目录下:
  # cd /usr/local/src
  下载源码包:
  # wget http://download.redis.io/releases/redis-2.8.23.tar.gz
  2、解压:
  # tar xf redis-2.8.23.tar.gz
  3、切换至redis-2.8.23目录下:
  # cd redis-2.8.23
  4、安装redis至/usr/local/redis目录:
  # make PREFIX=/usr/local/redis install
  5、为redis提供SysV init脚本:
  # vim /etc/rc.d/init.d/redis
  #!/bin/sh
  # chkconfig: 2345 83 93
  # Simple Redis init.d script conceived to work on Linuxsystems
  # as it does use of the /proc filesystem.
  #
  # Simple Redis init.d script conceived to work on Linuxsystems
  # 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"
  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 startor stop as first argument"
  ;;
  esac
  6、给脚本赋予执行权限:
  # chmod u+x /etc/rc.d/init.d/redis
  7、添加至服务管理列表,并让其开机自动启动:
  # chkconfig --add /etc/rc.d/init.d/redis
  # chkconfig redis on
  8、创建redis持久化文件存放目录
  mkdir -pv /var/redis/data
  9、创建配置文件存放目录
  # mkdir /etc/redis
  10、提供配置文件
  # cp/usr/local/src/redis-2.8.23/redis.conf /etc/redis/
  11、编辑配置文件更改以下选项为如下值
  # vim /etc/redis/redis.conf
  daemonizeyes                              #使Redis以守护进程模式运行
  dir/var/redis/data                           #设置持久化文件存放位置,路径可自定义
  12、启动服务
  # service redis start
  13、检查服务端口
  # netstat -tunl | grep 6379
  tcp      0      00.0.0.0:6379                0.0.0.0:*                  LISTEN
  14、修改PATH环境变量,让系统可以直接使用redis的相关命令:
  # echo 'exportPATH=/usr/local/redis/bin:$PATH' > /etc/profile.d/redis.sh
  # source /etc/profile.d/redis.sh
  15、使用redis客户端工具连上redis进行测试:
  # redis-cli
  127.0.0.1:6379> set hello world
  OK
  127.0.0.1:6379>
  127.0.0.1:6379> get hello
  "world"
  127.0.0.1:6379> quit
  #
  到此Redis的安装测试已经完成。

页: [1]
查看完整版本: redis2.8安装小试