当前位置:网站首页>Shell之一键自动部署Redis任意版本
Shell之一键自动部署Redis任意版本
2022-07-01 04:33:00 【Moshow郑锴】
脚本用法:chmod 755 redis-install.sh && sh redis-install.sh {version} (后面 {version}的是你需要的版本号,需要什么版本就写什么版本),我这里安装的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 http://download.redis.io/releases/redis-${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 * soft nofile 65535 * hard nofile 65535 EOF
#Redis编译安装
cd /usr/local/src
tar -zxvf redis-${version}.tar.gz
cd /usr/local/src/redis-${version}
make
make PREFIX=/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


到这里整改自动安装脚本已成功执行完毕,我们可以收到通过ps –ef|grep redis来查看服务状态以及监听端口。
登陆redis,执行简单的语句:
边栏推荐
- PgSQL failed to start after installation
- CUDA development and debugging tool
- Spock单元测试框架介绍及在美团优选的实践___第一章
- LM小型可编程控制器软件(基于CoDeSys)笔记二十:plc通过驱动器控制步进电机
- [Master / slave] router election in DD message
- js 图片路径转换base64格式
- This may be your last chance to join Tencent
- Obtain detailed ideas for ABCDEF questions of 2022 American Games
- Offline installation of Wireshark 2.6.10
- JS rotation chart
猜你喜欢

【LeetCode】100. Same tree

2022 G2 power station boiler stoker examination question bank and G2 power station boiler stoker simulation examination question bank

尺取法:有效三角形的个数

JMeter learning notes 2 - brief introduction to graphical interface
![[godot] unity's animator is different from Godot's animplayer](/img/51/48f40a7b6736d7f78040eabbbd3395.jpg)
[godot] unity's animator is different from Godot's animplayer

Question bank and online simulation examination for special operation certificate of G1 industrial boiler stoker in 2022

2022 Shanghai safety officer C certificate examination question simulation examination question bank and answers

TCP server communication flow

2022 gas examination question bank and online simulation examination

LM小型可编程控制器软件(基于CoDeSys)笔记二十:plc通过驱动器控制步进电机
随机推荐
使用WinMTR软件简单分析跟踪检测网络路由情况
[untitled]
Simple implementation of slf4j
嵌入式系統開發筆記80:應用Qt Designer進行主界面設計
一些小知识点
TASK04|數理統計
The junior college students were angry for 32 days, four rounds of interviews, five hours of soul torture, and won Ali's offer with tears
slf4j 简单实现
嵌入式系统开发笔记79:为什么要获取本机网卡IP地址
Internet winter, how to spend three months to make a comeback
采购数智化爆发在即,支出宝'3+2'体系助力企业打造核心竞争优势
离线安装wireshark2.6.10
嵌入式系统开发笔记80:应用Qt Designer进行主界面设计
2022 t elevator repair new version test questions and t elevator repair simulation test question bank
Knowledge supplement: redis' basic data types and corresponding commands
Dual contractual learning: text classification via label aware data augmentation reading notes
[send email with error] 535 error:authentication failed
Daily algorithm & interview questions, 28 days of special training in large factories - the 13th day (array)
为什么香港服务器最适合海外建站使用
283. move zero