Redis集群安装

来源:互联网 发布:小应变数据分析 编辑:程序博客网 时间:2024/05/20 14:15

注:官方给出的安装文档是在一台物理机安装多个Redis实例,https://redis.io/topics/cluster-tutorial,我的生产环境是多台物理机,安装起来就更简单

环境:

6台物理机 CentOS7.2-1511-minimal

ip:192.168.1.101-192.168.1.106

网络环境:内网 挂载Everything.iso作为本地yum源 ,可参考我的一篇文章 http://blog.csdn.net/github_38358734/article/details/70212412

Redis版本:Redis-3.2.5.zip

gem版本:redis-3.3.2.gem

pip版本:pip-8.1.2

python版本:2.7.5

其他环境需要:gcc make


具体步骤如下:

1、在6个节点上解压redis-3.2.5.zip 并 编译安装

   # unzip redis-3.2.5.zip

   # cd redis-3.2.5

  # make && make install

2、检查安装过程

    (1)、在redis-3.2.5目录下执行 make test 报错 tcl问题

    (2)解决报错: yum install tcl  (内网 yum --disablerepo=* --enablerepo=CentOS7-media install tcl 基于搭建好本地yum源;也可以通过yum install --dwonloadonly --downloaddir=...的方式下载安装),重装执行make tesst 显示所有正常

    (3)

zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/data0/src/redis-2.6.2/src'
make: *** [all] Error 2

解决:

make MALLOC=libc


3、部署安装cluster

    1、修改配置文件

    appendonly yes

    appendfilename "appendonly-6379.aof" 去掉注释

    cluster-enabled yes  

    cluster-config-file /opt/nodes-6379.conf  去掉注释

    cluster-node-timeout 5000  去掉注释


其中

    bind 127.0.0.1 可以注释掉

    protected-mode no 默认yes

  使用默认值时,启动集群提示connection refused 没有详细找原因,配置文件参数说明很详细

4、分别启动每一个节点

   # cd /redis-3.2.5

  #./src/redis-server redis.conf  > redis.log 2>&1 & 输出Log

  如果正常启动的话 cat redis.log 

  格式如下:

  

[root@localhost opt]# cat redis-6379.log 

6115:M 31 Aug 12:34:28.904 * Increased maximum number of open files to 10032 (it was originally set to 1024).

6115:M 31 Aug 12:34:28.906 * No cluster configuration found, I'm 92999f9840418a848f7b10c5bca0119e3b515fa4

                _._                                                  

           _.-``__ ''-._                                             

      _.-``    `.  `_.  ''-._           Redis 2.9.57 (00000000/0) 64 bit

  .-`` .-```.  ```\/    _.,_ ''-._                                   

 (    '      ,       .-`  | `,    )     Running in cluster mode

 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6380

 |    `-._   `._    /     _.-'    |     PID: 6115

  `-._    `-._  `-./  _.-'    _.-'                                   

 |`-._`-._    `-.__.-'    _.-'_.-'|                                  

 |    `-._`-._        _.-'_.-'    |           http://redis.io        

  `-._    `-._`-.__.-'_.-'    _.-'                                   

 |`-._`-._    `-.__.-'    _.-'_.-'|                                  

 |    `-._`-._        _.-'_.-'    |                                  

  `-._    `-._`-.__.-'_.-'    _.-'                                   

      `-._    `-.__.-'    _.-'                                       

          `-._        _.-'                                           

              `-.__.-'                                               


6115:M 31 Aug 12:34:28.924 # Server started, Redis version 2.9.57

6115:M 31 Aug 12:34:28.924 * The server is now ready to accept connections on port 6379

5、在每个节点上执行 ps aux | grep redis 

    如果有

  root      6109  0.6  0.9 137408  9740 pts/1    Sl   12:33   0:52 redis-server *:6379 [cluster]

    说明服务正常启动

6、集群的安装:需要安装ruby gem

    (1)yum install ruby ruby-rdoc

    (2)gem install redis (内网可以下载安装redis-3.3.2.gem)

    (3)在其中一个节点上执行(如192.168.1.101)

    #cd /redis-3.2.5

    ./src/redis-trib.rb create --replicas 1 192.168.1.101:6379 192.168.1.102:6379 192.168.1.103:6379 192.168.1.104:6379 192.168.1.105:6379 192.168.1.106:6379

    (4)出现

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

    说明集群安装完成

    测试信息:./src/redis-trib.rb check 192.168.1.101:6379

    


0 0