One click online installation of redis database by shell script (implemented by function)

Keywords: Linux Redis firewall glibc network

The previous article gives the process of manual compilation and installation of redis, and gives the process of online installation of redis when simulating the establishment of redis cluster, so I want to write a redis script for online installation. In this paper, I mainly use shell functions to realize and verify the process of online installation, and I want to share it after it is executed correctly.

PS: the system environment is Centos7.4

The script is as follows:

#!/bin/bash

function  checkroot(){
if [ $UID -ne  0 ]
  then
    echo "|----------------------------------------------------------------------------------------------------------------|"
    echo "|------------------------------------------[Insufficient authority..Please switch to root user]-------------------------------------------|"
    echo "|----------------------------------------------------------------------------------------------------------------|"
    exit;
fi
}

function judge(){
    echo
    off_file=`ls | grep redis-*.tar.gz`
    if [[ "$off_file" = "" ]]
    then
        echo "|----------------------------------------------------------------------------------------------------------------|"
        echo "|-------------------------------------------------[No offline packages found]--------------------------------------------------|"
        echo "|-------------------------------------------------[Start online installation]--------------------------------------------------|"
        /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  #Install dependency Library
    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 "file does not exist!"
        exit;
    fi

    sed -i '136s/daemonize no/daemonize yes/' /usr/local/redis/redis.conf    #(edit the redis service configuration file and modify its configuration)
    #Set to start the running of Daemons
    sed -i '69s/127.0.0.1/0.0.0.0/' /usr/local/redis/redis.conf 
    #Set to any terminal access
    sed -i '88s/protected-mode yes/protected-mode no/' /usr/local/redis/redis.conf
    #Turn off protected mode
    sed -i '832s/#//' /usr/local/redis/redis.conf
    #The following three lines of regular commands are used in cluster deployment. Do not open them in single installation, or errors will occur
    #Turn on cluster mode
    #sed -i '840s/#//' /usr/local/redis/redis.conf
    #Cluster profile directory
    #sed -i '846s/#//' /usr/local/redis/redis.conf
    #Node timeout
    #sed -i '699s/no/yes/' /usr/local/redis/redis.conf
    #Enable aof persistence
    mkdir -p /etc/redis
    ln -s /usr/local/redis/redis.conf /etc/redis/6379.conf   #(place profile in default profile road strength)
    ln -s /usr/local/redis/utils/redis_init_script /etc/init.d/redisd    #(configure the initialization file to the folder where the system starts. redisd is the service name, which can be modified by yourself.)
    service redisd start   #(enable the redis service. The service name is redisd)
    #redis-cli  
    netstat -ntpl|grep redis
    echo "Redis Deployment complete!"
    echo " "
    echo "If your system is Centos 7 Pay attention to the firewall after installation, and execute the following command to release redis External communication,If not, turn off the firewall and SELinux Function."
    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 during installation:

Enter database validation after installation

Posted by m!tCh on Wed, 25 Mar 2020 07:48:09 -0700