Linux-Redis 6.2.6 installation record + background start + boot automatically

Linux-Redis 6.2.6 installation notes Records
Historical installation records: Linux-6.2.1 , Linux-6.0.10

1. Download the latest stable version from the official website

wget https://download.redis.io/releases/redis-6.2.6.tar.gz


2. Unzip

yum install -y tar
tar -zxvf redis-6.2.6.tar.gz

3. Create a soft link

ln -s redis-6.2.6 redis (或者直接改: mv redis-6.2.6 redis) 

redis


4. Enter the redis directory

cd redis

5. Start compiling

In order to avoid compilation errors, first upgrade the gcc version:

gcc -v
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutilsscl enable devtoolset-9 bash

Start compiling:

make

6. Compile and install:

make install

7. Modify the configuration file:

vi redis.conf
(按Esc退出编辑模式下: /protected-mode 即可搜索)

protected-mode no # 关闭保护模式

daemonize yes # 守护进程模式开启

#bind 127.0.0.1 # 绑定IP按需修改,bind指定网段远程访问redis,注释就没有限制了。

port 6379 # 端口(单机默认,集群按需修改)

requirepass 123456 # (搜/requirepass foobared)设置Redis密码

Note: The cloud server must set a password to prevent the server from being regarded as a mining machine


8. redis startup: enter the src directory

cd src

src

Start command: (start command + configuration file + background start)

./redis-server /usr/local/redis/redis.conf &  

start up
View process:

ps -ef | grep redis 

view progress
Built-in client connection test:
(connection command + IP + port number + password)

./redis-cli -h 127.0.0.1 -p 6379 -a 123456 

Tool remote connection test:
connect
redis shutdown command:

redis-cli shutdown 

9 Relevant file analysis:

redis-server server startup command
redis-cli client startup command
redis.conf redis core configuration file
redis-check-dump RDB file inspection tool (snapshot persistent file)
redis-check-aof AOF file repair tool

10 boot configuration

10.1 Create a redis directory under the etc directory

mkdir /etc/redis

10.2 Copy the redis configuration file to the etc/redis directory

cp /usr/local/redis/redis.conf /etc/redis/6379.conf

10.3 File authorization to avoid file execution without permission

chmod 755 /etc/redis/6379.conf

10.4 Then enter the /redis/utils directory and copy the startup script redis_init_script and rename it to redis

insert image description here

cp /usr/local/redis/utils/redis_init_script  /etc/init.d/redis

10.5 Modify redis script

 vi /etc/init.d/redis 
首行添加:
#chkconfig: 2345 10 90  
#description: Start and Stop redis 

Modify the corresponding startup service location

EXEC=/usr/local/redis/src/redis-server
CLIEXEC=/usr/local/redis/src/redis-cli

As shown below:
insert image description here

detailed document

#!/bin/sh
# chkconfig: 2345 10 90  
# description: Start and Stop redis 
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

### BEGIN INIT INFO
# Provides:     redis_6379
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Redis data structure server
# Description:          Redis data structure server. See https://redis.io
### END INIT INFO

REDISPORT=6379
PASSWORD=123456
EXEC=/usr/local/redis/src/redis-server
CLIEXEC=/usr/local/redis/src/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"

case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Redis服务启动..."
                $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -a $PASSWORD -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Redis服务关闭错误..."
                    sleep 1
                done
                echo "Redis服务关闭成功..."
        fi
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac


10.6 Enable autostart

chkconfig redis on

10.7 You can test whether the startup and shutdown are normal

stop:

service redis stop

(It will prompt that the command line is not safe to add a password, ignore it for now)
insert image description here
Start:

service redis start

View process
ps -ef | grep redis
insert image description here

10.8 reboot Restart the host and check whether redis starts automatically

reboot
ps -ef | grep redis 

insert image description here


Thanks for reading, this is the end for now.


Guess you like

Origin blog.csdn.net/qq_44870331/article/details/122892553