此脚本是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
若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!如本文“对您有用”,欢迎随意打赏,谢谢!
继续阅读
Wechat
微信扫一扫,加我!
微信号已复制
微信公众号
微信扫一扫,关注我!
公众号已复制
评论