saltstack之redis集群创建

redis集群创建

我这里用了2台机器,创建伪集群,大家可根据自己需要,稍微调整即可



##安装配置redis集群

[[email protected] redis]# cat redis.sls
redis-installed:
  archive.extracted:
    - name: /ane/soft/
    - source: salt://redis/files/redis-3.2.1.tar.gz
    - archive_format: tar
    - if_missing: /ane/soft/redis-3.2.1
    - unless: test -d /ane/redis
  pkg.installed:
    - pkgs:
       - gcc
       - tcl
       - gcc-c++
  cmd.run:
    - name: cd /ane/soft/redis-3.2.1 && make && make install
redis-6379conf:
  file.managed:
    - name: /ane/redis/6379/redis.conf
    - source: salt://redis/files/redis.conf
    - makedirs: True
    - template: jinja
      host: {{ grains[‘fqdn_ip4‘][0] }}
      port: 6379
redis-6380conf:
  file.managed:
    - name: /ane/redis/6380/redis.conf
    - source: salt://redis/files/redis.conf
    - makedirs: True
    - template: jinja
      host: {{ grains[‘fqdn_ip4‘][0] }}
      port: 6380
redis-6381conf:
  file.managed:
    - name: /ane/redis/6381/redis.conf
    - source: salt://redis/files/redis.conf
    - makedirs: True
    - template: jinja
      host: {{ grains[‘fqdn_ip4‘][0] }}
      port: 6381
redis-cluster:
  pkg.installed:
    - pkgs:
        - ruby
        - ruby-devel
        - rubygems
  file.managed:
    - name: /ane/soft/redis-3.2.1.gem
    - source: salt://redis/files/redis-3.2.1.gem
  cmd.run:
   - name: gem install /ane/soft/redis-3.2.1.gem
redis-service:
  file.managed:
   - name: /ane/script/startredis.sh
   - source: salt://redis/files/startredis.sh
   - makedirs: True
   - mode: 655
  cmd.run:
   - name: /ane/script/startredis.sh

上面采用了jinja模版,其中host和port是定义的两个模版变量,可以传不同的值进去
##创建集群

[[email protected] redis]# salt ‘master1‘ cmd.run ‘echo yes|/ane/soft/redis-3.2.1/src/redis-trib.rb create --replicas 1 172.16.77.160:6379 172.16.77.160:6380 172.16.77.160:6381 172.16.77.162:6379 172.16.77.162:6380 172.16.77.162:6381‘
master1:
    >>> Creating cluster
    >>> Performing hash slots allocation on 6 nodes...
    Using 3 masters:
    172.16.77.160:6379
    172.16.77.162:6379
    172.16.77.160:6380
    Adding replica 172.16.77.162:6380 to 172.16.77.160:6379
    Adding replica 172.16.77.160:6381 to 172.16.77.162:6379
    Adding replica 172.16.77.162:6381 to 172.16.77.160:6380
    M: 1ef26e8ddcd56d22f66b1270e0f29cf319b6305c 172.16.77.160:6379
       slots:0-5460 (5461 slots) master
    M: 0cd4d5ecdecc538e76c6b3d0cfa689cb40f7e573 172.16.77.160:6380
       slots:10923-16383 (5461 slots) master
    S: 07b6124f057e12fc78833be31757413de01f6368 172.16.77.160:6381
       replicates e4d5bdc8815126789cc8935cec5be3380f7e68d4
    M: e4d5bdc8815126789cc8935cec5be3380f7e68d4 172.16.77.162:6379
       slots:5461-10922 (5462 slots) master
    S: 6cafd239cff892c4e587b14d5cc5619cb3a97277 172.16.77.162:6380
       replicates 1ef26e8ddcd56d22f66b1270e0f29cf319b6305c
    S: cb31f41ffe6ff356b65727b1dc3d5fdc14378c45 172.16.77.162:6381
       replicates 0cd4d5ecdecc538e76c6b3d0cfa689cb40f7e573
    Can I set the above configuration? (type ‘yes‘ to accept): >>> Nodes configuration updated
    >>> Assign a different config epoch to each node
    >>> Sending CLUSTER MEET messages to join the cluster
    Waiting for the cluster to join......
    >>> Performing Cluster Check (using node 172.16.77.160:6379)
    M: 1ef26e8ddcd56d22f66b1270e0f29cf319b6305c 172.16.77.160:6379
       slots:0-5460 (5461 slots) master
    M: 0cd4d5ecdecc538e76c6b3d0cfa689cb40f7e573 172.16.77.160:6380
       slots:10923-16383 (5461 slots) master
    M: 07b6124f057e12fc78833be31757413de01f6368 172.16.77.160:6381
       slots: (0 slots) master
       replicates e4d5bdc8815126789cc8935cec5be3380f7e68d4
    M: e4d5bdc8815126789cc8935cec5be3380f7e68d4 172.16.77.162:6379
       slots:5461-10922 (5462 slots) master
    M: 6cafd239cff892c4e587b14d5cc5619cb3a97277 172.16.77.162:6380
       slots: (0 slots) master
       replicates 1ef26e8ddcd56d22f66b1270e0f29cf319b6305c
    M: cb31f41ffe6ff356b65727b1dc3d5fdc14378c45 172.16.77.162:6381
       slots: (0 slots) master
       replicates 0cd4d5ecdecc538e76c6b3d0cfa689cb40f7e573
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.

