這篇文章主要介紹了關於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.pidunixsocket /var/run/redis/redis-6581.socklogfile /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