一键自动部署Redis的任意版本脚本分享(超实用)

今天给大家分享一个超级实用的脚本,一键自动安装部署Redis的任意版本,记住是任意版本哦!
脚本用法:chmod 755 redis-install.sh && sh redis-install.sh 4.0.10 (后面跟的是你需要的版本号,需要什么版本就写什么版本),我这里安装的4.0.10
具体脚本内容如下展示:
#! /usr/bin/bash
##redis任何版本全程自动化源码编译安装
##用法: sh redis-install.sh 4.0.10 (后面跟的是你需要的版本号,需要什么版本就写什么版本),我这里安装的4.0.10
version=$1
usage(){
echo "usage: $0 version"
}
if [ $# -ne 1 ]
then
usage
exit -1
fi
#Redis安装包下载
cd /usr/local/src
if [ ! -f redis-${version}.tar.gz ]
then
curl -o /usr/local/src/redis-${version}.tar.gz ${version}.tar.gz
fi
#Redis依赖包安装
yum clean all
yum makecache fast
yum -y install gcc gcc-c++ tcl
#编译Redis所需要的gcc
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
source /opt/rh/devtoolset-9/enable
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
gcc --version
##内系统参数核优化
cat >> /etc/rc.d/rc.local << "EOF"
##关闭Linux的THP(内存管理系统)通过使用更大的内存页面,来减少具有大量内存的计算机上的TLB的开销
if [ -f /sys/kernel/mm/transparent_hugepage/enabled ]
then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if [ -f /sys/kernel/mm/transparent_hugepage/defrag ]
then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
EOF
chmod u+x /etc/rc.d/rc.local
if [ -f /sys/kernel/mm/transparent_hugepage/enabled ]
then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if [ -f /sys/kernel/mm/transparent_hugepage/defrag ]
then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
cat >> /etc/sysctl.conf << "EOF"
#Linux系统内核参数优化
net.core.somaxconn = 2048
net.ipv4.tcp_max_syn_backlog = 2048
vm.overcommit_memory = 1
EOF
sysctl -p
cat > /etc/security/limits.conf << "EOF"
root soft nofile 65535
root hard nofile 65535
IT之家 soft nofile 65535
IT之家 hard nofile 65535
EOF
#Redis编译安装
cd /usr/local/src
tar -zxvf redis-${version}.tar.gz
cd /usr/local/src/redis-${version}
make
make PREFIX=http://www.ym97.com/usr/local/redis install
#Redis基础配置
mkdir -p /usr/local/redis/{etc,logs,data}
egrep -v "^$|^#" /usr/local/src/redis-${version}/redis.conf > /usr/local/redis/etc/redis.conf
#sed -i "s/bind 127.0.0.1/bind 0.0.0.0/g" /usr/local/redis/etc/redis.conf
sed -i "s/protected-mode yes/protected-mode no/g" /usr/local/redis/etc/redis.conf
sed -i "s/daemonize no/daemonize yes/g" /usr/local/redis/etc/redis.conf
sed -i "s/pidfile \/var\/run\/redis_6379.pid/pidfile \/usr\/local\/redis\/redis.pid/g" /usr/local/redis/etc/redis.conf
sed -i "s/dir \.\//dir \/usr\/local\/redis\/data/g" /usr/local/redis/etc/redis.conf
sed -i "s/logfile \"\"/logfile \"\/usr\/local\/redis\/logs\/redis.log\"/g" /usr/local/redis/etc/redis.conf
sed -i "s/dbfilename dump.rdb/dbfilename dump.rdb/g" /usr/local/redis/etc/redis.conf
sed -i "s/appendfilename \"appendonly.aof\"/appendfilename \"appendonly.aof\"/g" /usr/local/redis/etc/redis.conf
#PATH配置
echo "export PATH=${PATH}:/usr/local/redis/bin" >>/etc/profile
source /etc/profile
#启动redis服务
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
#查看redis监听端口
netstat -tanp|grep redis
执行脚本后开始自动安装redis4.0.10

自动安装Redis4.0.10所需要的的依赖包,如下图所示:

自动开始解压:

开始自动make

开始自动make install

安装完成,Redis服务已成功启动:

到这里整改自动安装脚本已成功执行完毕,我们可以收到通过ps –ef|grep redis来查看服务状态以及监听端口。
登陆redis,执行简单的语句:

原文地址:https://www.toutiao.com/i6906374379522015747/
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/sql/redis/8748.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
详解Redis的慢查询日志
时间:2020-12-28
-
如何高效使用Redis作为LR
时间:2020-12-28
-
WINDOWS中REDIS主从配置实现
时间:2020-12-28
-
redis单线程快的原因和原理
时间:2020-12-25
-
Windows操作系统下Redis服务
时间:2020-12-25
-
Windows下Redis安装配置简单
时间:2020-12-25
-
Redis安装教程图解
时间:2020-12-25
-
Windows下Redis的安装使用教
时间:2020-12-25
热门文章
-
Redis的8大数据类型,写得非常好!
时间:2020-12-25
-
Redis总结笔记(一):安装和常用命令
时间:2020-12-25
-
一键自动部署Redis的任意版本脚本分享(超
时间:2020-12-25
-
败家玩意儿!Redis 竟然浪费了这么多内存
时间:2020-12-25
-
Windows下Redis的安装使用教程
时间:2020-12-25
-
redis单线程快的原因和原理
时间:2020-12-25
-
WINDOWS中REDIS主从配置实现代码解析
时间:2020-12-28
-
Redis,就是这么朴实无华
时间:2020-12-25
-
Windows下Redis安装配置简单教程
时间:2020-12-25
-
Windows操作系统下Redis服务安装图文教程
时间:2020-12-25
