1. 程式人生 > >java:redis(redis的集群配置)

java:redis(redis的集群配置)

升級 hosts keys tor and 建立 pen daemon bsp

服務器集群作用:

  服務器集群就是指將很多服務器集中起來一起進行同一種服務,在客戶端看來就象是只有一個服務器 集群可以利用多個計算機進行並行計算從而獲得很高的計算速度,也可以用多個計算機做備份,從而使得任何一個機器壞了整個系統還是能正常運行。一旦在服務器上安裝並運行了群集服務,該服務器即可加入群集。群集化操作可以減少單點故障數量,並且實現了群集化資源的高可用性。

redis的集群配置:

  (.編輯network文件
  HOSTNAME=redis(自己定義的hostname)
  vi /etc/sysconfig/network
  .編輯hosts文件
  需要在hosts文件末尾添加ip和主機名的映射


  127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
  ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  本虛擬機機的ip地址 自己定義的hostname
  192.168.1.162 redis
  vi /etc/hosts
  . 關閉防火墻開機啟動
  service iptables stop
   chkconfig iptables off

  )


  1. 把redis-3.2.10.tar.gz放到linux中
  2. 解壓該壓縮包(tar -zxvf xxxxx)到當前目錄
  3. 進入redis-3.2.10目錄(cd xxxxx)
  4. make && make install 編譯和安裝redis
  5. 在redis-3.2.10目錄下創建redis_cluster文件夾(mkdir redis_cluster)
  6. 在redis_cluster文件夾下創建對應的端口號文件夾(6380,6381,6382,6383,6384,6385)
  7. 分別在這6個文件夾中創建redis.conf文件(touch redis.conf)


  8. 對該文件進行編輯
    !!註意:必須要修改ip和對應的端口號
    daemonize yes
    pidfile redis_6380.pid
    logfile redis_6380.log
    appendonly yes
    bind 192.168.242.10
    port 6380
    cluster-enabled yes
    cluster-config-file nodes-6380.conf
    cluster-node-timeout 15000
    cluster-slave-validity-factor 10
    cluster-migration-barrier 1
    cluster-require-full-coverage yes
  9. 啟動集群
    進入redis-3.2.10的src目錄下
    ./redis-server ../redis_cluster/6380/redis.conf
    ./redis-server ../redis_cluster/6381/redis.conf
    ./redis-server ../redis_cluster/6382/redis.conf
    ./redis-server ../redis_cluster/6383/redis.conf
    ./redis-server ../redis_cluster/6384/redis.conf
    ./redis-server ../redis_cluster/6385/redis.conf
  10. 檢查redis集群啟動情況
    ps -ef |grep redis
  11. 如果集群正常啟動
    創建redis(數據庫)集群
    也必須首先進入redis-3.2.10的src目錄
    ./redis-trib.rb create --replicas 1 ip地址:端口號 ip地址:端口號 ip地址:端口號 ip地址:端口號 ip地址:端口號 ip地址:端口號
    ./redis-trib.rb create --replicas 1 192.168.1.186:6380 192.168.1.186:6381 192.168.1.186:6382 192.168.1.186:6383 192.168.1.186:6384 192.168.1.186:6385

    如果報錯:/usr/bin/env: ruby: No such file or directory
    說明ruby沒有安裝
  12. 安裝ruby
    yum install ruby
  13. 再次運行./redis-trib.rb create --replicas 1 ip地址:端口號 ip地址:端口號 ip地址:端口號 ip地址:端口號 ip地址:端口號 ip地址:端口號

  如果報錯:no such file to load -- rubygems (LoadError)
  14. 安裝rubygems
    yum install rubygems
  15. 執行gem install redis來把gem和redis對接
  16. 如果報錯:redis required ruby version >= 2.2.2
  17. 升級ruby的版本信息

  18. ruby的升級需要兩個依賴 curl和RVM
    18.1 安裝culr
      yum install curl
    18.2 RVM
      curl -L get.rvm.io | bash -s stable
      需要等待很久很久很久很久
      如果出現以下錯誤:
      Warning, RVM 1.26.0 introduces signed releases and automated check of signatures when GPG software found. Assuming       you trust Michal Papis import the mpapis public key (downloading the signatures).

      GPG signature verification failed for ‘/usr/local/rvm/archives/rvm-1.29.3.tgz‘ -       ‘https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc‘! Try to install GPG v2 and then fetch the public key:

      gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

      or if it fails:

      command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -

      the key can be compared with:

      https://rvm.io/mpapis.asc
      https://keybase.io/mpapis

      NOTE: GPG version 2.1.17 have a bug which cause failures during fetching keys from remote server. Please downgrade or       upgrade to newer version (if available) or use the second method described above.

    18.3 解決以上錯誤
      使用curl -sSL https://rvm.io/mpapis.asc | gpg2 --import - 先生成密鑰
      gpg: 鑰匙環‘/root/.gnupg/secring.gpg’已建立
      gpg: /root/.gnupg/trustdb.gpg:建立了信任度數據庫
      gpg: 密鑰 D39DC0E3:公鑰“Michal Papis (RVM signing) <[email protected]>”已導入
      gpg: 合計被處理的數量:1
      gpg: 已導入:1 (RSA: 1)
      gpg: 沒有找到任何絕對信任的密鑰
    18.4 再次運行curl -L get.rvm.io | bash -s stable
      無盡的等待
  19. 使用source /usr/local/rvm/scripts/rvm命令
    使rvm立即生效
  20. rvm list known查看當前可用ruby版本
  21. 從可用的ruby版本中選一個進行安裝,但是所要安裝的版本必須要大於2.2.2
  22. rvm install x.x.x
  23. rvm use x.x.x立即使用新安裝的ruby版本

  24. 運行gem install redis
  25. 進入redis數據庫
    首先要到redis-3.2.10的src目錄下
    ./redis-cli -h xxx.xxx.xxx.xxx -c -p 6380
    當進行增刪查的時候,報錯,找不到其他的集群信息,說明redis集群中沒有創建數據庫,導致集群找不到存儲的空間
    exit命令退出集群
  26. 創建redis的數據庫
    ./redis-trib.rb create --replicas 1 ip地址:端口號 ip地址:端口號 ip地址:端口號 ip地址:端口號 ip地址:端口號 ip地址:端口號

    ./redis-trib.rb create --replicas 1 192.168.1.186:6380 192.168.1.186:6381 192.168.1.186:6382 192.168.1.186:6383 192.168.1.186:6384 192.168.1.186:6385

  27. 再次進入集群
    首先要到redis-2.3.10的src目錄下
    運行./redis-cli -h xxx.xxx.xxx.xxx -c -p 6380
    再次測試增刪查

java:redis(redis的集群配置)