部署REDIS服务,准备集群环境(一)。

此博客主要介绍了快速搭建REDIS的方法,包含输出不同颜色字体、检查安装是否成功、定义启动和停止函数等。还涉及一键安装REDIS,以及对配置文件进行解析,同时准备集群环境。

#!/bin/bash
#AUTHOR:ZHD
#DATE:2019-05-19
#FUNCTION:快速搭建REDIS,配置文件解析,准备集群环境。
#VERSION:1.0

#输出不同颜色的字体

function cecho {
  echo -e "\033[$1m$2\033[0m"
}

#检查REDIS是否安装成功

function check_redis {
        netstat -ntulp | grep redis-server &> /dev/null && cecho 32 "REDIS BUILD SUCCESSFULLY!!" || cecho  31 " REDIS BUILD FAIL,PLEASE CHECK IT!!"
}

#定义redis启动函数

function redis_start {
        /etc/init.d/redis_6379 start
}

#定义redis停止函数

function redis_stop {
        /etc/init.d/redis_6379 stop
}

#定义一键安装REDIS函数

function redis_install {
        cecho 32 "系统正在装包,请稍等......."
        yum -y install expect &> /dev/null
        yum -y install gcc &> /dev/null
        cd /root/soft/redis
        tar -xf redis-4.0.8.tar.gz &> /dev/null
        cd redis-4.0.8/
        cecho 32 "源码编译安装过程中,这会需要一点时间,请稍等......"
        make &> /dev/null &&  make install &> /dev/null
        cd /root/soft/redis/redis-4.0.8/utils
expect <<EOF &> /dev/null
        spawn  ./install_server.sh  
        expect "]"      {send "\r"}
        expect "]"      {send "\r"}
        expect "]"      {send "\r"}
        expect "]"      {send "\r"}
        expect "]"      {send "\r"}
        expect "abort." {send "\r"}
        expect "#"      {send "exit\rr"}
EOF
}

redis_install
redis_start
check_redis

#配置文件解析

function file_resolution {
        /etc/init.d/redis_6379 stop
        read -p "请输入要更改的端口号:" port_number
        read -p "请设置要更改的IP地址:" IP_add
        read -p "是否开启redis集群服务?(yes/no)"  yes
        read -p "设置集群配置文件编号:" number
        read -p "设置集群超时时间:" timess

        if [ $yes = yes ];then
                sed -i '815s/# cluster-enabled yes/cluster-enabled yes/' /etc/redis/6379.conf
        else
                exit 0
        fi

        sed -i "823s/# cluster-config-file nodes-6379.conf/cluster-config-file nodes-$number.conf/"  /etc/redis/6379.conf
        sed -i "829s/# cluster-node-timeout 15000/cluster-node-timeout $timess/"  /etc/redis/6379.conf

        sed -i "93s/port 6379/port $port_number/" /etc/redis/6379.conf
        sed -i "70s/bind 127.0.0.1/bind $IP_add/" /etc/redis/6379.conf
        sed -i "43c \$CLIEXEC -p $port_number -h $IP_add shutdown" /etc/init.d/redis_6379
        /etc/init.d/redis_6379 start
}

file_resolution

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

河 静

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值