1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務時間:8:30-17:00
      你可能遇到了下面的問題
      關閉右側工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      redis安裝和主從復制、主從切換的使用方法

      安裝redis

      下載redis源碼,并進行相關操作,如下:
      wget http://download.redis.io/releases/redis-3.2.3.tar.gz
      解壓安裝redis
      [root@redis ~]# tar zxf redis-3.2.3.tar.gz
      解壓完畢后,現(xiàn)在開始安裝,如下:
      [root@redis ~]# cd redis-3.2.3/
      [root@redis redis-3.2.3]# make&& make install
      通過上圖,我們可以很容易的看出,redis安裝到
      /usr/local,/usr/local/bin,/usr/local/share,/usr/local/include,/usr/local/lib,/usr/l
      ocal/share/man目錄下。
      然后再切換到utils目錄下,執(zhí)行redis初始化腳本install_server.sh,如下:
      [root@redis redis-3.2.3]# cd utils/
      [root@redisutils]# ./install_server.sh
      Welcome to the redis service installer
      This script will help you easily set up a running redis server
      Please select the redis port for this instance: [6379]
      Selecting default: 6379
      Please select the redisconfig file name [/etc/redis/6379.conf]
      Selected default - /etc/redis/6379.conf
      Please select the redis log file name [/var/log/redis_6379.log]
      Selected default - /var/log/redis_6379.log
      Please select the data directory for this instance [/var/lib/redis/6379]
      Selected default - /var/lib/redis/6379
      Please select the redis executable path [/usr/local/bin/redis-server]
      Selected config:
      Port : 6379
      Config file : /etc/redis/6379.conf
      Log file : /var/log/redis_6379.log
      Data dir : /var/lib/redis/6379
      Executable : /usr/local/bin/redis-server
      CliExecutable : /usr/local/bin/redis-cli
      Is this ok? Then press ENTER to go on or Ctrl-C to abort.
      Copied /tmp/6379.conf => /etc/init.d/redis_6379
      Installing service...
      Successfully added to chkconfig!
      Successfully added to runlevels 345!
      Starting Redis server...
      Installation successful!
      通過上面的安裝過程,我們可以看出redis初始化后redis配置文件為
      /etc/redis/6379.conf,日志文件為/var/log/redis_6379.log,數(shù)據(jù)文件dump.rdb存
      放到/var/lib/redis/6379目錄下,啟動腳本為/etc/init.d/redis_6379。
      現(xiàn)在我們要使用systemd,所以在 /etc/systems/system 下創(chuàng)建一個單位文件名字
      為 redis_6379.service。
      [root@redisutils]# vi /etc/systemd/system/redis_6379.service
      內容如下:
      [Unit]
      Description=Redis on port 6379
      [Service]
      Type=forking
      ExecStart=/etc/init.d/redis_6379 start
      ExecStop=/etc/init.d/redis_6379 stop
      [Install]
      WantedBy=multi-user.target

      注:這里Type=forking是后臺運行的形式
      啟動redis
      [root@redisutils]# systemctl daemon-reload
      [root@redisutils]# systemctl enable redis_6379.service
      [root@redisutils]# systemctl start redis_6379.service
      [root@redisutils]# systemctl status redis_6379.service
      ● redis_6379.service - Redis on port 6379
      Loaded: loaded (/etc/systemd/system/redis_6379.service; enabled; vendor preset: disabled)
      Active: active (running) since Wed 2016-11-16 21:07:26 CST; 4min 25s ago
      Process: 7732 ExecStart=/etc/init.d/redis_6379 start (code=exited, status=0/SUCCESS)
      Main PID: 7734 (redis-server)
      CGroup: /system.slice/redis_6379.service
      └─7734 /usr/local/bin/redis-server 127.0.0.1:6379
      Nov 16 21:07:26 redissystemd[1]: Starting Redis on port 6379...
      Nov 16 21:07:26 redis redis_6379[7732]: Starting Redis server...
      Nov 16 21:07:26 redissystemd[1]: Started Redis on port 6379.
      [root@redisutils]# netstat -anpt | grep 6379
      tcp 0 0 127.0.0.1:6379 0.0.0.0: LISTEN 7734/redis-server 1
      從顯示結果可以看到redis默認監(jiān)聽的是127.0.0.1的6379端口
      防火墻規(guī)則設置
      [root@redisutils]# firewall-cmd --permanent --add-port=6379/tcp
      success
      [root@redisutils]# firewall-cmd --reload
      success
      現(xiàn)在來查看redis版本使用redis-cli –version命令,如下
      [root@redisutils]# redis-cli --version
      redis-cli 3.2.3
      通過顯示結果,我們可以看到redis版本是3.2.3。
      到此源碼方式安裝redis就介紹完畢。
      redis安裝完畢之后,我們再來配置redis
      設置redis監(jiān)聽的地址,添加監(jiān)聽redis主機的ip
      考慮到安全性,我們需要啟用redis的密碼驗證功能requirepass參數(shù)
      最終redis配置文件如下:
      [root@redis ~]# grep -Ev '^#|^$' /etc/redis/6379.conf (標粗部分為修改內容)
      bind 127.0.0.1 192.168.31.106
      protected-mode yes
      port 6379
      tcp-backlog 511
      timeout 0
      tcp-keepalive 300
      daemonize yes
      supervised no
      pidfile /var/run/redis6379.pid
      loglevel notice
      logfile /var/log/redis6379.log
      databases 16
      save 900 1
      save 300 10
      save 60 10000
      stop-writes-on-bgsave-error yes
      rdbcompression yes
      rdbchecksum yes
      dbfilenamedump.rdb
      dir /var/lib/redis/6379
      slave-serve-stale-data yes
      slave-read-only yes
      repl-diskless-sync no
      repl-diskless-sync-delay 5
      repl-disable-tcp-nodelay no
      slave-priority 100
      requirepass pwd@123 此項為密碼
      appendonly no
      appendfilename "appendonly.aof"
      appendfsynceverysec
      no-appendfsync-on-rewrite no
      auto-aof-rewrite-percentage 100
      auto-aof-rewrite-min-size 64mb
      aof-load-truncated yes
      lua-time-limit 5000
      slowlog-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-size -2
      list-compress-depth 0
      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-limitpubsub 32mb 8mb 60
      hz 10
      aof-rewrite-incremental-fsync yes
      重新啟動redis服務
      [root@redis ~]# systemctl restart redis6379.service
      [root@redis ~]# netstat -anpt | grep redis
      tcp 0 0 192.168.31.106:6379 0.0.0.0:
      LISTEN 8418/redis-server 1
      Redis 命令
      Redis 命令用于在 redis 服務上執(zhí)行操作。
      要在 redis 服務上執(zhí)行命令需要一個 redis 客戶端。Redis 客戶端在我們之前下載的的
      redis 的安裝包中。
      語法
      Redis 客戶端的基本語法為:
      $ redis-cli
      實例
      以下實例講解了如何啟動 redis 客戶端:
      啟動 redis 客戶端,打開終端并輸入命令 redis-cli。該命令會連接本地的 redis 服務。
      $redis-cli
      redis 127.0.0.1:6379>
      redis 127.0.0.1:6379> PING
      PONG
      在以上實例中我們連接到本地的 redis 服務并執(zhí)行 PING 命令,該命令用于檢測 redis 服
      務是否啟動。
      在遠程服務上執(zhí)行命令
      如果需要在遠程 redis 服務上執(zhí)行命令,同樣我們使用的也是 redis-cli 命令。
      語法
      $ redis-cli -h host -p port -a password
      實例
      以下實例演示了如何連接到主機為 127.0.0.1,端口為 6379 ,密碼為 mypass 的 redis
      服務上。
      $redis-cli -h 127.0.0.1 -p 6379 -a "mypass"
      redis 127.0.0.1:6379>
      redis 127.0.0.1:6379> PING
      PONG

      創(chuàng)新互聯(lián)2013年開創(chuàng)至今,先為渭城等服務建站,渭城等地企業(yè),進行企業(yè)商務咨詢服務。為渭城企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務解決您的所有建站問題。

      主從復制

      環(huán)境描述:
      主 redis:192.168.10.1 6379
      從 redis:192.168.10.2 6380
      一、主從配置
      1、將主從 redis 配置文件 redis.conf 中的 daemonize no 改為 yes
      2、修改從 redis 配置文件 redis.conf 中的 port 6379 改為 6380,添加 slaveof
      192.168.10.1 6379
      三種辦法:a、配置文件中加 slaveof [masterHost] [masterPort]
      b、redis-server 啟動時加--slaveof [masterHost] [masterPort]
      c、直接使用命令 slaveof [masterHost] [masterPort]
      3、啟動主從服務
      主 redis:
      [root@localhost redis-2.8.3]# src/redis-server /soft/redis-2.8.3-master/redis2.8.3/redis.conf
      從 redis:
      [root@localhost redis-2.8.3]# src/redis-server /soft/redis-2.8.3-slave/redis2.8.3/redis.conf
      4、測試數(shù)據(jù)同步
      主 redis:
      [root@localhost redis-2.8.3]# src/redis-cli -p 6379
      127.0.0.1:6379> set name abc
      OK
      127.0.0.1:6379> get name
      "abc"
      127.0.0.1:6379>
      從 redis:
      [root@localhost redis-2.8.3]# src/redis-cli -p 6380
      127.0.0.1:6380> get name
      "abc"
      127.0.0.1:6380>
      5、默認是讀寫分離的
      在從 redis:
      [root@localhost redis-2.8.3]# src/redis-cli -p 6380
      127.0.0.1:6380> set name 123
      (error) READONLY You can't write against a read only slave.

      二、主從切換

      1、停止主 redis
      [root@localhost redis-2.8.3]# src/redis-cli -n 6379 shutdown
      [root@localhost redis-2.8.3]# src/redis-cli -p 6379
      Could not connect to Redis at 127.0.0.1:6379: Connection refused
      not connected>
      2、將從 redis 設成主 redis
      [root@localhost redis-2.8.3]# src/redis-cli -p 6380 slaveof NO ONE
      OK
      3、測試從 redis 是否切換從主 redis
      [root@localhost redis-2.8.3]# src/redis-cli -p 6380
      127.0.0.1:6380> set name 123
      OK
      127.0.0.1:6380> get name
      "123"
      127.0.0.1:6380>
      4、原來的主 redis 恢復正常了,要重新切換回去
      1)將現(xiàn)在的主 redis 的數(shù)據(jù)進行保存
      [root@localhost redis-2.8.3]# src/redis-cli -p 6380
      127.0.0.1:6380> get name
      "abc"
      127.0.0.1:6380> set name 123
      OK
      127.0.0.1:6380> get name
      "123"
      127.0.0.1:6380> save
      OK
      127.0.0.1:6380> get name
      "123"
      127.0.0.1:6380>
      2)將現(xiàn)在的主 redis 根目錄下 dump.rdb 文件拷貝覆蓋到原來主 redis 的根目錄
      3)啟動原來的主 redis
      [root@localhost redis-2.8.3]# src/redis-server /soft/redis-2.8.3-master/redis2.8.3/redis.conf
      4)在現(xiàn)在的主 redis 中切換
      [root@localhost redis-2.8.3]# src/redis-cli -p 6380 slaveof 192.168.10.1 6379
      OK


      主從切換

      主節(jié)點
      63  redis-cli -p 6379 shutdown      # 停止redis
      65  rm -rf /var/lib/redis/6379/dump.rdb    #刪除redis里面的數(shù)據(jù)

      從節(jié)點
      26  scp /var/lib/redis/6379/dump.rdb     root@192.168.1.2:/var/lib/redis/6379/dump.rdb    #把從節(jié)點上的數(shù)據(jù)復制到主節(jié)點上

      主節(jié)點
      66  redis-cli -h 192.168.1.2 shutdown          #停止redis
      67  redis-cli /etc/redis/6379.conf                  #啟動redis
      69  redis-server /etc/redis/6379.conf           #啟動redis
      70  redis-cli -h 192.168.1.2 -p 6379             #進入redis



      文章題目:redis安裝和主從復制、主從切換的使用方法
      本文URL:http://ef60e0e.cn/article/jjjojp.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        江孜县| 德令哈市| 张家口市| 措美县| 鹤峰县| 梅河口市| 特克斯县| 桐柏县| 紫阳县| 汉阴县| 龙胜| 云龙县| 广平县| 武陟县| 漳州市| 西安市| 铜梁县| 永康市| 万源市| 黔西| 盖州市| 黄梅县| 大厂| 辽中县| 永平县| 天台县| 武鸣县| 焦作市| 柯坪县| 开江县| 宜兰县| 故城县| 略阳县| 鄂伦春自治旗| 南江县| 延津县| 永康市| 泾川县| 龙泉市| 连城县| 广水市|