Redisのインストールと構成および一般的なコマンド

1ダウンロード

公式ウェブサイトアドレス: https //redis.io/download

ここに画像の説明を挿入

**履歴バージョン:** http://download.redis.io/releases/

ここに画像の説明を挿入

** Windows版本:** https://github.com/tporadowski/redis/releases
ここに画像の説明を挿入

CSDN-Windowsバージョンアドレス: https ://download.csdn.net/download/qq_15769939/15039183

CSDN-Linuxバージョンアドレス: https ://download.csdn.net/download/qq_15769939/15039008

2redisをインストールします

2.1サーバーにファイルをアップロードする

[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.2GCCコンパイル環境をインストールする

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

2.3コンパイルしてインストールする

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

3Redisを構成する

3.1スクリプトファイルをコピーする

[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カスタム構成ファイル

[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.1redisを開始してバックグラウンドで実行するように設定する

daemonize no改訂daemonize 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.2redis作業ディレクトリの変更

# 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リモートアクセスの設定(無制限の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パスワードの設定

默认没有密码、指定するように構成する必要があります

################################## 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スクリプトファイルを変更する

[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承認して開始する

[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電源投入後の自動起動を設定する

[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 停止パスワード検証を追加

chkconfig redis_init_script on

4一般的なコマンド

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関連情報

  • ブログ投稿は簡単ではありません、注意と賞賛に一生懸命働いたすべての人、ありがとう

おすすめ

転載: blog.csdn.net/qq_15769939/article/details/113677172