Redis構成セクション

20152 ワード

Redis


バージョン情報を指定しない構成の説明はすべてごろつきです。 例えば4.0.9にvm関連およびglueoutputbufの構成情報がない

共通の構成セクションの一部(詳細は後述):
  • daemonize
  • pidfile
  • port
  • bind
  • timeout
  • loglevel
  • logfile
  • databases
  • save
  • rdbcompression
  • dbfilename
  • dir
  • slaveof
  • masterauth
  • requirepass
  • maxclients
  • maxmemory
  • maxmemory-policy
  • appendonly
  • appendfilename
  • appendfsync
  • hash-max-zipmap-entries
  • hash-max-zipmap-value
  • activerehashing
  • include

  • Redisの紹介


    String、Hash、List、Set、Zset、Geo、Hyperlogsなどのマルチデータ構造をサポートするオープンソースメモリデータベース.同僚は主従レプリケーション、Luauスクリプト、トランザクション、データ持続化、高可用性、クラスタ化などをサポートします.

    Redis特性

  • 高性能:Redisは単一スレッドであるが、同様にこの超高性能を有する.毎秒要求OPSが10 W程度に達することを示すテストがある.
  • 多様化データ構造:RedisはString、Hash、List、Set、Zset、Geoなどのマルチデータ構造をサポートする.
  • 永続化:
  • RDB持続化(スナップショット持続化方式)は、メモリ内の全量のデータをディスクにdumpする.その利点はAOFよりもロード速度が速く、劣勢はスナップショット式の全量バックアップであり、増分データがなく、データ損失をもたらす.
  • AOF永続化:AOFはRedisが実行するすべての書き込み操作コマンドを記録する.データを復元するプロセスは、これらの書き込みを再生することに相当します.AOFの持続化方式を使用すると、柔軟なブラシ戦略があり、データの安全性を保証することがメリットです.劣勢はAOFファイルの体積がRDBより大きく、ディスクの占有量が多く、データのメモリへのロード速度が遅いことである.

  • 複数データ削除ポリシー:
  • 不活性削除:期限切れのkeyを読み書きすると、不活性削除ポリシーがトリガーされ、この期限切れのkeyが削除されます.
  • 定期削除:不活性削除ポリシーは冷たいデータがタイムリーに削除されることを保証できないため、すべてのredisは定期的に期限切れのkeyを自主的に淘汰する.
  • アクティブ削除:メモリがmaxmemoryの制限を超えた場合、アクティブクリアポリシーがトリガーされます.このポリシーは起動パラメータの構成によって決定されます.構成可能なパラメータと説明は以下の通りです.
  • volatile-lru:有効期限が設定されているサンプルからLRUアルゴリズムに従ってデータを削除する(redis 3.0以前のデフォルトポリシー)
  • .
  • volatile-ttl:有効期限が設定されているサンプルから有効期限が最も小さいデータを選択
  • を削除する.
  • volatile-random:有効期限が設定されているサンプルからランダムにデータを選択して
  • を削除
  • allkeys-lru:サンプルからLRUアルゴリズムに従ってデータを削除する
  • allkeys-random:サンプルから任意選択でデータを削除
  • noenviction:メモリからのデータの削除を禁止する(redis 3.0からデフォルトポリシーを開始する)

  • 高可用性:Redis自身は歩哨(Sentinal)のコンポーネントを持っており、Redis主従の運行回転状態と自動的な故障切替を監視することができ、Redisの高可用性を実現することができる.

  • Redisインストール構成


    Redisインストール


    1.Redisのダウンロードと解凍(現在の最新バージョンは4.0.9)

    cd /usr/local/
    wget http://download.redis.io/releases/redis-4.0.9.tar.gz
    tar -zxzf redis-4.0.9.tar.gz
    

    2.コンパイルとインストール


    make install PREFIX=インストールパス
    cd /usr/local/redis-4.0.9
    make install PREFIX=/usr/local/redis
    

    redis関連コマンドを/usr/sbinディレクトリにコピーできます。これにより、パス全体に関係なく実行できます。
    cd /usr/local/redis/bin
    cp redis-cli redis-server redis-sentinel /usr/sbin
    

    3.Redis構成(v 4.0.9)


    redisのプロファイル(redis.conf)コピーバックアップ 個人的な習慣は、最も原始的なプロファイルをバックアップし、後期の比較や復元を容易にすることです。 redisプロファイルの主要パラメータ解析リファレンス
  • daemonize

  • Redisがデーモンプロセスで実行されるかどうかを設定します。デフォルトはnoです。
    # 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 no
    
  • pidfile

  • Redisがデーモン方式で実行する場合、Redisはデフォルトでpidを/var/run/redisに書き込む.pidファイル、pidfileで指定できます
    # If a pid file is specified, Redis writes it where specified at startup
    # and removes it at exit.
    #
    # When the server runs non daemonized, no pid file is created if none is
    # specified in the configuration. When the server is daemonized, the pid file
    # is used even if not specified, defaulting to "/var/run/redis.pid".
    #
    # Creating a pid file is best effort: if Redis is not able to create it
    # nothing bad happens, the server will start and run normally.
    pidfile /var/run/redis_6379.pid
    
  • port

  • Redisのリスニングポートを指定し、ポートのデフォルトは6379です(ソースの女性歌手の名前)
    # Accept connections on the specified port, default is 6379 (IANA #815344).
    # If port 0 is specified Redis will not listen on a TCP socket.
    port 6379
    
  • bind

  • バインドされたホストアドレス
    # By default, if no "bind" configuration directive is specified, Redis listens
    # for connections from all the network interfaces available on the server.
    # It is possible to listen to just one or multiple selected interfaces using
    # the "bind" configuration directive, followed by one or more IP addresses.
    #
    # Examples:
    #
    # bind 192.168.1.100 10.0.0.1
    # bind 127.0.0.1 ::1
    #
    # ~~~ 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 lookback 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 127.0.0.1
    
  • timeout

  • クライアントがアイドル状態になってから接続をオフにします。0を指定すると、この機能をオフにします。
    # Close the connection after a client is idle for N seconds (0 to disable)
    timeout 0
    
  • loglevel

  • ログ・レコード・レベルを指定します。Redisは4つのレベルをサポートします。debug、verbose、notice、warning、デフォルトはnoticeです。
    # Specify the server verbosity level.
    # This can be one of:
    # debug (a lot of information, useful for development/testing)
    # verbose (many rarely useful info, but not a mess like the debug level)
    # notice (moderately verbose, what you want in production probably)
    # warning (only very important / critical messages are logged)
    loglevel notice
    
  • logfile

  • ログ記録方式、デフォルトは標準出力で、Redisをデーモン方式で実行するように構成し、ここでログ記録方式を標準出力として構成すると、ログは/dev/nullに送信されます。
    # Specify the log file name. Also the empty string can be used to force
    # Redis to log on the standard output. Note that if you use standard
    # output for logging but daemonize, logs will be sent to /dev/null
    logfile ""
    
  • databases

  • データベースの数を設定します。デフォルトのデータベースは0です。SELECTコマンドを使用して、接続にデータベースidを指定できます。
    # Set the number of databases. The default database is DB 0, you can select
    # a different one on a per-connection basis using SELECT  where
    # dbid is a number between 0 and 'databases'-1
    databases 16
    
  • save

  • どのくらいの時間内に、何回の更新操作があるかを指定して、データをデータファイルに同期して、複数の条件を合わせることができます デフォルト
    # Save the DB on disk:
    #
    #   save  
    #
    #   Will save the DB if both the given number of seconds and the given
    #   number of write operations against the DB occurred.
    #
    #   In the example below the behaviour will be to save:
    #   after 900 sec (15 min) if at least 1 key changed
    #   after 300 sec (5 min) if at least 10 keys changed
    #   after 60 sec if at least 10000 keys changed
    #
    #   Note: you can disable saving completely by commenting out all "save" lines.
    #
    #   It is also possible to remove all the previously configured save
    #   points by adding a save directive with a single empty string argument
    #   like in the following example:
    #
    #   save ""
    
    save 900 1
    save 300 10
    save 60 10000
    
  • rdbcompression

  • ローカル・データベースに格納するときにデータを圧縮するかどうかを指定します。デフォルトはyesです。RedisはLZF(Apacheオープン・ソース・アルゴリズム)で圧縮されます。CPUの時間を節約するために、このオプションをオフにすることができますが、データベース・ファイルが大きくなります。
    # Compress string objects using LZF when dump .rdb databases?
    # For default that's set to 'yes' as it's almost always a win.
    # If you want to save some CPU in the saving child set it to 'no' but
    # the dataset will likely be bigger if you have compressible values or keys.
    rdbcompression yes
    
  • dbfilename

  • ローカルデータベースのファイル名を指定します。デフォルトはdumpです。rdb
    # The filename where to dump the DB
    dbfilename dump.rdb
    
  • dir

  • ローカル・データベースの保存ディレクトリの指定
    # 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 ./
    
  • slaveof

  • 設定自機がslaveサービスの場合、masterサービスのipアドレスとポートを設定し、Redis起動時、自動的にmasterからデータ同期を行う
    # Master-Slave replication. Use slaveof to make a Redis instance a copy of
    # another Redis server. A few things to understand ASAP about Redis replication.
    #
    # 1) Redis replication is asynchronous, but you can configure a master to
    #    stop accepting writes if it appears to be not connected with at least
    #    a given number of slaves.
    # 2) Redis slaves are able to perform a partial resynchronization with the
    #    master if the replication link is lost for a relatively small amount of
    #    time. You may want to configure the replication backlog size (see the next
    #    sections of this file) with a sensible value depending on your needs.
    # 3) Replication is automatic and does not need user intervention. After a
    #    network partition slaves automatically try to reconnect to masters
    #    and resynchronize with them.
    #
    # slaveof  
    
  • masterauth

  • マスターサービスがパスワード保護を設定するとsalveサービスはマスターのパスワードに接続されます
    # If the master is password protected (using the "requirepass" configuration
    # directive below) it is possible to tell the slave to authenticate before
    # starting the replication synchronization process, otherwise the master will
    # refuse the slave request.
    #
    # masterauth 
    
  • requirepass

  • Redisの接続パスワードを設定します。接続パスワードが設定されている場合、クライアントはRedisに接続する際、AUTHコマンドでパスワードを入力する必要があります。デフォルトでは閉じます。
    # Require clients to issue AUTH  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
    
  • maxclients

  • 同じ時間に最大クライアント接続数を設定します。デフォルトでは制限はありません。Redisが同時に開くことができるクライアント接続数は、maxclients 0を設定すると制限されません。クライアント接続数が制限に達すると、Redisは新しい接続を閉じ、クライアントにmax number of clients reachedエラーメッセージを返したい
    # Set the max number of connected clients at the same time. By default
    # this limit is set to 10000 clients, however if the Redis server is not
    # able to configure the process file limit to allow for the specified limit
    # the max number of allowed clients is set to the current file limit
    # minus 32 (as Redis reserves a few file descriptors for internal uses).
    #
    # Once the limit is reached Redis will close all the new connections sending
    # an error 'max number of clients reached'.
    #
    # maxclients 10000
    
  • maxmemory

  • Redisの最大メモリ制限を指定します。Redisは起動時にメモリにデータをロードします。最大メモリに達すると、Redisは書き込み操作ができなくなりますが、読み取り操作は可能です。メモリクリーンアップは、次のメモリクリーンアップポリシーを使用して行います。Redisの新しいvmメカニズムは、Keyをメモリに保存し、Valueをswap領域に保存します。
    # Set a memory usage limit to the specified amount of bytes.
    # When the memory limit is reached Redis will try to remove keys
    # according to the eviction policy selected (see maxmemory-policy).
    #
    # If Redis can't remove keys according to the policy, or if the policy is
    # set to 'noeviction', Redis will start to reply with errors to commands
    # that would use more memory, like SET, LPUSH, and so on, and will continue
    # to reply to read-only commands like GET.
    #
    # This option is usually useful when using Redis as an LRU or LFU cache, or to
    # set a hard memory limit for an instance (using the 'noeviction' policy).
    #
    # WARNING: If you have slaves attached to an instance with maxmemory on,
    # the size of the output buffers needed to feed the slaves are subtracted
    # from the used memory count, so that network problems / resyncs will
    # not trigger a loop where keys are evicted, and in turn the output
    # buffer of slaves is full with DELs of keys evicted triggering the deletion
    # of more keys, and so forth until the database is completely emptied.
    #
    # In short... if you have slaves attached it is suggested that you set a lower
    # limit for maxmemory so that there is some free RAM on the system for slave
    # output buffers (but this is not needed if the policy is 'noeviction').
    #
    # maxmemory 
    
  • maxmemory-policy

  • メモリが設定された最大メモリに達した後、どのポリシーを使用してメモリをクリーンアップしますか?
    # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
    # is reached. You can select among five behaviors:
    #
    # volatile-lru -> Evict using approximated LRU among the keys with an expire set.
    # allkeys-lru -> Evict any key using approximated LRU.
    # volatile-lfu -> Evict using approximated LFU among the keys with an expire set.
    # allkeys-lfu -> Evict any key using approximated LFU.
    # volatile-random -> Remove a random key among the ones with an expire set.
    # allkeys-random -> Remove a random key, any key.
    # volatile-ttl -> Remove the key with the nearest expire time (minor TTL)
    # noeviction -> Don't evict anything, just return an error on write operations.
    #
    # LRU means Least Recently Used
    # LFU means Least Frequently Used
    #
    # Both LRU, LFU and volatile-ttl are implemented using approximated
    # randomized algorithms.
    #
    # Note: with any of the above policies, Redis will return an error on write
    #       operations, when there are no suitable keys for eviction.
    #
    #       At the date of writing these commands are: set setnx setex append
    #       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
    #       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
    #       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
    #       getset mset msetnx exec sort
    #
    # The default is:
    #
    # maxmemory-policy noeviction
    
  • appendonly

  • 更新操作のたびにログを記録するかどうかを指定します。Redisのデフォルトでは、ディスクに非同期でデータを書き込みます。オンにしないと、電源が切れたときに一定期間のデータが失われる可能性があります。Redis自体の同期データファイルは上記のsave条件で同期されるため、一定期間メモリにしか存在しないデータもあります。デフォルトはno
    # By default Redis asynchronously dumps the dataset on disk. This mode is
    # good enough in many applications, but an issue with the Redis process or
    # a power outage may result into a few minutes of writes lost (depending on
    # the configured save points).
    #
    # The Append Only File is an alternative persistence mode that provides
    # much better durability. For instance using the default data fsync policy
    # (see later in the config file) Redis can lose just one second of writes in a
    # dramatic event like a server power outage, or a single write if something
    # wrong with the Redis process itself happens, but the operating system is
    # still running correctly.
    #
    # AOF and RDB persistence can be enabled at the same time without problems.
    # If the AOF is enabled on startup Redis will load the AOF, that is the file
    # with the better durability guarantees.
    #
    # Please check http://redis.io/topics/persistence for more information.
    
    appendonly no
    
  • appendfilename

  • 更新ログファイル名の指定
    # The name of the append only file (default: "appendonly.aof")
    
    appendfilename "appendonly.aof"
    
  • appendfsync

  • 更新ログの条件を指定します。オプションは3つあります。
    # The fsync() call tells the Operating System to actually write data on disk
    # instead of waiting for more data in the output buffer. Some OS will really flush
    # data on disk, some other OS will just try to do it ASAP.
    #
    # Redis supports three different modes:
    #
    # no: don't fsync, just let the OS flush the data when it wants. Faster.
    # always: fsync after every write to the append only log. Slow, Safest.
    # everysec: fsync only one time every second. Compromise.
    #
    # The default is "everysec", as that's usually the right compromise between
    # speed and data safety. It's up to you to understand if you can relax this to
    # "no" that will let the operating system flush the output buffer when
    # it wants, for better performances (but if you can live with the idea of
    # some data loss consider the default persistence mode that's snapshotting),
    # or on the contrary, use "always" that's very slow but a bit safer than
    # everysec.
    #
    # More details please check the following article:
    # http://antirez.com/post/redis-persistence-demystified.html
    #
    # If unsure, use "everysec".
    
    # appendfsync always
    appendfsync everysec
    # appendfsync no
    
  • hash-max-zipmap-entries、hash-max-zipmap-value

  • 一定の数または最大の要素が臨界値を超える場合に、特殊なハッシュアルゴリズムを使用することを指定します。
    # Hashes are encoded using a memory efficient data structure when they have a
    # small number of entries, and the biggest entry does not exceed a given
    # threshold. These thresholds can be configured using the following directives.
    hash-max-ziplist-entries 512
    hash-max-ziplist-value 64
    
  • activerehashing

  • リセットハッシュをアクティブにするかどうかを指定します。デフォルトはオンです。
    # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
    # order to help rehashing the main Redis hash table (the one mapping top-level
    # keys to values). The hash table implementation Redis uses (see dict.c)
    # performs a lazy rehashing: the more operation you run into a hash table
    # that is rehashing, the more rehashing "steps" are performed, so if the
    # server is idle the rehashing is never complete and some more memory is used
    # by the hash table.
    #
    # The default is to use this millisecond 10 times every second in order to
    # actively rehash the main dictionaries, freeing memory when possible.
    #
    # If unsure:
    # use "activerehashing no" if you have hard latency requirements and it is
    # not a good thing in your environment that Redis can reply from time to time
    # to queries with 2 milliseconds delay.
    #
    # use "activerehashing yes" if you don't have such hard requirements but
    # want to free memory asap when possible.
    activerehashing yes
    
  • include

  • 同じホスト上の複数のRedisインスタンス間で同じプロファイルを使用しながら、個々のインスタンスが独自のプロファイルを持つ他のプロファイルを含めるよう指定します。
    # Include one or more other config files here.  This is useful if you
    # have a standard template that goes to all Redis servers but also need
    # to customize a few per-server settings.  Include files can include
    # other files, so use this wisely.
    #
    # Notice option "include" won't be rewritten by command "CONFIG REWRITE"
    # from admin or Redis Sentinel. Since Redis always uses the last processed
    # line as value of a configuration directive, you'd better put includes
    # at the beginning of this file to avoid overwriting config change at runtime.
    #
    # If instead you are interested in using includes to override configuration
    # options, it is better to use include as the last line.
    #
    # include /path/to/local.conf
    # include /path/to/other.conf