Redis 主從配置

來源:互聯網
上載者:User

標籤:style   color   strong   檔案   資料   io   cti   ar   

redis 主從配置

Master:192.168.209.18

Slave:192.168.209.19

Master:

tar xzvf redis-2.8.12.tar.gz

mv  redis-2.8.12 /usr/local/redis

cd /usr/local/redis

make

cp redis.conf  redis.conf.bak

mkdir /data1/redis_6379

vi redis.conf

 

grep -v "#" redis.conf | tr -s ‘\n‘

設定檔形如:

daemonize yes

# 是否後台運行

pidfile /var/run/redis.pid

#業務連接埠

port 6379

tcp-backlog 511

timeout 0

tcp-keepalive 0

loglevel notice

logfile ""

databases 16

save 900 1

save 300 10

save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename dump.rdb

dir /data1/redis_6379/

# 資料檔案路徑

slave-serve-stale-data yes

slave-read-only yes

repl-disable-tcp-nodelay no

slave-priority 100

appendonly no

appendfilename "appendonly.aof"

appendfsync everysec

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100

auto-aof-rewrite-min-size 64mb

lua-time-limit 5000

slowlog-log-slower-than 10000

slowlog-max-len 128

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 256mb 64mb 60

client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

aof-rewrite-incremental-fsync yes

 

 

 

 

啟動redis

/usr/local/redis/src/redis-server /usr/local/redis/redis.conf

關閉redis

/usr/local/redis/src/redis-cli -n 6379 shutdown

 

redis命令測試

先登入shell用戶端

/usr/local/redis/src/redis-cli -p 6379

 

set 測試

redis 127.0.0.1:6379> set name abc

OK <---成功

 

get 測試

redis 127.0.0.1:6379> get name

"abc"

 

/usr/local/redis/src/redis-cli -p 6379

/usr/local/redis/src/redi-cli -p 6379

 

 

Slave

tar xzvf redis-2.8.12.tar.gz

mv  redis-2.8.12 /usr/local/redis

cd /usr/local/redis

make

cp redis.conf  redis.conf.bak

mkdir /data1/redis_6379

vi redis.conf

 

grep -v "#" redis.conf | tr -s ‘\n‘

設定檔形如:

daemonize yes

pidfile /var/run/redis.pid

port 6379

tcp-backlog 511

timeout 0

tcp-keepalive 0

loglevel notice

logfile ""

databases 16

save 900 1

save 300 10

save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename dump.rdb

dir /data1/redis_6379/

slaveof 192.168.209.18 6379

#slaveof master的ip master的連接埠

slave-serve-stale-data yes

slave-read-only yes

repl-disable-tcp-nodelay no

slave-priority 100

appendonly no

appendfilename "appendonly.aof"

appendfsync everysec

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100

auto-aof-rewrite-min-size 64mb

lua-time-limit 5000

slowlog-log-slower-than 10000

slowlog-max-len 128

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 256mb 64mb 60

client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

aof-rewrite-incremental-fsync yes

 

6.2 主從測試

在master set

redis 192.168.209.18:12002> set testms gogogo

OK

 

在slave get

redis 192.168.209.19:12002> get testms

"gogogo" <---- 擷取到的value

 

 

 

 

===================================

以下為一主多從

直接在master和slave上面,複製主的redis目錄,並修改設定檔,設定檔只需修改port,dir,slaveof三項即可。

cp -rp redis redis_6380

mkdir /data1/redis_6380

cd redis_6380/

vi redis.conf

形如:

daemonize yes

pidfile /var/run/redis.pid

port 6380

tcp-backlog 511

timeout 0

tcp-keepalive 0

loglevel notice

logfile ""

databases 16

save 900 1

save 300 10

save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename dump.rdb

dir /data1/redis_6380/

slaveof 192.168.209.18 6379

slave-serve-stale-data yes

slave-read-only yes

repl-disable-tcp-nodelay no

slave-priority 100

appendonly no

appendfilename "appendonly.aof"

appendfsync everysec

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100

auto-aof-rewrite-min-size 64mb

lua-time-limit 5000

slowlog-log-slower-than 10000

slowlog-max-len 128

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 256mb 64mb 60

client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

aof-rewrite-incremental-fsync yes

==================================

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.