Redis installation and configuration and common commands

1 download

Official website address: https://redis.io/download

Insert picture description here

**History version:**http://download.redis.io/releases/

Insert picture description here

**Windows 版本:**https://github.com/tporadowski/redis/releases
Insert picture description here

CSDN-Windows version address: https://download.csdn.net/download/qq_15769939/15039183

CSDN-Linux version address: https://download.csdn.net/download/qq_15769939/15039008

2 install redis

2.1 Upload files to the server

[root@localhost ~]# cd /opt/module/software
[root@localhost software]# ll
-rw-r--r--. 1 root root 1975750 2月   4 10:20 redis-5.0.5.tar.gz
[root@localhost software]# tar -zxvf redis-5.0.5.tar.gz
[root@localhost software]# ll
drwxrwxr-x. 6 root root    4096 5月  16 2019 redis-5.0.5
-rw-r--r--. 1 root root 1975750 2月   4 10:20 redis-5.0.5.tar.gz

2.2 Install GCC compilation environment

[root@localhost software]# yum install gcc-c++

2.3 Compile and install

[root@localhost software]# cd /opt/module/software/redis-5.0.5
[root@localhost redis-5.0.5]# make && make install

3 Configure Redis

3.1 Copy script file

[root@localhost redis-5.0.5]# cd /opt/module/software/redis-5.0.5/utils
[root@localhost utils]# cp redis_init_script /etc/init.d
[root@localhost utils]# cd /usr/local/redis/
[root@localhost redis]# mkdir working

3.2 Custom configuration file

[root@localhost utils]# mkdir /usr/local/redis -p
[root@localhost utils]# cd /opt/module/software/redis-5.0.5
[root@localhost redis-5.0.5]# cp redis.conf /usr/local/redis
[root@localhost redis-5.0.5]# vi /usr/local/redis/redis.conf

3.2.1 Set redis to start and run in the background

The daemonize norevised todaemonize yes

################################# GENERAL #####################################

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes

3.2.2 Modify redis working directory

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir /usr/local/redis/working

3.2.3 Set up remote access (unlimited IP)

# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 loopback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 0.0.0.0

3.2.4 Set password

默认没有密码, Need to be configured to specify

################################## SECURITY ###################################

# Require clients to issue AUTH <PASSWORD> before processing any other
# commands.  This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
# requirepass foobared
requirepass auskat

3.3 Modify the script file

[root@localhost redis-5.0.5]# vi /etc/init.d/redis_init_script
CONF="/usr/local/redis/${REDISPORT}.conf"
[root@localhost redis-5.0.5]# mv /usr/local/redis/redis.conf /usr/local/redis/6379.conf

3.4 Authorize and start

[root@localhost redis-5.0.5]# cd /etc/init.d/
[root@localhost init.d]# chmod 777 redis_init_script
[root@localhost init.d]# ./redis_init_script start
Starting Redis server...
12217:C 04 Feb 2021 10:42:30.639 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
12217:C 04 Feb 2021 10:42:30.639 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=12217, just started
12217:C 04 Feb 2021 10:42:30.639 # Configuration loaded
[root@localhost init.d]# ps -ef | grep redis
root      12218      1  0 10:42 ?        00:00:00 /usr/local/bin/redis-server 0.0.0.0:6379
root      12223   7622  0 10:42 pts/3    00:00:00 grep --color=auto redis

3.5 Set auto-start after power-on

[root@localhost redis-5.0.5]# vi /etc/init.d/redis_init_script
#chkconifg: 22345 10 90
#description: Start and stop redis


    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -a auskat -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    *)

$CLIEXEC -a auskat -p $REDISPORT shutdown Add stop password verification

chkconfig redis_init_script on

4 Common commands

redis-cli -a password shutdown :关闭redis
./redis_init_script stop :关闭redis
redis-cli :进入到redis客户端
auth pwd :输入密码
set key value :设置缓存
get key :获得缓存
del key :删除缓存
redis-cli -a password ping :查看是否存活

5 Related information

  • The blog post is not easy, everyone who has worked so hard to pay attention and praise, thank you

Guess you like

Origin blog.csdn.net/qq_15769939/article/details/113677172