redis下载与安装

redis下载与安装

  1. redis下载地址:https://github.com/redis/redis/archive/7.0.5.tar.gz

  2. 解压:tar -zxvf redis-7.0.5.tar.gz

  3. 编译:

    	make  
    	#需要有gcc支持,否则会编译失败 
    
  4. 清除编译:

    	make distclean
    	#make失败后重新make的时候之前用一下
    	make 
    
  5. 安装:make PREFIX=/opt/redis7 install

安装redis服务

  • 前置,配置环境变量

    1. 打开环境配置: vi /etc/profile
    2. 在环境配置文件中最后追加:
    	export REDIS_HOME=/opt/redis7
    	export PATH=$PATH:$REDIS_HOME/bin	
    
    1. 让配置生效:source /etc/profile

    2. 查看环境变量PATH:echo $PATH

      配置完环境变量redis命令可以在任意目录执行了

  • 安装

    1. 进入redis安装根目录utils下:cd utils

    2. 执行install_server.sh 命令: ./install_server.sh

      	这个地方可能会报错
      	
      	vi install_server.sh
      	注释掉下面几行
      
      	#_pid_1_exe="$(readlink -f /proc/1/exe)"
      	
      	#if [ "${_pid_1_exe##*/}" = systemd ]
      	
      	#then
      
      	# echo "This systems seems to use systemd."
      	
      	# echo "Please take...them. Sorry!"
      	
      	# exit 1
      	
      	#fi
      
      	保存退出,即可解决问题
      
      	继续执行 ./install_server.sh
      
      	Please ...port for this instance: [6379] 
      	让我们选择端口号,我们选择默认,回车继续...	    	
      	
      	Copied /tmp/6379.conf => /etc/init.d/redis_6379
      	Installing service...
      	Successfully added to chkconfig!
      	Successfully added to runlevels 345!
      	Starting Redis server...
      	Installation successful!
      	
      	完成后会在/etc/init.d/下生成一个redis_6379可执行文件。
      	
      
      
    3. redis_6379文件内容如下

      #!/bin/sh
      #Configurations injected by install_server below....
      
      EXEC=/opt/redis7/bin/redis-server
      CLIEXEC=/opt/redis7/bin/redis-cli
      PIDFILE=/var/run/redis_6379.pid
      CONF="/etc/redis/6379.conf"
      REDISPORT="6379"
      ###############
      # SysV Init Information
      # chkconfig: - 58 74
      # description: redis_6379 is the redis daemon.
      ### BEGIN INIT INFO
      # Provides: redis_6379
      # Required-Start: $network $local_fs $remote_fs
      # Required-Stop: $network $local_fs $remote_fs
      # Default-Start: 2 3 4 5
      # Default-Stop: 0 1 6
      # Should-Start: $syslog $named
      # Should-Stop: $syslog $named
      # Short-Description: start and stop redis_6379
      # Description: Redis daemon
      ### END INIT INFO
      
      
      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
              ;;
          status)
              PID=$(cat $PIDFILE)
              if [ ! -x /proc/${PID} ]
              then
                  echo 'Redis is not running'
              else
                  echo "Redis is running ($PID)"
              fi
              ;;
          restart)
              $0 stop
              $0 start
              ;;
          *)
          echo "Please use start, stop, restart or status as first argument"
          ;;
      esac
      
    4. 执行开启redis只需要执行service redis_6379 start …

你可能感兴趣的:(redis,redis,linux,数据库)