<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Redis

      1、RDB和AOF的優(yōu)缺點(diǎn)

      RDB優(yōu)點(diǎn):

      • RDB快照保存了某個(gè)時(shí)間點(diǎn)的數(shù)據(jù),可以通過(guò)腳本執(zhí)行redis指令bgsave(非阻塞,后臺(tái)執(zhí)行)或者 save(會(huì)阻塞寫(xiě)操作,不推薦)命令自定義時(shí)間點(diǎn)備份,可以保留多個(gè)備份,當(dāng)出現(xiàn)問(wèn)題可以恢復(fù)到不同時(shí)間點(diǎn)的版本,很適合備份,并且此文件格式也支持有不少第三方工具可以進(jìn)行后續(xù)的數(shù)據(jù)分析

        比如: 可以在最近的24小時(shí)內(nèi),每小時(shí)備份一次RDB文件,并且在每個(gè)月的每一天,也備份一個(gè) ROB文件。這樣的話,即使遇上問(wèn)題,也可以隨時(shí)將數(shù)據(jù)集還原到不同的版本。

      • RDB可以最大化Redis的性能,父進(jìn)程在保存 RDB文件時(shí)唯一要做的就是fork出一個(gè)子進(jìn)程,然后 這個(gè)子進(jìn)程就會(huì)處理接下來(lái)的所有保存工作,父進(jìn)程無(wú)須執(zhí)行任何磁盤(pán)工/0操作。

      • RDB在大量數(shù)據(jù),比如幾個(gè)G的數(shù)據(jù),恢復(fù)的速度比AOF的快

      RDB缺點(diǎn):

      • 不能實(shí)時(shí)保存數(shù)據(jù),可能會(huì)丟失自上一次執(zhí)行RDB備份到當(dāng)前的內(nèi)存數(shù)據(jù)

        如果你需要盡量避免在服務(wù)器故障時(shí)丟失數(shù)據(jù),那么RDB不適合你。雖然Redis允許你設(shè)置不同的 保存點(diǎn)(save point)來(lái)控制保存RDB文件的頻率,但是,因?yàn)镽OB文件需要保存整個(gè)數(shù)據(jù)集的狀態(tài),所以它并不是一個(gè)輕松的操作。因此你可能會(huì)至少5分鐘才保存一次RDB文件。在這種情況 下,一旦發(fā)生故障停機(jī),你就可能會(huì)丟失好幾分鐘的數(shù)據(jù)。 (不能保證數(shù)據(jù)一點(diǎn)不丟失)

      • 當(dāng)數(shù)據(jù)量非常大的時(shí)候,從父進(jìn)程fork子進(jìn)程進(jìn)行保存至RDB文件時(shí)需要一點(diǎn)時(shí)間,可能是毫秒或 者秒,取決于磁盤(pán)IO性能

      • 在數(shù)據(jù)集比較龐大時(shí),fork()可能會(huì)非常耗時(shí),造成服務(wù)器在一定時(shí)間內(nèi)停止處理客戶端﹔如果數(shù) 據(jù)集非常巨大,并且CPU時(shí)間非常緊張的話,那么這種停止時(shí)間甚至可能會(huì)長(zhǎng)達(dá)整整一秒或更久。

      • 雖然 AOF重寫(xiě)也需要進(jìn)行fork(),但無(wú)論AOF重寫(xiě)的執(zhí)行間隔有多長(zhǎng),數(shù)據(jù)的持久性都不會(huì)有任何損失。

       

      AOF 優(yōu)點(diǎn):

      • 數(shù)據(jù)安全性相對(duì)較高,根據(jù)所使用的fsync策略(fsync是同步內(nèi)存中redis所有已經(jīng)修改的文件到存 儲(chǔ)設(shè)備),默認(rèn)是appendfsync everysec,即每秒執(zhí)行一次 fsync,在這種配置下,Redis 仍然可以保持良好的性能,并且就算發(fā)生故障停機(jī),也最多只會(huì)丟失一秒鐘的數(shù)據(jù)( fsync會(huì)在后臺(tái)線程執(zhí) 行,所以主線程可以繼續(xù)努力地處理命令請(qǐng)求)

      • 由于該機(jī)制對(duì)日志文件的寫(xiě)入操作采用的是append模式,因此在寫(xiě)入過(guò)程中不需要seek, 即使出現(xiàn)宕機(jī)現(xiàn)象,也不會(huì)破壞日志文件中已經(jīng)存在的內(nèi)容。然而如果本次操作只是寫(xiě)入了一半數(shù)據(jù)就出現(xiàn)了系統(tǒng)崩潰問(wèn)題,不用擔(dān)心,在Redis下一次啟動(dòng)之前,可以通過(guò) redis-check-aof 工具來(lái)解決數(shù)據(jù)一致性的問(wèn)題

      • Redis可以在 AOF文件體積變得過(guò)大時(shí),自動(dòng)地在后臺(tái)對(duì)AOF進(jìn)行重寫(xiě):重寫(xiě)后的新AOF文件包含了恢復(fù)當(dāng)前數(shù)據(jù)集所需的最小命令集合。整個(gè)重寫(xiě)操作是絕對(duì)安全的,因?yàn)镽edis在創(chuàng)建新 AOF文件的過(guò)程中,append模式不斷的將修改數(shù)據(jù)追加到現(xiàn)有的 AOF文件里面,即使重寫(xiě)過(guò)程中發(fā)生停 機(jī),現(xiàn)有的 AOF文件也不會(huì)丟失。而一旦新AOF文件創(chuàng)建完畢,Redis就會(huì)從舊AOF文件切換到新 AOF文件,并開(kāi)始對(duì)新AOF文件進(jìn)行追加操作。

      • AOF包含一個(gè)格式清晰、易于理解的日志文件用于記錄所有的修改操作。事實(shí)上,也可以通過(guò)該文件完成數(shù)據(jù)的重建AOF文件有序地保存了對(duì)數(shù)據(jù)庫(kù)執(zhí)行的所有寫(xiě)入操作,這些寫(xiě)入操作以Redis協(xié)議的格式保存,因此 AOF文件的內(nèi)容非常容易被人讀懂,對(duì)文件進(jìn)行分析(parse)也很輕松。導(dǎo)出(export)AOF文件 也非常簡(jiǎn)單:舉個(gè)例子,如果你不小心執(zhí)行了FLUSHALL.命令,但只要AOF文件未被重寫(xiě),那么只 要停止服務(wù)器,移除 AOF文件末尾的FLUSHAL命令,并重啟Redis ,就可以將數(shù)據(jù)集恢復(fù)到 FLUSHALL執(zhí)行之前的狀態(tài)。

      AOF缺點(diǎn):

      • 即使有些操作是重復(fù)的也會(huì)全部記錄,AOF 的文件大小要大于 RDB 格式的文件

      • AOF 在恢復(fù)大數(shù)據(jù)集時(shí)的速度比 RDB 的恢復(fù)速度要慢

      • 根據(jù)fsync策略不同,AOF速度可能會(huì)慢于RDB

      • bug 出現(xiàn)的可能性更多


      2、master和slave同步過(guò)程

      復(fù)制代碼
      環(huán)境:
      兩臺(tái)機(jī)器
      10.0.0.8       master
      10.0.0.18     slave

      #兩臺(tái)機(jī)器安裝redis服務(wù)并啟動(dòng)
      [root@centos8 ~]#yum -y install redis
      [root@centos8 ~]#systemctl start redis
      [root@centos18 ~]#yum -y install redis
      [root@centos18 ~]#systemctl start redis
      #主節(jié)點(diǎn)進(jìn)行配置
      [root@centos8 ~]#vim /etc/redis.conf
      69 bind 0.0.0.0
      88 protected-mode yes
      308 replica-serve-stale-data yes
      324 replica-read-only yes
      355 repl-diskless-sync no
      367 repl-diskless-sync-delay 5
      #設(shè)置連接密碼
      [root@centos8 ~]#redis-cli
      127.0.0.1:6379> CONFIG SET requirepass 123456
      OK
      #重啟服務(wù)
      [root@centos8 ~]#systemctl restart redis
      #從節(jié)點(diǎn)進(jìn)行設(shè)置
      #查看是否能夠遠(yuǎn)程連接10.0.0.8
      [root@centos18 ~]#redis-cli -h 10.0.0.8 -a 123456
      Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
      10.0.0.8:6379>
      #搭建主從節(jié)點(diǎn)
      #登錄本機(jī),輸入主服務(wù)器的IP和端口號(hào)
      #在slave上設(shè)置master的IP和端口,4.0版之前的指令為slaveof
      127.0.0.1:6379> REPLICAOF 10.0.0.8 6379 #仍可使用SLAVEOF MasterIP Port
      OK
      #輸入主服務(wù)器的密碼進(jìn)行同步,進(jìn)行全量復(fù)制
      #在slave上設(shè)置master的密碼,才可以同步
      127.0.0.1:6379> CONFIG SET masterauth 123456
      OK
      127.0.0.1:6379> INFO replication
      # Replication   #角色變?yōu)閟lave
      role:slave
      master_host:10.0.0.8   #指向master
      master_port:6379
      master_link_status:up
      master_last_io_seconds_ago:8
      master_sync_in_progress:0
      slave_repl_offset:42
      slave_priority:100
      slave_read_only:1
      connected_slaves:0
      master_replid:b69908f23236fb20b810d198f7f4539f795e0ee5
      master_replid2:0000000000000000000000000000000000000000
      master_repl_offset:42
      second_repl_offset:-1
      repl_backlog_active:1
      repl_backlog_size:1048576
      repl_backlog_first_byte_offset:1
      repl_backlog_histlen:42
      #在所有slave節(jié)點(diǎn)保存配置到redis.conf
      [root@centos18 ~]#vim /etc/redis.conf
       .......
      # replicaof <masterip> <masterport>
      replicaof 10.0.0.8 6379 #指定master的IP和端口號(hào)
      # If the master is password protected (using the "requirepass" configuration
      # directive below) it is possible to tell the replica to authenticate before
      # starting the replication synchronization process, otherwise the master will
      # refuse the replica request.
      # masterauth <master-password>
      masterauth 123456     #如果密碼需要設(shè)置
      .......

      注:主從搭建完畢,搭建成功,從節(jié)點(diǎn)只能讀不能寫(xiě)
      復(fù)制代碼

       

      3、哨兵的使用和實(shí)現(xiàn)機(jī)制

      #前提是已經(jīng)實(shí)現(xiàn)了一主兩從的搭建

       
      環(huán)境
      
      master      10.0.0.8
      
      slave1        10.0.0.18
      
      slave2         10.0.0.28
      
      
      
      #搭建一主兩從
      #三臺(tái)機(jī)器安裝redis服務(wù)并啟動(dòng)
      [root@centos8 ~]#yum -y install redis
      [root@centos8 ~]#systemctl start redis
      
      [root@centos18 ~]#yum -y install redis
      [root@centos18 ~]#systemctl start redis
      
      [root@centos28 ~]#yum -y install redis
      [root@centos28 ~]#systemctl start redis
      
      #主節(jié)點(diǎn)進(jìn)行配置
      [root@centos8 ~]#vim /etc/redis.conf
      69 bind 0.0.0.0
      88 protected-mode yes
      308 replica-serve-stale-data yes
      
      324 replica-read-only yes
      
      355 repl-diskless-sync no
      
      367 repl-diskless-sync-delay 5
      
      #設(shè)置連接密碼
      
      [root@centos8 ~]#redis-cli
      127.0.0.1:6379> CONFIG SET requirepass 123456
      OK
      #重啟服務(wù)
      [root@centos8 ~]#systemctl restart redis
      #從節(jié)點(diǎn)進(jìn)行設(shè)置
      
      #查看是否能夠遠(yuǎn)程連接10.0.0.8
      [root@centos18 ~]#redis-cli -h 10.0.0.8 -a 123456
      Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
      10.0.0.8:6379> 
      #搭建主從節(jié)點(diǎn)
      #登錄本機(jī),輸入主服務(wù)器的IP和端口號(hào)
      #在slave上設(shè)置master的IP和端口,4.0版之前的指令為slaveof 
      127.0.0.1:6379> REPLICAOF 10.0.0.8 6379 #仍可使用SLAVEOF MasterIP Port
      OK
      #輸入主服務(wù)器的密碼進(jìn)行同步,進(jìn)行全量復(fù)制
      #在slave上設(shè)置master的密碼,才可以同步
      127.0.0.1:6379> CONFIG SET masterauth 123456
      OK
      127.0.0.1:6379> INFO replication
      # Replication   #角色變?yōu)閟lave
      role:slave
      master_host:10.0.0.8   #指向master
      master_port:6379
      master_link_status:up
      master_last_io_seconds_ago:8
      master_sync_in_progress:0
      slave_repl_offset:42
      slave_priority:100
      slave_read_only:1
      connected_slaves:0
      master_replid:b69908f23236fb20b810d198f7f4539f795e0ee5
      master_replid2:0000000000000000000000000000000000000000
      master_repl_offset:42
      second_repl_offset:-1
      repl_backlog_active:1
      repl_backlog_size:1048576
      repl_backlog_first_byte_offset:1
      repl_backlog_histlen:42
      
      #在所有slave節(jié)點(diǎn)保存配置到redis.conf
      [root@centos18 ~]#vim /etc/redis.conf 
       .......
      # replicaof <masterip> <masterport>
      replicaof 10.0.0.8 6379 #指定master的IP和端口號(hào)
      # If the master is password protected (using the "requirepass" configuration
      # directive below) it is possible to tell the replica to authenticate before
      # starting the replication synchronization process, otherwise the master will
      # refuse the replica request.
      # masterauth <master-password>
      masterauth 123456     #如果密碼需要設(shè)置
      .......
      
      #查看是否能夠遠(yuǎn)程連接10.0.0.8
      [root@centos28 ~]#redis-cli -h 10.0.0.8 -a 123456
      Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
      10.0.0.8:6379> 
      #搭建主從節(jié)點(diǎn)
      #登錄本機(jī),輸入主服務(wù)器的IP和端口號(hào)
      #在slave上設(shè)置master的IP和端口,4.0版之前的指令為slaveof 
      127.0.0.1:6379> REPLICAOF 10.0.0.8 6379 #仍可使用SLAVEOF MasterIP Port
      OK
      #輸入主服務(wù)器的密碼進(jìn)行同步,進(jìn)行全量復(fù)制
      #在slave上設(shè)置master的密碼,才可以同步
      127.0.0.1:6379> CONFIG SET masterauth 123456
      OK
      127.0.0.1:6379> INFO replication
      # Replication   #角色變?yōu)閟lave
      role:slave
      master_host:10.0.0.8   #指向master
      master_port:6379
      master_link_status:up
      master_last_io_seconds_ago:8
      master_sync_in_progress:0
      slave_repl_offset:42
      slave_priority:100
      slave_read_only:1
      connected_slaves:0
      master_replid:b69908f23236fb20b810d198f7f4539f795e0ee5
      master_replid2:0000000000000000000000000000000000000000
      master_repl_offset:42
      second_repl_offset:-1
      repl_backlog_active:1
      repl_backlog_size:1048576
      repl_backlog_first_byte_offset:1
      repl_backlog_histlen:42
      
      #在所有slave節(jié)點(diǎn)保存配置到redis.conf
      [root@centos28 ~]#vim /etc/redis.conf 
       .......
      # replicaof <masterip> <masterport>
      replicaof 10.0.0.8 6379 #指定master的IP和端口號(hào)
      # If the master is password protected (using the "requirepass" configuration
      # directive below) it is possible to tell the replica to authenticate before
      # starting the replication synchronization process, otherwise the master will
      # refuse the replica request.
      # masterauth <master-password>
      masterauth 123456     #如果密碼需要設(shè)置
      .......
      
      
      #所有主從節(jié)點(diǎn)的redis.conf中關(guān)鍵配置
      #三臺(tái)機(jī)器全部配置成以下三步
      [root@centos8 ~]#vim /etc/redis.conf
      bind 0.0.0.0
      masterauth "123456"
      requirepass "123456"
      [root@centos8 ~]#systemctl restart redis
      
      [root@centos18 ~]#vim /etc/redis.conf
      bind 0.0.0.0
      masterauth "123456"
      requirepass "123456"
      [root@centos18 ~]#systemctl restart redis
      
      [root@centos28 ~]#vim /etc/redis.conf
      bind 0.0.0.0
      masterauth "123456"
      requirepass "123456"
      [root@centos18 ~]#systemctl restart redis
      
      #三個(gè)哨兵服務(wù)器的配置如下
      [root@centos8 ~]#grep -vE "^#|^$" /etc/redis-sentinel.conf
      port 26379
      daemonize no
      pidfile "/var/run/redis-sentinel.pid"
      logfile "/var/log/redis/sentinel.log"
      dir "/tmp"
      sentinel monitor mymaster 10.0.0.8 6379 2   #修改此行
      sentinel auth-pass mymaster 123456 #增加此行
      sentinel down-after-milliseconds mymaster 3000   #修改此行
      sentinel parallel-syncs mymaster 1
      sentinel failover-timeout mymaster 180000
      sentinel deny-scripts-reconfig yes
      
      #以下內(nèi)容自動(dòng)生成,不需要修改
      sentinel myid 50547f34ed71fd48c197924969937e738a39975b  #此行每個(gè)哨兵主機(jī)自動(dòng)生成,且必須唯一
      .....
      # Generated by CONFIG REWRITE
      protected-mode no
      supervised systemd
      sentinel leader-epoch mymaster 0
      sentinel known-replica mymaster 10.0.0.28 6379
      sentinel known-replica mymaster 10.0.0.18 6379
      sentinel current-epoch 0
      
      [root@centos8 ~]#scp /etc/redis-sentinel.conf redis-slave1:/etc/
      [root@centos8 ~]#scp /etc/redis-sentinel.conf redis-slave2:/etc/
      
      #三臺(tái)哨兵服務(wù)器都要啟動(dòng)
      ###確保每個(gè)哨兵主機(jī)myid不同!!!
      [root@centos18 ~]#vim /etc/redis-sentinel.conf
      sentinel myid 50547f34ed71fd48c197924969937e738a39975c 
      [root@centos28 ~]#vim /etc/redis-sentinel.conf
      sentinel myid 50547f34ed71fd48c197924969937e738a39975d
      
      [root@centos8 ~]#systemctl enable --now redis-sentinel.service
      [root@centos18 ~]#systemctl enable --now redis-sentinel.service
      [root@centos28 ~]#systemctl enable --now redis-sentinel.service
       

       


      4、redis cluster集群創(chuàng)建和使用

       #此實(shí)驗(yàn)部署的是基于Redis 5 的redis cluster  

      復(fù)制代碼
      #環(huán)境
      10.0.0.8
      10.0.0.18
      10.0.0.28
      10.0.0.38
      10.0.0.48
      10.0.0.58
      
      注:
      1. 每個(gè)redis 節(jié)點(diǎn)采用相同的硬件配置、相同的密碼、相同的redis版本 
      2. 所有redis服務(wù)器必須沒(méi)有任何數(shù)據(jù) 
      3. 先啟動(dòng)為單機(jī)redis且沒(méi)有任何key value 

      #配置

      1.####以下內(nèi)容六臺(tái)機(jī)器均需要執(zhí)行,在此只寫(xiě)出在一臺(tái)機(jī)器上的執(zhí)行過(guò)程,其余參考第一臺(tái)機(jī)器的執(zhí)行過(guò)程進(jìn)行執(zhí)行####
      [root@centos8 ~]#dnf -y install redis
      #批量修改配置文件
      [root@centos8 ~]#sed -i.bak -e 's/bind 127.0.0.1/bind 0.0.0.0/' -e '/masterauth/a masterauth 123456' -e '/# requirepass/a requirepass 123456' -e '/# cluster-enabled yes/a cluster-enabled yes' -e '/# cluster-config-file nodes-6379.conf/a cluster-config-file nodes-6379.conf' -e '/cluster-require-full-coverage yes/c cluster-require-full-coverage no' /etc/redis.conf
      [root@centos8 ~]#systemctl enable --now  redis

      2.#創(chuàng)建集群
      # --cluster-replicas 1 表示每個(gè)master對(duì)應(yīng)一個(gè)slave節(jié)點(diǎn)
      [root@centos8 ~]#redis-cli -a 123456 --cluster create 10.0.0.8:6379 10.0.0.18:6379 10.0.0.28:6379 10.0.0.38:6379 10.0.0.48:6379 10.0.0.58:6379 --cluster-replicas 1

      3.#六臺(tái)機(jī)器分別查看主從狀態(tài),在此也是只寫(xiě)出一臺(tái)機(jī)器的執(zhí)行狀態(tài)
      [root@centos8 ~]#redis-cli -a 123456 -c INFO replication
      Warning: Using a password with '-a' or '-u' option on the command line interface
      may not be safe.
      # Replication
      role:master
      connected_slaves:1
      slave0:ip=10.0.0.38,port=6379,state=online,offset=896,lag=1
      master_replid:3a388865080d779180ff240cb75766e7e57877da
      master_replid2:0000000000000000000000000000000000000000
      master_repl_offset:896
      second_repl_offset:-1
      repl_backlog_active:1
      repl_backlog_size:1048576
      repl_backlog_first_byte_offset:1
      repl_backlog_histlen:896

      4.#查看指定master節(jié)點(diǎn)的slave節(jié)點(diǎn)的信息
      [root@centos8 ~]#redis-cli -a 123456 cluster nodes
      4f146b1ac51549469036a272c60ea97f065ef832 10.0.0.28:6379@16379 master - 0
      1602571565772 12 connected 10923-16383
      779a24884dbe1ceb848a685c669ec5326e6c8944 10.0.0.48:6379@16379 slave
      97c5dcc3f33c2fc75c7fdded25d05d2930a312c0 0 1602571565000 11 connected
      97c5dcc3f33c2fc75c7fdded25d05d2930a312c0 10.0.0.18:6379@16379 master - 0
      1602571564000 11 connected 5462-10922
      07231a50043d010426c83f3b0788e6b92e62050f 10.0.0.58:6379@16379 slave
      4f146b1ac51549469036a272c60ea97f065ef832 0 1602571565000 12 connected
      a177c5cbc2407ebb6230ea7e2a7de914bf8c2dab 10.0.0.8:6379@16379 myself,master - 0
      1602571566000 10 connected 0-5461
      cb20d58870fe05de8462787cf9947239f4bc5629 10.0.0.38:6379@16379 slave
      a177c5cbc2407ebb6230ea7e2a7de914bf8c2dab 0 1602571566780 10 connected
       
      #以下命令查看指定master節(jié)點(diǎn)的slave節(jié)點(diǎn)信息,其中
      #a177c5cbc2407ebb6230ea7e2a7de914bf8c2dab 為master節(jié)點(diǎn)的ID
      [root@centos8 ~]#redis-cli -a 123456 cluster slaves a177c5cbc2407ebb6230ea7e2a7de914bf8c2dab
      1) "cb20d58870fe05de8462787cf9947239f4bc5629 10.0.0.38:6379@16379 slave
      a177c5cbc2407ebb6230ea7e2a7de914bf8c2dab 0 1602571574844 10 connected"
      5.#驗(yàn)證集群狀態(tài)
      [root@centos8 ~]#
      redis-cli -a 123456 CLUSTER INFO
      Warning: Using a password with '-a' or '-u' option on the command line interface
      may not be safe.
      cluster_state:ok
      cluster_slots_assigned:16384
      cluster_slots_ok:16384
      cluster_slots_pfail:0
      cluster_slots_fail:0
      cluster_known_nodes:6  #節(jié)點(diǎn)數(shù)
      cluster_size:3                        #三個(gè)集群
      cluster_current_epoch:6
      cluster_my_epoch:1
      cluster_stats_messages_ping_sent:837
      cluster_stats_messages_pong_sent:811
      cluster_stats_messages_sent:1648
      cluster_stats_messages_ping_received:806
      cluster_stats_messages_pong_received:837
      cluster_stats_messages_meet_received:5
      cluster_stats_messages_received:1648
      #查看任意節(jié)點(diǎn)的集群狀態(tài)
      [root@centos8 ~]#redis-cli -a 123456 --cluster info 10.0.0.38:6379
      Warning: Using a password with '-a' or '-u' option on the command line interface
      may not be safe.
      10.0.0.18:6379 (99720241...) -> 0 keys | 5462 slots | 1 slaves.
      10.0.0.28:6379 (d34da866...) -> 0 keys | 5461 slots | 1 slaves.
      10.0.0.8:6379 (cb028b83...) -> 0 keys | 5461 slots | 1 slaves.
      [OK] 0 keys in 3 masters.
      0.00 keys per slot on average.
       
      6.#查看集群node對(duì)應(yīng)關(guān)系
      [root@redis-node1 ~]#redis-cli -a 123456 CLUSTER NODES
      Warning: Using a password with '-a' or '-u' option on the command line interface
      may not be safe.
      9875b50925b4e4f29598e6072e5937f90df9fc71 10.0.0.58:6379@16379 slave
      d34da8666a6f587283a1c2fca5d13691407f9462 0 1582344815790 6 connected
      f9adcfb8f5a037b257af35fa548a26ffbadc852d 10.0.0.38:6379@16379 slave
      cb028b83f9dc463d732f6e76ca6bbcd469d948a7 0 1582344811000 4 connected
      d04e524daec4d8e22bdada7f21a9487c2d3e1057 10.0.0.48:6379@16379 slave
      99720241248ff0e4c6fa65c2385e92468b3b5993 0 1582344815000 5 connected
      99720241248ff0e4c6fa65c2385e92468b3b5993 10.0.0.18:6379@16379 master - 0
      1582344813000 2 connected 5461-10922
      d34da8666a6f587283a1c2fca5d13691407f9462 10.0.0.28:6379@16379 master - 0
      1582344814780 3 connected 10923-16383
      cb028b83f9dc463d732f6e76ca6bbcd469d948a7 10.0.0.8:6379@16379 myself,master - 0
      1582344813000 1 connected 0-5460
      [root@redis-node1 ~]#redis-cli -a 123456 --cluster check 10.0.0.38:6379
      Warning: Using a password with '-a' or '-u' option on the command line interface
      may not be safe.
      10.0.0.18:6379 (99720241...) -> 0 keys | 5462 slots | 1 slaves.
      10.0.0.28:6379 (d34da866...) -> 0 keys | 5461 slots | 1 slaves.
      10.0.0.8:6379 (cb028b83...) -> 0 keys | 5461 slots | 1 slaves.
      [OK] 0 keys in 3 masters.
      0.00 keys per slot on average.
      >>> Performing Cluster Check (using node 10.0.0.38:6379)
      S: f9adcfb8f5a037b257af35fa548a26ffbadc852d 10.0.0.38:6379
         slots: (0 slots) slave
         replicates cb028b83f9dc463d732f6e76ca6bbcd469d948a7
      S: d04e524daec4d8e22bdada7f21a9487c2d3e1057 10.0.0.48:6379
         slots: (0 slots) slave
         replicates 99720241248ff0e4c6fa65c2385e92468b3b5993
         M: 99720241248ff0e4c6fa65c2385e92468b3b5993 10.0.0.18:6379
         slots:[5461-10922] (5462 slots) master
         1 additional replica(s)
      S: 9875b50925b4e4f29598e6072e5937f90df9fc71 10.0.0.58:6379
         slots: (0 slots) slave
         replicates d34da8666a6f587283a1c2fca5d13691407f9462
      M: d34da8666a6f587283a1c2fca5d13691407f9462 10.0.0.28:6379
         slots:[10923-16383] (5461 slots) master
         1 additional replica(s)
      M: cb028b83f9dc463d732f6e76ca6bbcd469d948a7 10.0.0.8:6379
         slots:[0-5460] (5461 slots) master
         1 additional replica(s)
      [OK] All nodes agree about slots configuration.
      >>> Check for open slots...
      >>> Check slots coverage...
      [OK] All 16384 slots covered.
       
      7.#驗(yàn)證集群寫(xiě)入key
      #經(jīng)過(guò)算法計(jì)算,當(dāng)前key的槽位需要寫(xiě)入指定的node
      [root@redis-node1 ~]#redis-cli -a 123456 -h 10.0.0.8 SET key1 values1
      Warning: Using a password with '-a' or '-u' option on the command line interface
      may not be safe.
      (error) MOVED 9189 10.0.0.18:6379    #槽位不在當(dāng)前node所以無(wú)法寫(xiě)入
      [root@redis-node1 ~]#redis-cli -a 123456 -h 10.0.0.18 SET key1 values1
      Warning: Using a password with '-a' or '-u' option on the command line interface
      may not be safe.
      OK
      #指定node可寫(xiě)入
      [root@redis-node1 ~]#redis-cli -a 123456 -h 10.0.0.18 GET key1
      Warning: Using a password with '-a' or '-u' option on the command line interface
      may not be safe.
      "values1"
      #對(duì)應(yīng)的slave節(jié)點(diǎn)可以KEYS *,但GET key1失敗,可以到master上執(zhí)行GET key1
      [root@redis-node1 ~]#redis-cli -a 123456 -h 10.0.0.48 KEYS "*"
      Warning: Using a password with '-a' or '-u' option on the command line interface
      may not be safe.
      1) "key1"
      [root@redis-node1 ~]#redis-cli -a 123456 -h 10.0.0.48 GET key1
      Warning: Using a password with '-a' or '-u' option on the command line interface
      may not be safe.
      (error) MOVED 9189 10.0.0.18:6379
       
      #redis cluster 計(jì)算key 所有slot
      [root@centos8 ~]#redis-cli -h 10.0.0.8 -a 123456 --no-auth-warning cluster nodes
      4f146b1ac51549469036a272c60ea97f065ef832 10.0.0.28:6379@16379 master - 0
      1602561649000 12 connected 10923-16383
      779a24884dbe1ceb848a685c669ec5326e6c8944 10.0.0.48:6379@16379 slave
      97c5dcc3f33c2fc75c7fdded25d05d2930a312c0 0 1602561648000 11 connected
      97c5dcc3f33c2fc75c7fdded25d05d2930a312c0 10.0.0.18:6379@16379 master - 0
      1602561650000 11 connected 5462-10922
      07231a50043d010426c83f3b0788e6b92e62050f 10.0.0.58:6379@16379 slave
      4f146b1ac51549469036a272c60ea97f065ef832 0 1602561650229 12 connected
      a177c5cbc2407ebb6230ea7e2a7de914bf8c2dab 10.0.0.8:6379@16379 myself,master - 0
      1602561650000 10 connected 0-5461
      cb20d58870fe05de8462787cf9947239f4bc5629 10.0.0.38:6379@16379 slave
      a177c5cbc2407ebb6230ea7e2a7de914bf8c2dab 0 1602561651238 10 connected
      #計(jì)算得到hello對(duì)應(yīng)的slot
      [root@centos8 ~]#redis-cli -h 10.0.0.8 -a 123456 --no-auth-warning cluster keyslot hello
      (integer) 866
      [root@centos8 ~]#redis-cli -h 10.0.0.8 -a 123456 --no-auth-warning set hello magedu
      OK
      [root@centos8 ~]#redis-cli -h 10.0.0.8 -a 123456 --no-auth-warning cluster keyslot name
      (integer) 5798
      [root@centos8 ~]#redis-cli -h 10.0.0.8 -a 123456 --no-auth-warning set name wang
      (error) MOVED 5798 10.0.0.18:6379
      [root@centos8 ~]#redis-cli -h 10.0.0.18 -a 123456 --no-auth-warning set name wang
      OK
      [root@centos8 ~]#redis-cli -h 10.0.0.18 -a 123456 --no-auth-warning get name
      "wang"
      [root@centos8 ~]#redis-cli -c -h 10.0.0.8 -a 123456 --no-auth-warning
      10.0.0.8:6379> cluster keyslot linux
      (integer) 12299
      10.0.0.8:6379> set linux love
      -> Redirected to slot [12299] located at 10.0.0.28:6379
      OK
      10.0.0.28:6379> get linux
      "love"
      10.0.0.28:6379> exit
      [root@centos8 ~]#redis-cli -h 10.0.0.28 -a 123456 --no-auth-warning get linux
      "love"
       
      8.#用python腳本實(shí)現(xiàn)Redis Cluster集群寫(xiě)入
      [root@centos8 ~]#dnf -y install python3
      [root@centos8 ~]#pip3 install redis-py-cluster
      [root@centos8 ~]#vim redis_cluster_test.py
      [root@centos8 ~]#cat ./redis_cluster_test.py
      #!/usr/bin/env python3
      from rediscluster  import RedisCluster
      startup_nodes = [
         {"host":"10.0.0.8", "port":6379},
         {"host":"10.0.0.18", "port":6379},
         {"host":"10.0.0.28", "port":6379},
         {"host":"10.0.0.38", "port":6379},
         {"host":"10.0.0.48", "port":6379},
         {"host":"10.0.0.58", "port":6379} ]
      redis_conn= RedisCluster(startup_nodes=startup_nodes,password='123456',
      decode_responses=True)
      for i in range(0, 10000):
          redis_conn.set('key'+str(i),'value'+str(i))
          print('key'+str(i)+':',redis_conn.get('key'+str(i)))
      [root@centos8 ~]#chmod +x redis_cluster_test.py
      [root@centos8 ~]#./redis_cluster_test.py
      ......
      key9998: value9998
      key9999: value9999
      [root@centos8 ~]#redis-cli -a 123456 -h 10.0.0.8
      Warning: Using a password with '-a' or '-u' option on the command line interface
      may not be safe.
      10.0.0.8:6379> DBSIZE
      (integer) 3331
      10.0.0.8:6379> GET key1
      (error) MOVED 9189 10.0.0.18:6379
      10.0.0.8:6379> GET key2
      "value2"
      10.0.0.8:6379> GET key3
      "value3"
      10.0.0.8:6379> KEYS *
      ......
      3329) "key7832"
      3330) "key2325"
      3331) "key2880"
      10.0.0.8:6379>
      [root@centos8 ~]#redis-cli -a 123456 -h 10.0.0.18 DBSIZE
      Warning: Using a password with '-a' or '-u' option on the command line interface
      may not be safe. (integer) 3340
      [root@centos8 ~]#redis-cli -a 123456 -h 10.0.0.18 GET key1
      Warning: Using a password with '-a' or '-u' option on the command line interface
      may not be safe.
      "value1"
      [root@centos8 ~]#redis-cli -a 123456 -h 10.0.0.28 DBSIZE
      Warning: Using a password with '-a' or '-u' option on the command line interface
      may not be safe.
      (integer) 3329
      [root@centos8 ~]#redis-cli -a 123456 -h 10.0.0.18 GET key5
      Warning: Using a password with '-a' or '-u' option on the command line interface
      may not be safe.
      "value5"
      [root@centos8 ~]#
      posted @ 2020-10-25 18:42  肖豪  閱讀(204)  評(píng)論(0)    收藏  舉報(bào)
      主站蜘蛛池模板: 国内极度色诱视频网站| 福利视频一区二区在线| 欧美成人精品三级网站| 成人午夜免费无码视频在线观看 | 开心激情站开心激情网六月婷婷| 国产av不卡一区二区| 九九综合九色综合网站| 麻豆麻豆麻豆麻豆麻豆麻豆| 男女xx00上下抽搐动态图| 99在线小视频| 久久精品国产一区二区蜜芽| 高清有码国产一区二区| 日韩亚洲国产中文字幕欧美| 人人爽人人澡人人人妻| 亚洲AV无码成H人动漫无遮挡| 精品国产大片中文字幕| 免费人妻无码不卡中文18禁| 九九热在线精品视频99| 成人午夜大片免费看爽爽爽| 日韩精品成人一区二区三区| 亚洲精品专区在线观看| 免费看成人毛片无码视频| 久热re这里精品视频在线6| 中文字幕在线视频不卡一区二区| 免费a级毛片18以上观看精品| 精品偷拍被偷拍在线观看| 国产午夜精品福利视频| 国产色无码专区在线观看| www夜插内射视频网站| 久久波多野结衣av| 激情综合网激情五月俺也去| 狠狠亚洲色一日本高清色| 欧美丰满熟妇hdxx| 亚洲国产精品老熟女乱码| 国产精品中文字幕日韩| 久女女热精品视频在线观看| 欧美激欧美啪啪片| 天天影视色香欲综合久久| 性欧美欧美巨大69| 国产精品亚洲中文字幕| 亚洲国产精品久久久天堂麻豆宅男|