使用说明

source install_redis.sh

install_redis.sh接收$1参数,可指定安装路径,默认安装路径为/usr/local

install_redis.sh

#!/bin/bash

directory=$1
current_dir=`pwd`

function select_installation_directory(){
  if [[ -z ${directory} ]];
  then
    directory='/usr/local'
  fi
}

function check_gcc(){
  if [[ -z $(rpm -qa | grep ^gcc | grep -v grep) ]];
  then
    cd gcc && rpm -Uvh *.rpm --nodeps --force && cd ..
  fi
}

function install_redis(){
  tar -zxvf "${current_dir}"/redis-5.0.3.tar.gz
  cd redis-5.0.3 && make install PREFIX=${directory}/redis
  cp "${current_dir}"/redis-5.0.3/redis.conf ${directory}/redis/bin/
  sed -i 's/^daemonize no/daemonize yes/g' ${directory}/redis/bin/redis.conf
  sed -i 's/^protected-mode yes/protected-mode no/g' ${directory}/redis/bin/redis.conf
  sed -i 's/^bind 127.0.0.1/# bind 127.0.0.1/g' ${directory}/redis/bin/redis.conf
  #${directory}/redis/bin/redis-server ${directory}/redis/bin/redis.conf
}

function install_redis(){
  tar -zxvf "${current_dir}"/redis-5.0.3.tar.gz
  cd redis-5.0.3 && make install PREFIX=${directory}/redis
  cp "${current_dir}"/redis-5.0.3/redis.conf ${directory}/redis/bin/
  sed -i 's/^daemonize no/daemonize yes/g' ${directory}/redis/bin/redis.conf
  sed -i 's/^protected-mode yes/protected-mode no/g' ${directory}/redis/bin/redis.conf
  sed -i 's/^bind 127.0.0.1/# bind 127.0.0.1/g' ${directory}/redis/bin/redis.conf
  #${directory}/redis/bin/redis-server ${directory}/redis/bin/redis.conf
}

function powered_up_redis(){
  sed -i "s:^EXEC=/usr/local/bin/redis-server:EXEC=${directory}/redis/bin/redis-server:g" ./utils/redis_init_script
  sed -i "s:^CLIEXEC=/usr/local/bin/redis-cli:CLIEXEC=${directory}/redis/bin/redis-cli:g" ./utils/redis_init_script
  sed -i  "$(sed -n '/^CONF=/=' ./utils/redis_init_script)a  CONF=${directory}/redis/bin/redis.conf" ./utils/redis_init_script
  cp ./utils/redis_init_script /etc/init.d/redis
  service redis start
  chkconfig redis on
  cd ..
}

function Main(){
  select_installation_directory;
  check_gcc;
  install_redis;
  powered_up_redis;
}
Main;

资源下载

https://www.sky12580.cn/upload/2022/04/redis.zip