redis​完全分布式安装

一、安装Redis集群
 1 .创建6个节点,其中3个主节点,3个从节点,对应的redis节点的ip和端口关系如下:
 HFPL-A01 HFPL-A02 HFPL-A03(不推荐,最好是安装到6个主机节点)
  21.67.123.67:7000
  21.67.123.67:7001
  21.67.123.68:7000
  21.67.123.68:7001
  21.67.123.69:7000
  21.67.123.69:7001
 2.上传文件
  scp -r drl/software wade@HFPL-A01:/mnt/disk6/
  scp -r drl/software wade@HFPL-A02:/mnt/disk6/
  scp -r drl/software wade@HFPL-A03:/mnt/disk6/
  
 3. cd redis-3.0.6/
 4. make
 5. make PREFIX=/mnt/disk6/drl/software/redis install
 6. 分别启动这6个实例
  (1)在/mnt/disk6/drl/software/redis目录下分别创建7000和7001这两个目录
  (2)分别将/mnt/disk6/drl/software/redis-3.0.6/redis.conf拷贝到7000和7001这两个目录
  (3)分别修改7000和7001这两个目录下的redis.conf文件
   最少选项的集群修改配置项如下:
    port 7000(7001)
    cluster-enabled yes
    cluster-config-file nodes-7000.conf(nodes-7001.conf)
    cluster-node-timeout 5000
    appendonly yes
  (4)/mnt/disk6/drl/software/redis/bin/redis-server 7000/redis.conf &
  (5)/mnt/disk6/drl/software/redis/bin/redis-server 7001/redis.conf &
    
  ps -ef | grep redis #查看redis进程
 7. 在HFPL-A01机器启动集群
  scp ruby-2.3.0.tar.gz wade@HFPL-A01:/mnt/disk6/drl/software
  scp redis-3.2.1.gem wade@HFPL-A01:/mnt/disk6/drl/software
  
  (1) tar -zxvf ruby-2.3.0.tar.gz
  (2) ./configure --prefix=/mnt/disk6/drl/software/ruby
  (3) make
  (4) make install
  (5) sudo ln -s /mnt/disk6/drl/software/ruby/bin/ruby /usr/local/bin/ruby
  (6) sudo ln -s /mnt/disk6/drl/software/ruby/bin/gem /usr/local/bin/gem
  (7) sudo gem install -l /mnt/disk6/drl/software/redis-3.2.1.gem
  
  可能报错,缺少zlib:
  解决方法:
   (1)安装zlib   
    gunzip zlib-1.2.6.gz
    tar -xvf zlib-1.2.6
    cd zlib-1.2.6
    ./configure --prefix=/mnt/disk6/drl/software/zlib

   (2)cd /mnt/disk6/drl/software/ruby-2.3.0/ext/zlib
   (3)ruby extconf.rb --with-zlib-dir=/mnt/disk6/drl/software/zlib
   (4)make
   (5)make install
   (6)sudo gem install -l /mnt/disk6/drl/software/redis-3.2.1.gem
  接下来:
 

 cd /mnt/disk6/drl/software/redis-3.0.6/src 

  ./redis-trib.rb create --replicas 1 21.67.123.67:7000 21.67.123.68:7000 21.67.123.69:7000 21.67.123.67:7001 21.67.123.68:7001 21.67.123.69:7001

  输入:yes

 8. 集群安装成功
二、使用Redis集群

 redis-cli -p 7001 cluster nodes #查看集群节点信息
 redis-cli -p 7001 #启用单节点模式命令


 启用集群模式命令
 

redis-cli -c -h 21.67.123.67 -p 7000
 21.67.123.67:7000> set foo bar
 -> Redirected to slot [12182] located at 21.67.123.69:7000
 OK
 21.67.123.69:7000> set hello world
 -> Redirected to slot [866] located at 21.67.123.67:7000
 OK
 21.67.123.67:7000> get foo
 -> Redirected to slot [12182] located at 21.67.123.69:7000
 "bar"
 21.67.123.69:7000> get hello
 -> Redirected to slot [866] located at 21.67.123.67:7000
 "world"
 21.67.123.67:7000>

你可能感兴趣的:(redis,安装,分布式)