me小怪兽

导航

redis安装脚本

gcc等依赖包已封装在redis-5.0.10.tar.gz中,下载地址

链接:https://pan.baidu.com/s/1IWzy6DDq1xb_mrZjtfSBSA
提取码:rgjk

 

注: 将redis_install.sh和redis-5.0.10.tar.gz放在同一路径下

vim redis_install.sh  添加安装工具

#!/bin/bash
# -*- codeing = utf-8 -*-
# @Time : 2021/11/7 22:11
# @Author : xiaoguaishou
# @File : redis_install.sh
# @Software : PyCharm

#1.设置redis安装目录
redis_install=/app
#2.设置redis端口
redis_port=20002
#3.设置redis版本号
redis_version=redis-5.0.10
#解压安装包
tar -zxvf $redis_version.tar.gz -C $redis_install
sleep 3
mv $redis_install/$redis_version $redis_install/redis
cd $redis_install/redis

#创建redis数据存放,日志目录
mkdir {data,logs}
#安装离线gcc依赖
rpm -ivh gcc/*.rpm --nodeps --force
sleep 5
#安装redis
make -j 4
sleep 5
make install
sleep 5
#127.0.0.1允许本地连接,0.0.0.0允许所有连接
sed -i 's/^bind 127.0.0.1/bind 0.0.0.0/g' $redis_install/redis/redis.conf
#使用yes后台运行
sed -i 's/daemonize no/daemonize yes/g' $redis_install/redis/redis.conf
#将yes改为no,开启远程连接
sed -i 's/protected-mode yes/protected-mode no/g' $redis_install/redis/redis.conf
#修改密码
sed -i 's/# requirepass foobared/requirepass XLxu!R1UFg6sDQfYa/g' $redis_install/redis/redis.conf
#设置log输出目录,必须绝对路径(sed不支持变量)
sed -i '/logfile/c\logfile "/app/redis/logs/redis.log"' $redis_install/redis/redis.conf
#设置数据存放的目录,必须绝对路径(sed不支持变量)
sed -i '/dir .\//c\dir /app/redis/data' $redis_install/redis/redis.conf
#修改连接端口(sed不支持变量)
sed -i 's/port 6379/port 20002/g' $redis_install/redis/redis.conf
sleep 5
echo '
[Unit]
Description=Redis
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/app/redis/src/redis-server /app/redis/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
' > /usr/lib/systemd/system/redis-server.service
#启动redis
systemctl daemon-reload
systemctl start redis-server.service
systemctl enable redis-server.service
systemctl status redis-server.service
sleep 5
#检查redis是否启动成功
ss -antlp |grep $redis_port
if [ $? -eq 0 ];then
echo "redis部署成功,密码:XLxu!R1UFg6sDQfYa"
echo "redis部署成功,密码:XLxu!R1UFg6sDQfYa"
else
echo "redis部署失败"
echo "redis部署失败"
fi
firewall-cmd --zone=public --add-port=$redis_port/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-port

 

#开始安装redis

[root@localhost]# chmod +x redis_install.sh  #授权

[root@localhost]#  ./redis_install.sh      #执行安装

 

posted on 2022-08-21 23:01  me小怪兽  阅读(169)  评论(0编辑  收藏  举报