a key installation shell script redis online database (using the function implementation)

a key installation shell script redis online database (using the function implementation)

Previous article about the given process manually compile and install redis, and gives the online installation process redis redis building at the time of the simulation cluster, so they think of their own written script redis online installation, the paper mainly use shell functions to achieve and verification process line installation, after the implementation of correct thinking about sharing it.

PS: system environment Centos7.4

Script is as follows:

#!/bin/bash

function  checkroot(){
if [ $UID -ne  0 ]
  then
    echo "|----------------------------------------------------------------------------------------------------------------|"
    echo "|------------------------------------------[权限不足..请切换至root用户]-------------------------------------------|"
    echo "|----------------------------------------------------------------------------------------------------------------|"
    exit;
fi
}

function judge(){
    echo
    off_file=`ls | grep redis-*.tar.gz`
    if [[ "$off_file" = "" ]]
    then
        echo "|----------------------------------------------------------------------------------------------------------------|"
        echo "|-------------------------------------------------[未发现离线包]--------------------------------------------------|"
        echo "|-------------------------------------------------[开始在线安装]--------------------------------------------------|"
        /usr/bin/sleep 3
        network
    else
        exit;
    fi
}

function network(){
    yum install cpp binutils glibc-kernheaders glibc-common glibc-devel gcc gcc-c++ make wget  -y  #安装依赖库
    wget http://download.redis.io/releases/redis-5.0.7.tar.gz
    if [ -f /root/redis-5.0.7.tar.gz ];then
        tar zxvf redis-5.0.7.tar.gz
        mv redis-5.0.7 /usr/local/redis
        cd /usr/local/redis
        make
        cd src/
        make install 
    else
        echo "文件不存在!"
        exit;
    fi

    sed -i '136s/daemonize no/daemonize yes/' /usr/local/redis/redis.conf    #(编辑redis服务配置文件,修改其中配置)
    #设置开启守护进程运行
    sed -i '69s/127.0.0.1/0.0.0.0/' /usr/local/redis/redis.conf 
    #设置为任意终端访问
    sed -i '88s/protected-mode yes/protected-mode no/' /usr/local/redis/redis.conf
    #关闭受保护模式
    sed -i '832s/#//' /usr/local/redis/redis.conf
    #一下三行正则命令在部署集群时使用,单一安装时不要开启,否则会出错
    #开启集群模式
    #sed -i '840s/#//' /usr/local/redis/redis.conf
    #集群配置文件目录
    #sed -i '846s/#//' /usr/local/redis/redis.conf
    #节点超时时间
    #sed -i '699s/no/yes/' /usr/local/redis/redis.conf
    #开启aof持久化
    mkdir -p /etc/redis
    ln -s /usr/local/redis/redis.conf /etc/redis/6379.conf   #(在默认的配置文件路劲中放置配置文件)
    ln -s /usr/local/redis/utils/redis_init_script /etc/init.d/redisd    #(将初始化文件配置到系统自启动的文件夹内,redisd为服务名,可自行修改)
    service redisd start   #(开启redis服务,服务名为:redisd)
    #redis-cli  
    netstat -ntpl|grep redis
    echo "Redis 部署完成!"
    echo " "
    echo "如果你的系统是Centos 7在安装完毕后留意防火墙,可执行以下命令来放行redis 外部通信,若是没有成功则关闭防火墙及SELinux功能。"
    echo "firewall-cmd --zone=public --add-port=6379/tcp --permanent"
    echo "firewall-cmd --reload"
    echo "firewall-cmd --zone=public --query-port=6379/tcp"

}

function main(){
    checkroot
    judge
}

main

Screenshot installation:

a key installation shell script redis online database (using the function implementation)

After the installation into the database verification

a key installation shell script redis online database (using the function implementation)

Guess you like

Origin blog.51cto.com/14557673/2481435