Installing and Configuring Redis 7.4.3 on Linux

Supported Operating Systems:BigCloud Enterprise Linux For Euler 21.10 LTShttps://mirrors.cmecloud.cn/bclinux/oe21.10/openEuler 24.03 LTS SP1https://www.openeuler.org/en/download/CentOS-8, AlmaLinux, Rocky Linux, etc.1. Download the installation packageDownload link:https://download.redis.io/releases/redis-7.4.3.tar.gzUpload the installation package to the server in the /usr/local/src directory2. Upgrade GCC version# Redis source code compilation requires GCC version 5 or highergcc -v # Check GCC version# If GCC is already a high version, no upgrade is needed# yum -y install gcc gcc-c++ # Install GCC# yum -y install tcl# Upgrade to GCC version# yum -y install centos-release-scl# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils# scl enable devtoolset-9 bash # Temporarily activate the version# echo “source /opt/rh/devtoolset-9/enable” >>/etc/profile # Permanently activate the version3. Install Redis

mkdir -p /data/server/redis  # Create installation directorymkdir -p /data/server/redis/data  # Create data storage directorymkdir -p /data/server/redis/log  # Create log directorycd  /usr/local/srctar  -zxvf  redis-7.4.3.tar.gzcd  redis-7.4.3makemake install  PREFIX=/data/server/redis

4. Configure Redis

cp  /usr/local/src/redis-7.4.3/redis.conf  /data/server/redis/redis.confvi /data/server/redis/redis.confdaemonize yes  # Run Redis in daemon modepidfile /data/server/redis/redis_6379.pidport 6379bind 127.0.0.1 -::1protected-mode yestimeout 300 # Client timeout setting, in secondsloglevel warning # Set log level, supports four levels: debug, verbose, notice, warninglogfile "/data/server/redis/log/redis.log"  # Log recording method, default is standard output, logs do not write to file, output to null device /dev/null databases 16  # Number of databases enabledsave 900 1save 300 10save 60 10000rdbcompression yes # Enable database lzf compressiondbfilename dump.rdbdir "/data/server/redis/data"requirepass 123456  # Set Redis database connection passwordmaxclients 10000 # Maximum number of client connections at the same time, 0 means unlimitedmaxmemory 4096MB # Set the maximum memory usage for Redis, value must be less than physical memory, must be setappendonly yes  # Enable log recording, equivalent to MySQL's binlogappendfilename "appendonly.aof"   # Log file name, note: not directory pathappendfsync everysec # Synchronize every second, there are two other parameters always, no generally set to everysec, equivalent to MySQL transaction log writing method:wq! # Save and exit

5. Start Redis

# Start /data/server/redis/bin/redis-server  /data/server/redis/redis.conf# Enter console/data/server/redis/bin/redis-cli -a 123456AUTH 123456shutdown# Shutdown/data/server/redis/bin/redis-cli -a 123456 shutdown

6. Add startup script

vi /data/server/redis/redis.sh#!/bin/bash# Application nameAPP_NAME=redis# Redis portREDISPORT=6379# Redis installation directoryDIR=/data/server/redis# Redis process filePIDFILE=/data/server/redis/redis_6379.pid# Redis configuration fileCONF="/data/server/redis/redis.conf"# Redis passwordAUTH='123456'# Usage instructions, used to prompt input parametersusage() {    echo "Usage: ./redis.sh [start|stop|restart|status]"    exit 1}# Check if the program is runningis_exist() {    if [ -f $PIDFILE ]    then         pid=$(cat $PIDFILE)    else pid=    fi    # If it does not exist return 1, exists return 0    if [ -z "${pid}" ]; then      return 1    else      return 0    fi}# Start methodstart() {   is_exist   if [ $? -eq "0" ]; then     echo "${APP_NAME} is already running. pid=${pid} ."   else     echo "Starting Redis server..."     $DIR/bin/redis-server  $CONF   fi}# Stop methodstop() {   is_exist   if [ $? -eq "0" ]; then        $DIR/bin/redis-cli -p $REDISPORT   -a  $AUTH  shutdown  2>/dev/null        sleep 2        while [ -x $PIDFILE ]        do            echo "Waiting for Redis to shutdown..."            sleep 1        done            echo "Redis stopped"   else     echo "${APP_NAME} is not running"   fi}# Output running statusstatus() {   is_exist   if [ $? -eq "0" ]; then     echo "${APP_NAME} is running. Pid is ${pid}"   else     echo "${APP_NAME} is not running."   fi}# Restartrestart() {   stop   sleep 2   start}# Based on input parameters, choose to execute the corresponding method, if not input, execute usage instructionscase "$1" in   "start")     start     ;;   "stop")     stop     ;;   "status")     status     ;;   "restart")     restart     ;;   *)     usage     ;;esac:wq! # Save and exit
chmod +x /data/server/redis/redis.sh  # Add execution permission/data/server/redis/redis.sh start # Start Redis

At this point, the installation and configuration of Redis 7.4.3 on Linux is complete.

Leave a Comment