iT邦幫忙

2021 iThome 鐵人賽

DAY 8
0
Software Development

Redis還在學系列 第 8

Day8 Redis組態檔設定-KEYS TRACKING/SECURITY/CLIENT

Redis.config

KEYS TRACKING

  • tracking-table-max-keys

當開啟Tracking 模式時,如果Tracking keys大於設定的數量,則會隨機刪除Tracking的key,然後回應用戶端invalidate。透過此方式可以追蹤用戶端使用哪些key.

https://ithelp.ithome.com.tw/upload/images/20210923/201116584YUjhCxWas.png

# 預設
# tracking-table-max-keys 1000000

# 開啟Tracking key
client tracking on

SECURITY

  • user acl

設定使用者和相關權限,所有參數可以參閱下面網址進一步了解。

ACL configuration

https://ithelp.ithome.com.tw/upload/images/20210923/20111658RaBN8gfnjU.png
https://ithelp.ithome.com.tw/upload/images/20210923/20111658uP32hjhFVS.png
https://ithelp.ithome.com.tw/upload/images/20210923/20111658dlWzsAst7S.png

# For example:
# 使用者worker 有list與connection權限,並可操作jobs的key,預設開啟並設定密碼。
#   user worker +@list +@connection ~jobs:* on >ffa9203c493aa99
  • acllog-max-len

設定acl記錄中的項目上限.

https://ithelp.ithome.com.tw/upload/images/20210923/20111658dIpJ0pj4Bz.png

# 預設
acllog-max-len 128
  • aclfile

透過檔案設定acl.需注意如果redis.config已經設定acl,則會拒絕檔案acl設定.

https://ithelp.ithome.com.tw/upload/images/20210923/20111658nOBNxl4tnC.png

# 預設
# aclfile /etc/redis/users.acl
  • requirepass

用戶端登入Redis Server時需要使用此密碼進行驗證才可執行操作.

https://ithelp.ithome.com.tw/upload/images/20210923/20111658mOsW3H3Z5k.png

# 預設
# requirepass foobared
  • acl-pubsub-default

設定預設channels的pub/sub權限,Redis 6.2開始可以使用acl設定channels的pub/sub權限.

https://ithelp.ithome.com.tw/upload/images/20210923/20111658CGKkUpHT1N.png

# 預設
# 拒絕使用channels的pub/sub
# acl-pubsub-default resetchannels

# 授權使用channels的pub/sub
acl-pubsub-default allchannels

CLIENT

  • maxclients

用戶端最多可以允許多少連線數,需搭配伺服器環境設定的net.core.somaxconn.

https://ithelp.ithome.com.tw/upload/images/20210923/20111658STZnKmQgNq.png

# 預設
# maxclients 10000

# 允許32767連線數
net.core.somaxconn= 32767

MEMORY MANAGEMENT

  • maxmemory

設定Redis Server 最多可以使用多少記憶體.因backgrond服務也會使用到記憶體,故建議需保留一半避免out of memory.

https://ithelp.ithome.com.tw/upload/images/20210923/20111658znEuBeNuKR.png

# 預設
# maxmemory <bytes>
  • maxmemory-policy

當記憶體不足時,配置相關的規則進行因應.
LRU: 最近沒有用到的key優先刪除
LFU: 最不頻繁使用到的key優先刪除

https://ithelp.ithome.com.tw/upload/images/20210923/20111658d5z3h4oSuI.png

# 預設
# 當超過maxmemory則會拋出錯誤
# maxmemory-policy noeviction
  • maxmemory-samples

針對使用LRU及TTL存活時間計算,此參數表示要檢查鍵的樣本大小。

https://ithelp.ithome.com.tw/upload/images/20210923/20111658c8R9UMT9DX.png

# 預設
# maxmemory-samples 5
  • maxmemory-eviction-tenacity

當超過maxmemory-policy設定時,設定是否需要延遲,當用戶端此時大量操作時,建議放大此設定.

https://ithelp.ithome.com.tw/upload/images/20210923/20111658cJvENqVfy6.png

# 預設
# 0 低延遲
# maxmemory-eviction-tenacity 10
  • replica-ignore-maxmemory

確定Replica是否忽略maxmemory設定,方法是不從Master刪除key獨立移出.

https://ithelp.ithome.com.tw/upload/images/20210923/20111658PAAJ4CBYeD.png

# 預設
# replica-ignore-maxmemory yes
  • active-expire-effort

Redis 會刪除已經超過其時間由兩種機制生活的密鑰。

https://ithelp.ithome.com.tw/upload/images/20210923/20111658BE6Rh8tZ2H.png

# 預設
# 1 會嘗試避免超過 10% 的過期金鑰仍在記憶體中。
# active-expire-effort 1

# 10 最多允許值,以增加在處理過期金鑰上花費的工作量,但可能會使用到CPU和造成更高的延遲

上一篇
Day7 Redis組態檔設定-REPLICATION
下一篇
Day9 Redis組態檔設定-LAZY FREEING/THREADED IO/KERNEL OOM CONTROL/APPEND ONLY MODE
系列文
Redis還在學30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言