Redis如何一键部署脚本

先将安装包拖入/opt目录

在这里插入图片描述

注意:这里的脚本bind修改后为 0.0.0.0

bind修改后为bind 127.0.0.1 +服务器IP在下面

#!/bin/bash#yum源echo -e "\033[31m =====正在验证当前为仅主机还是NAT模式===== \033[0m"ping -c1 -W1 www.baidu.com &> /dev/nullif [ $? -eq 0 ];then echo -e "\033[31m 检测当前为NAT模式,为您配置在线yum源 \033[0m"mkdir -p /etc/yum.repos.d/repo.bakmv -f /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak &> /dev/nullwget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo &> /dev/nullyum clean all &> /dev/nullyum list &> /dev/nullecho -e "\033[31m 在线源已配置完成 \033[0m"elseecho -e "\033[31m 检测当前为仅主机模式,为您配置本地yum源 \033[0m"mount /dev/sr0 /mnt &> /dev/nullcd /etc/yum.repos.d/mkdir -p /etc/yum.repos.d/repo.bakmv -f /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak &> /dev/nullecho '[local]name=localbaseurl=file:///mntenabled=1gpgcheck=0' > /etc/yum.repos.d/local.repoyum clean all &> /dev/nullyum makecache &> /dev/nulldf -h | grep "/mnt" if [ $? -ne 0 ];thenecho -e "\033[31m 检测当前为仅主机模式,但光盘未连接! \033[0m"elseecho -e "\033[31m 本地yum源已配置完成 \033[0m"fifi#关闭防火墙systemctl stop firewalldsetenforce 0yum install -y gcc gcc-c++ makerpm -q expectrpm -q tclyum -y install expectcd /opttar zxvf redis-5.0.7.tar.gz -C /opt/cd /opt/redis-5.0.7/makemake PREFIX=/usr/local/redis install#由于Redis源码包中直接提供了Makefile 文件,所以在解压完软件包后,不用先执行./configure进行配置,可直接执行make与make install 命令进行安装。#在/utils里执行软件包提供的install_server.sh脚本文件设置Redis服务所需要的相关配置文件cd /opt/redis-5.0.7/utils#开始免交换执行/usr/bin/expect <<EOF#expect开始标志spawn ./install_server.sh#Please select the redis port for this instance: [6379]expect "instance"send "\r" #Please select the redis config file name [/etc/redis/6379.conf] expect "config"send "\r"#Please select the redis log file name [/var/log/redis_6379.log]expect "log"send "\r"#Please select the data directory for this instance [/var/lib/redis/6379]expect "data"send "\r"#Please select the redis executable path []expect "executable"send "/usr/local/redis/bin/redis-server\r"#Is this ok? Then press ENTER to go on or Ctrl-C to abort.expect "abort"send "\r"expect eofEOFln -s /usr/local/redis/bin/* /usr/local/bin/netstat -natp | grep redis/etc/init.d/redis_6379 restart     /etc/init.d/redis_6379 status   sed -i '/bind 127.0.0.1/c bind 0.0.0.0' /etc/redis/6379.confsed -i 's/appendonly no/appendonly yes/' /etc/redis/6379.conf/etc/init.d/redis_6379 restart/etc/init.d/redis_6379 status  

bind修改后为bind 127.0.0.1 +服务器IP脚本

#!/bin/bash#yum源echo -e "\033[31m =====正在验证当前为仅主机还是NAT模式===== \033[0m"ping -c1 -W1 www.baidu.com &> /dev/nullif [ $? -eq 0 ];then echo -e "\033[31m 检测当前为NAT模式,为您配置在线yum源 \033[0m"mkdir -p /etc/yum.repos.d/repo.bakmv -f /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak &> /dev/nullwget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo &> /dev/nullyum clean all &> /dev/nullyum list &> /dev/nullecho -e "\033[31m 在线源已配置完成 \033[0m"elseecho -e "\033[31m 检测当前为仅主机模式,为您配置本地yum源 \033[0m"mount /dev/sr0 /mnt &> /dev/nullcd /etc/yum.repos.d/mkdir -p /etc/yum.repos.d/repo.bakmv -f /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak &> /dev/nullecho '[local]name=localbaseurl=file:///mntenabled=1gpgcheck=0' > /etc/yum.repos.d/local.repoyum clean all &> /dev/nullyum makecache &> /dev/nulldf -h | grep "/mnt" if [ $? -ne 0 ];thenecho -e "\033[31m 检测当前为仅主机模式,但光盘未连接! \033[0m"elseecho -e "\033[31m 本地yum源已配置完成 \033[0m"fifi#防火墙关闭systemctl stop firewalldsetenforce 0yum install -y gcc gcc-c++ makerpm -q expectrpm -q tclyum -y install expectcd /opttar zxvf redis-5.0.7.tar.gz -C /opt/cd /opt/redis-5.0.7/makemake PREFIX=/usr/local/redis install#由于Redis源码包中直接提供了Makefile 文件,所以在解压完软件包后,不用先执行./configure进行配置,可直接执行make与make install 命令进行安装。#在/utils里执行软件包提供的install_server.sh脚本文件设置Redis服务所需要的相关配置文件cd /opt/redis-5.0.7/utils#开始免交换执行/usr/bin/expect <<EOF#expect开始标志spawn ./install_server.sh#Please select the redis port for this instance: [6379]expect "instance"send "\r" #Please select the redis config file name [/etc/redis/6379.conf] expect "config"send "\r"#Please select the redis log file name [/var/log/redis_6379.log]expect "log"send "\r"#Please select the data directory for this instance [/var/lib/redis/6379]expect "data"send "\r"#Please select the redis executable path []expect "executable"send "/usr/local/redis/bin/redis-server\r"#Is this ok? Then press ENTER to go on or Ctrl-C to abort.expect "abort"send "\r"expect eofEOFln -s /usr/local/redis/bin/* /usr/local/bin/netstat -natp | grep redis/etc/init.d/redis_6379 restart     /etc/init.d/redis_6379 status   xyw=$(ip a | grep "ens33" | awk NR==2'{print$2}' |awk -F/ '{print$1}')sed -i "/bind 127.0.0.1/c bind 127.0.0.1 $xyw" /etc/redis/6379.confsed -i 's/appendonly no/appendonly yes/' /etc/redis/6379.conf/etc/init.d/redis_6379 restart/etc/init.d/redis_6379 status   

到此这篇关于Redis如何一键部署脚本的文章就介绍到这了,更多相关Redis 部署脚本内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!