##测试redis集群

[[email protected] redis]# redis-cli -h 172.16.77.160 -p 6379
172.16.77.160:6379> set hello world
OK
172.16.77.160:6379> get hello
"world"
172.16.77.160:6379>
[[email protected] redis]# redis-cli -h 172.16.77.160 -p 6379
172.16.77.160:6379> set hello world
OK
172.16.77.160:6379> get hello
"world"
172.16.77.160:6379> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_sent:232
cluster_stats_messages_received:232
172.16.77.160:6379> cluster nodes
1ef26e8ddcd56d22f66b1270e0f29cf319b6305c 172.16.77.160:6379 myself,master - 0 0 1 connected 0-5460
cb31f41ffe6ff356b65727b1dc3d5fdc14378c45 172.16.77.162:6381 slave 0cd4d5ecdecc538e76c6b3d0cfa689cb40f7e573 0 1517560583831 6 connected
6cafd239cff892c4e587b14d5cc5619cb3a97277 172.16.77.162:6380 slave 1ef26e8ddcd56d22f66b1270e0f29cf319b6305c 0 1517560578775 5 connected
e4d5bdc8815126789cc8935cec5be3380f7e68d4 172.16.77.162:6379 master - 0 1517560580795 4 connected 5461-10922
07b6124f057e12fc78833be31757413de01f6368 172.16.77.160:6381 slave e4d5bdc8815126789cc8935cec5be3380f7e68d4 0 1517560579785 4 connected
0cd4d5ecdecc538e76c6b3d0cfa689cb40f7e573 172.16.77.160:6380 master - 0 1517560582817 2 connected 10923-16383
172.16.77.160:6379> 

原文地址:http://blog.51cto.com/9682938/2134823

时间: 2024-10-11 05:24:59

saltstack之redis集群创建的相关文章

Redis集群创建和配置

1.检查GCC是否安装,可以看看版本号 gcc -v 安装命令:yum install gcc-c++ 2.安装Ruby和Rubygems 如果有网的话,则通过yum命令进行安装,自动将关联的依赖包全部安装 yum install ruby yum install rubygems Ruby离线安装去官网下载:http://www.ruby-lang.org/en/downloads/ ./configure –-prefix=/usr/local/ruby -prefix是将ruby安装到指定

Redis集群创建报错

