首頁  >  文章  >  後端開發  >  redis單機開啟多實例

redis單機開啟多實例

不言
不言原創
2018-04-27 11:39:251644瀏覽

這篇文章主要介紹了關於redis單機開啟多實例,有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下

Redis 是一個開源(BSD許可)的,記憶體中的資料結構儲存系統,它可以用作資料庫、快取和訊息中間件。它支援多種類型的資料結構,如字串(strings), 雜湊(hashes), 列表(lists), 集合(sets), 有序集合(sorted sets) 與範圍查詢, bitmaps, hyperloglogs 和地理空間( geospatial) 索引半徑查詢。 Redis 內建了複製(replication),LUA腳本(Lua scripting), LRU驅動事件(LRU eviction),事務(transactions) 和不同級別的磁碟持久化(persistence), 並通過Redis哨兵(Sentinel)和自動分區(Cluster )提供高可用性(high availability)。

單機多實例設定

Redis 支援在同一台主機上運行多個實例, 用來提供不同目的的服務.
透過開放的連接埠號碼來區分, 預設連接埠是6379, 設定檔路徑是:
/etc/redis/redis.conf
如果打算新開一個實例使用6581埠, 那麼拷貝一份設定檔改名為redis-6581.conf
修改裡面與連接埠有關的設定:

port 6581pidfile /var/run/redis/redis-server-6581.pid
unixsocket /var/run/redis/redis-6581.sock
logfile /var/log/redis/redis-server-6581.logdbfilename dump-6581.rdb

需要注意的是, 正常應該使用redis 使用者啟動redis 服務, 表示需要將上述設定檔涉及的目錄權限賦予redis 使用者.

使用redis 使用者啟動新服務的指令是:

# su -l redis --shell=/bin/bash -c '/usr/bin/redis-server /etc/redis/redis-6581.conf'

以下是一個範例設定檔:

# su -l redis --shell=/bin/bash -c '/usr/bin/redis-server /etc/redis/redis-6581.conf'daemonize yes

port 6581pidfile /var/run/redis/redis-server-6581.pid
unixsocket /var/run/redis/redis-6581.sock
logfile /var/log/redis/redis-server-6581.logdbfilename dump-6581.rdb

tcp-backlog 511bind 127.0.0.1unixsocketperm 777timeout 0tcp-keepalive 0loglevel notice
databases 16save ""stop-writes-on-bgsave-error yesrdbcompression yes
dir /var/lib/redis
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5repl-disable-tcp-nodelay no
slave-priority 100appendonly no
appendfilename "appendonly.aof"appendfsync everysec
no-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256
mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yes

            

以上是redis單機開啟多實例的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn