当前位置:网站首页>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,执行简单的语句:
边栏推荐
- C language games (I) -- guessing games
- Hololens2 development environment building and deploying apps
- All in all, the low code still needs to solve these four problems
- Registration for R2 mobile pressure vessel filling test in 2022 and R2 mobile pressure vessel filling free test questions
- 跳槽一次涨8k,5年跳了3次...
- MySQL function variable stored procedure
- CUDA development and debugging tool
- ThreeJS开篇
- Maixll dock quick start
- JS image path conversion Base64 format
猜你喜欢

It's settled! 2022 JD cloud summit of JD global technology Explorer conference see you in Beijing on July 13

Threejs opening

【LeetCode】100. Same tree

2022危险化学品生产单位安全生产管理人员题库及答案

【发送邮件报错】535 Error:authentication failed

"Target detection" + "visual understanding" realizes the understanding of the input image

分账技术赋能农贸市场,重塑交易管理服务效能

slf4j 简单实现

25.k sets of flipped linked lists

After many job hopping, the monthly salary is equal to the annual salary of old colleagues
随机推荐
Custom components in applets
2022 hoisting machinery command registration examination and hoisting machinery command examination registration
TASK04|數理統計
What is uid? What is auth? What is a verifier?
Browser top loading (from Zhihu)
Recommend the best product development process in the Internet industry!
Why is Hong Kong server most suitable for overseas website construction
Advanced application of ES6 modular and asynchronous programming
2022 polymerization process test questions and simulation test
尺取法:有效三角形的个数
【发送邮件报错】535 Error:authentication failed
(12) Somersault cloud case (navigation bar highlights follow)
Codeforces Round #721 (Div. 2)B1. Palindrome Game (easy version)B2. Palindrome game (hard version)
Account sharing technology enables the farmers' market and reshapes the efficiency of transaction management services
Embedded System Development Notes 80: using QT designer to design the main interface
2022.2.7-2.13 AI industry weekly (issue 84): family responsibilities
[leetcode skimming] February summary (updating)
js 图片路径转换base64格式
Concurrent mode of different performance testing tools
嵌入式系统开发笔记81:使用Dialog组件设计提示对话框