Centos7 离线安装指定版本 redis + 一键部署脚本

1、本次安装redis7.0.11,官方网站 https://redis.io/download/

wget https://download.redis.io/releases/redis-7.0.11.tar.gz

2、安装gcc

yum install -y gcc

3、解压

tar zxvf redis-7.0.11.tar.gz -C /usr/local/

4、编译

cd /usr/local/redis-7.0.11/
make -j

5、安装

make install -j

 6、环境变量设置

PATH=$PATH:/usr/local/redis-7.0.11/src

7、copy配置文件

cp /usr/local/redis-7.0.11/redis.conf /etc/

8、修改配置

打开配置文件:vim /etc/redis.conf  
1.修改默认密码:查找 requirepass, 默认密码为 foobared, 将 foobared 修改为你的密码即可,在redis查询数据需要密码。注释requirepass在redis查询数据不需要密码。
2.找到 bind 127.0.0.1 将其注释,否则redis只允许本机连接
3.找到 protected-mode yes 将其改为:protected-mode no
4.找到dir ./ 修改数据存储目录
5.找到logfile "" 修改日志路径,注意加""
6.redis默认是rdb快照存储模式,找到appendonly可以根据需要配置yes开启aof文件仅追加模式

9、配置systemctl管理redis

vim /etc/systemd/system/redis.service
复制代码
[Unit]
Description=Redis
After=network.target

[Service]
PIDFile=/var/run/redis/redis-server.pid
ExecStart=/usr/local/redis-7.0.11/src/redis-server /etc/redis.conf
ExecStop=/usr/local/redis-7.0.11/src/redis-cli shutdown
Restart=always

[Install]
WantedBy=multi-user.target
复制代码

9、启动redis

systemctl daemon-reload
systemctl start redis

 

配置redis开启多线程(可选)

#设置io-threads-do-reads yes就可以开启io多线程
io-threads-do-reads yes

#设置io-threads 2
io-threads 2

 

一键部署脚本

vim deploy_redis.sh

 

复制代码
#/bin/bash

install_path=/usr/local

echo "下载"
wget https://download.redis.io/releases/redis-7.0.11.tar.gz
echo "安装gcc"
yum install -y gcc
echo "解压"
tar zxvf redis-7.0.11.tar.gz -C ${install_path}
echo "编译"
cd ${install_path}/redis-7.0.11/
make -j
echo "安装"
make install -j
echo "环境变量设置"
echo 'export PATH=$PATH:${install_path}/redis-7.0.11/src' | sudo tee -a /etc/profile > /dev/null
source /etc/profile
echo "copy配置文件"
cp /usr/local/redis-7.0.11/redis.conf /etc/
echo "修改配置"
sed -i 's/^protected-mode yes/protected-mode no/' /etc/redis.conf
sed -i 's/^bind 127.0.0.1/bind 0.0.0.0/' /etc/redis.conf
echo "配置systemctl管理redis"
cat <<EOF > /etc/systemd/system/redis.service
[Unit]
Description=Redis
After=network.target

[Service]
PIDFile=/var/run/redis/redis-server.pid
ExecStart=/usr/local/redis-7.0.11/src/redis-server /etc/redis.conf
ExecStop=/usr/local/redis-7.0.11/src/redis-cli shutdown
Restart=always

[Install]
WantedBy=multi-user.target
EOF

echo "启动redis"
systemctl daemon-reload
systemctl start redis
systemctl enable redis
复制代码

 

chmod a+x deploy_redis.sh
./deploy_redis.sh

 

posted @   苦逼yw  阅读(732)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示