51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

Linux环境安装Redis自动化脚本

此脚本是Redis安装脚本,有需要朋友可以参考,脚本内容如下:

系统环境:CentOS 7.9

软件版本:5.0.7

[root@localhost ~]# vim auto_install_redis.sh

#!/bin/bash
#2020-3-13 11:13:18
#BY:YangXingZhen
#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


脚本执行方式:

[root@localhost ~]# sh auto_install_redis.sh
继续阅读 Shell最后更新:2024-1-24

赞(0)
未经允许不得转载:工具盒子 » Linux环境安装Redis自动化脚本