Linux环境安装Redis自动化脚本

小柒博客 评论91,521字数 284阅读0分56秒阅读模式

此脚本是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
微信扫一扫,加我!
weinxin
微信号已复制
微信公众号
微信扫一扫,关注我!
weinxin
公众号已复制
Shell最后更新:2024-1-24
小柒博客
  • 本文由 小柒博客 发表于 2020年4月7日 16:37:39
  • 声明:本站所有文章,如无特殊说明或标注,本站文章均为原创。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。转载请务必保留本文链接:https://www.yangxingzhen.com/6686.html
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

拖动滑块以完成验证