Redis源码安装脚本

Redis 源码安装脚本

系统环境:CentOS 7.4 软件版本:7.3.7

[root@localhost ~]# cat auto_install_redis.sh

#!/usr/bin/env bash
# 2020-3-13 11:13:18
# Author: ^~^
# Auto Install Redis Server
 
#Define Redis path variables
REDIS_URL=http://download.redis.io/releases
REDIS_FILE=redis-5.0.7.tar.gz
REDIS_FILE_DIR=redis-5.0.7
REDIS_PREFIX=/usr/local/redis
 
#Install Redis
if [ ! -d  ${REDIS_PREFIX} ];then
    yum -y install wget gcc gcc-c++
    wget -c ${REDIS_URL}/${REDIS_FILE}
    tar zxf ${REDIS_FILE}
    mv ${REDIS_FILE_DIR} ${REDIS_PREFIX}
    cd ${REDIS_PREFIX} && make
    if [ $? -eq 0 ];then
        echo -e "\033[32mThe Redis Install Success...\033[0m"
    else
        echo -e "\033[31mThe Redis Install Failed...\033[0m"
    fi
else
    echo -e "\033[31mThe Redis has been installed...\033[0m"
    exit 1
fi
 
#Config Redis
ln -sf ${REDIS_PREFIX}/src/redis-* /usr/bin
sed -i "s/127.0.0.1/0.0.0.0/g" ${REDIS_PREFIX}/redis.conf
sed -i "/daemonize/s/no/yes/" ${REDIS_PREFIX}/redis.conf
sed -i "s/dir .*/dir \/data\/redis/" ${REDIS_PREFIX}/redis.conf
sed -i "s/logfile .*/logfile \/usr\/local\/redis\/redis.log/" ${REDIS_PREFIX}/redis.conf
sed -i '/appendonly/s/no/yes/' ${REDIS_PREFIX}/redis.conf
echo never > /sys/kernel/mm/transparent_hugepage/enabled
sysctl vm.overcommit_memory=1
 
#Create data directory And Start Redis
mkdir -p /data/redis
redis-server ${REDIS_PREFIX}/redis.conf
 
#Add power on self start
grep -qw "${REDIS_PREFIX}" /etc/rc.d/rc.local
if [ $? -ne 0 ];then
    echo "redis-server ${REDIS_PREFIX}/redis.conf" >>/etc/rc.d/rc.local
    chmod +x /etc/rc.d/rc.local
fi

Last updated