shell脚本一键部署——Redis(直接复制执行)亲测100% 有效
首先所需软件包拖进目录,然后编辑一个脚本,复制一下脚本,source执行一下即可
#!/bin/bash echo -e "\033[31m =====正在验证当前为仅主机还是NAT模式===== \033[0m" ping -c1 -W1 www.baidu.com &> /dev/null if [ $? -eq 0 ];then echo -e "\033[31m 检测当前为NAT模式,为您配置在线yum源 \033[0m" mkdir -p /etc/yum.repos.d/repo.bak mv -f /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak &> /dev/null wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo &> /dev/null yum clean all &> /dev/null yum list &> /dev/null echo -e "\033[31m 在线源已配置完成 \033[0m" else echo -e "\033[31m 检测当前为仅主机模式,为您配置本地yum源 \033[0m" mount /dev/sr0 /mnt &> /dev/null cd /etc/yum.repos.d/ mkdir -p /etc/yum.repos.d/repo.bak mv -f /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak &> /dev/null echo '[local] name=local baseurl=file:///mnt enabled=1 gpgcheck=0' > /etc/yum.repos.d/local.repo yum clean all &> /dev/null yum makecache &> /dev/null df -h | grep "/mnt" if [ $? -ne 0 ];then echo -e "\033[31m 检测当前为仅主机模式,但光盘未连接! \033[0m" else echo -e "\033[31m 本地yum源已配置完成 \033[0m" fi fi #关闭防火墙 systemctl stop firewalld setenforce 0 yum install -y gcc gcc-c++ make yum -y install expect cd /opt tar zxvf redis-5.0.7.tar.gz -C /opt/ cd /opt/redis-5.0.7/ make make PREFIX=/usr/local/redis install cd /opt/redis-5.0.7/utils /usr/bin/expect <<EOF spawn ./install_server.sh expect "instance" {send "\r"} expect "config" {send "\r"} expect "log" {send "\r"} expect "data" {send "\r"} expect "executable" {send "/usr/local/redis/bin/redis-server\r"} expect "abort" {send "\r"} expect eof EOF ln -s /usr/local/redis/bin/* /usr/local/bin/ /etc/init.d/redis_6379 restart sed -i '/bind 127.0.0.1/c bind 0.0.0.0' /etc/redis/6379.conf sed -i 's/appendonly no/appendonly yes/' /etc/redis/6379.conf /etc/init.d/redis_6379 restart /etc/init.d/redis_6379 status netstat -natp | grep redis
执行结果:
自古英雄多磨难