Redis集群环境:och163/och164/och165 在执行如下脚本时报错: ./src/redis-trib.rb create 10.1.253.163:6379 10.1.253.164:6379 10.1.253.165:6379 /usr/lib/ruby/gems/1.8/gems/redis-3.0.7/lib/redis/client.rb:97:in `call': ERR Slot 16011 is already busy (Redis::CommandError)

redis.conf中bind绑定IP不对,redis集群创建节点的时候,报错|redi群集密码设置

前言# 我们都知道,redis 的配置文件中,默认绑定接口是 127.0.0.1,也就是本地回环接口,所以是无法从外网连接 redis 服务的.如果想要让外网也能连接使用服务器上的 redis 服务,可以简单地注释掉 bind 这一行.但对于 bind 参数的作用,网上有很多文章的解释都是误人子弟的. 关于bind# 翻看网上的文章,此处多翻译为: 指定 redis 只接收来自于该 IP 地址的请求,如果不进行设置,那么将处理所有请求,在生产环境中最好设置该项.这种解释会搞糊涂初学者,甚至是错误

redis集群创建

部署3(Master)+3(Slave)的一个集群安装过程,真实生产环境上可以采用每台物理机上部署一个Master进程和一个Slave进程 架构 下载redis wget -c http://download.redis.io/releases/redis-3.0.7.tar.gz:tar -zxf redis-3.0.7.tar.gz :cd redis-3.0.7:make&&make install 新建6个文件夹 将redis.conf 拷贝到文件夹内 修改配置文件 配置选项 值

Redis集群搭建案例

版本及系统说明 系统:CentOS 6.8 64X Redis版本:redis-3.2.5 集群说明: 总共6个节点 3个Master节点,分别为7000.8000.9000. 3个Slave节点,分别为7001.8001.9001. 安装Redis # wget http://download.redis.io/releases/redis-3.2.5.tar.gz # yum -y install gcc tcl # mkdir /usr/local/redis # tar xvf redi

Redis集群部署(手动安装)

1. 安装依赖包 注意:本节需要使用root用户操作 1.1 安装ruby yum install ruby -y yum install ruby-devel.x86_64 -y 1.2 安装rubygem 有些系统默认没有rubygems的包,可能需要手动安装,先安装好ruby-irb和ruby-rdoc,然后操作以下步骤. (1) 下载rubygem包,https://rubygems.org/?locale=zh-CN (2) 上传rubygems-2.4.8.zip至/redis目录

Redis集群部署过程记录(3台服务器共6个节点)

这是我的第一篇博文,整理了我在部署Redis集群踩过的坑,以及详细的部署过程,同时归结了部署过程中遇到的问题的处理方法.1.部署的环境:SUSE Linux Enterprise 11 sp42.涉及到的安装包如下:(1) 安装包:redis-4.0.2.tar.gz下载地址:http://download.redis.io/releases/ redis官网http://www.redis.io(2) 接口包:redis-4.0.0.gem(3) 脚本语言包:ruby-2.4.2.tar.gz

Redis集群节点主从关系调整

一.概述 Redis集群创建后,可能会出现互为主从关系的节点从属于同一台服务器的情况.在此种情况下,若 服务器故障宕机或需要停机维护,互为主从关系的节点同时停止运行,导致redis集群暂时失去一部 分slot插槽.此时,redis集群为fail状态,对其进行的数据读写操作均无法正常进行.为避免此种情 况的发生,应对redis集群节点的主从关系进行调整,使互为主从关系的节点分属于不同的服务器. 二.调整方法描述 1.使用redis-trib.rb脚本将待调整的从节点从redis集群中删除.(执行此

redis集群 Waiting for the cluster to join 一直等待

问题: redis集群创建执行 ./redis-trib.rb create --replicas 1 XXXX:PORT1 XXXX:PORT2 .... 的时候一直等待 Waiting for the cluster to join 很久都没有反应 原因: redis集群不仅需要开通redis客户端连接的端口,而且需要开通集群总线端口 集群总线端口为redis客户端连接的端口 + 10000 如redis端口为6379 则集群总线端口为16379 故,所有服务器的点需要开通redis的客户端