OpenShift上部署Redis主从集群
客户有部署有状态服务的需求,单机部署模式相对简单,尝试一下集群部署。
关于Redis的master,slave 以及sentinal的架构和作用不提,有兴趣可以参考之前的博客
https://www.cnblogs.com/ericnie/p/7203950.html
github上参考的文章不少,但很多都需要基于连接互联网进行构建,同时也创建不少的buildconfig,研究了一下,还需要在本地部署一个git.
立刻觉得把问题搞复杂了。所以本文主要以简化为主,说明主要核心步骤,当然也掉到坑里浪费了些时间,不失为一种学习过程吧。
github上参考链接
https://github.com/mjudeikis/redis-openshift
架构
传统的Redis个节点角色和端口
在OpenShift上部署架构图
1.构建镜像
先clone到本地
git clone https://github.com/mjudeikis/redis-openshift
目录结构比较清晰明了,我喜欢
[root@master ~]# tree redis-openshift
redis-openshift
├── image
│ ├── Dockerfile
│ ├── Dockerfile.
│ ├── epel-.repo
│ ├── redis-master.conf
│ ├── redis-openshift.tar
│ ├── redis-slave.conf
│ └── run.sh
├── list.yaml
├── openshift
│ ├── build.yaml
│ ├── is-base.yaml
│ ├── is-output.yaml
│ ├── redis-master-dc.yaml
│ ├── redis-master-service.yaml
│ ├── redis-sentinel-dc.yaml
│ ├── redis-sentinel-services.yaml
│ └── redis.yaml
└── README.md
对了,这里我也根据我的环境修改了Dockerfile,主要是yum源的问题
先下载一个放到目录下
http://mirrors.aliyun.com/repo/epel-7.repo,
Dockerfile
FROM rhel7 #RUN yum install epel-release -y
COPY epel-.repo /etc/yum.repos.d/epel.repo RUN yum install redis hostname -y ; yum clean all COPY redis-master.conf /redis-master/redis.conf
COPY redis-slave.conf /redis-slave/redis.conf
RUN mkdir -p /redis-sentinel ; chmod -R /redis-sentinel /redis-slave
COPY run.sh /run.sh CMD [ "/run.sh" ] ENTRYPOINT [ "bash", "-c" ]
比较核心的run文件,我修改成这样
[root@master image]# cat run.sh
#!/bin/bash # Copyright The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. function launchmaster() {
if [[ ! -e /redis-master-data ]]; then
echo "Redis master data doesn't exist, data won't be persistent!"
mkdir /redis-master-data
fi
redis-server /redis-master/redis.conf --protected-mode no
} function launchsentinel() {
echo "Enter launch sentinel...." while true; do
master=$(redis-cli -h ${REDIS_SENTINEL_SERVICE_HOST} -p ${REDIS_SENTINEL_SERVICE_PORT} --csv SENTINEL get-master-addr-by-name mymaster | tr ',' ' ' | cut -d' ' -f1)
if [[ -n ${master} ]]; then
master="${master//\"}"
else
master=$(hostname -i)
fi redis-cli -h ${master} INFO
if [[ "$?" == "" ]]; then
break
fi
echo "Connecting to master failed. Waiting..."
sleep
done sentinel_conf=/redis-sentinel/sentinel.conf echo "sentinel monitor mymaster ${master} 6379 2" > ${sentinel_conf}
echo "sentinel down-after-milliseconds mymaster 60000" >> ${sentinel_conf}
echo "sentinel failover-timeout mymaster 180000" >> ${sentinel_conf}
echo "sentinel parallel-syncs mymaster 1" >> ${sentinel_conf}
echo "bind 0.0.0.0" >> ${sentinel_conf} redis-sentinel ${sentinel_conf} --protected-mode no } function launchslave() {
echo "Enter lauch slave....." while true; do
master=$(redis-cli -h ${REDIS_SENTINEL_SERVICE_HOST} -p ${REDIS_SENTINEL_SERVICE_PORT} --csv SENTINEL get-master-addr-by-name mymaster | tr ',' ' ' | cut -d' ' -f1)
if [[ -n ${master} ]]; then
master="${master//\"}"
else
echo "Failed to find master."
sleep
exit
fi redis-cli -h ${master} INFO
if [[ "$?" == "" ]]; then
break
fi
echo "Connecting to master failed. Waiting..."
sleep
done
sed -i "s/%master-ip%/${master}/" /redis-slave/redis.conf
sed -i "s/%master-port%/6379/" /redis-slave/redis.conf
redis-server /redis-slave/redis.conf --protected-mode no } if [[ "${MASTER}" == "true" ]]; then
launchmaster
exit
fi if [[ "${SENTINEL}" == "true" ]]; then
launchsentinel
exit
fi launchslave
oc new-project建立一个项目,然后
docker build -t registry.example.com/openshift/redis-openshift:1.0 . docker push registry.example.com/openshift/redis-openshift:1.0 oc import-image redis-openshift:latest --from=registry.example.com/openshift/redis-openshift:1.0 --insecure --confirm
这里必须表扬一下openshift的了,因为在调试过程中我的run.sh改来改去,每次改动需要build镜像,搞完后,直接运行上面三条,就把镜像刷新了
而Openshift的dc的trigger功能发挥作用,每次发现镜像更新后就自动更新,发布新应用,减少大量时间,感觉非常不错!
2.构建一系列的dc和service
修改openshift下的配置文件,确保镜像地址无误。
oc create -f openshift/redis-master-dc.yaml
oc create -f openshift/redis-master-service.yaml oc create -f openshift/redis-sentinel-dc.yaml
oc create -f openshift/redis-sentinel-services.yaml oc create -f openshift/redis.yaml
会建立一个master,3个sentinel和3个slave,如图
进去逐个检查日志,确保成功启动
运行下面命令,查看集群信息。
redis-cli -h redis-master info Replication
构建成功,可以愉快的使用了。
3.集群切换
讲redis-master直接scale到0,模拟down掉
然后检查sentinel的日志,发现mymaster已经从10.129.0.2切换到了10.129.0.8的redis pod.
在reids节点上运行 redis-cli -h 10.129.0.8 info Replication
可以看到集群状态已经发生变化
OpenShift上部署Redis主从集群的更多相关文章
- 02.Redis主从集群的Sentinel配置
1.集群环境 1.Linux服务器列表 使用4台CentOS Linux服务器搭建环境,其IP地址如下: 192.168.110.100 192.168.110.101 192.168.110.102 ...
- 一、全新安装搭建redis主从集群
前言· 这里分为三篇文章来写我是如何重新搭建redis主从集群和哨兵集群的及原本服务器上有单redis如何通过升级脚本来实现redis集群.(redis结构:主-从(备)-从(备)) 至于为什么要搭建 ...
- docker搭建redis主从集群和sentinel哨兵集群,springboot客户端连接
花了两天搭建redis主从集群和sentinel哨兵集群,讲一下springboot客户端连接测试情况 redis主从集群 从网上查看说是有两种方式:一种是指定配置文件,一种是不指定配置文件 引用地址 ...
- K8S部署Redis Cluster集群
kubernetes部署单节点redis: https://www.cnblogs.com/zisefeizhu/p/14282299.html Redis 介绍 • Redis代表REmote DI ...
- K8S部署Redis Cluster集群(三主三从模式) - 部署笔记
一.Redis 介绍 Redis代表REmote DIctionary Server是一种开源的内存中数据存储,通常用作数据库,缓存或消息代理.它可以存储和操作高级数据类型,例如列表,地图,集合和排序 ...
- helm部署Redis哨兵集群
介绍 Redis Sentinel集群是由若干Sentinel节点组成的分布式集群,可以实现故障发现.故障自动转移.配置中心和客户端通知. 如下图: Redis Sentinel 故障转移过程: 从这 ...
- redis —主从&&集群(CLUSTER)
REDIS主从配置 为了节省资源,本实验在一台机器进行.即,在一台机器上启动两个端口,模拟两台机器. 机器准备: [root@adailinux ~]# cp /etc/redis.conf /etc ...
- Redis主从集群及哨兵模式
本次实验环境准备用一台服务器模拟3台redis服务器,1主2从 主从集群搭建 第一步:安装Redis 安装Redis,参考前面安装Redis文章,保证单机使用没有问题. 第二步:配置服务器文件 定位到 ...
- docker swarm快速部署redis分布式集群
环境准备 四台虚拟机 192.168.2.38(管理节点) 192.168.2.81(工作节点) 192.168.2.100(工作节点) 192.168.2.102(工作节点) 时间同步 每台机器都执 ...
随机推荐
- Codeforces 429C Guess the Tree(状压DP+贪心)
吐槽:这道题真心坑...做了一整天,我太蒻了... 题意 构造一棵 $ n $ 个节点的树,要求满足以下条件: 每个非叶子节点至少包含2个儿子: 以节点 $ i $ 为根的子树中必须包含 $ c_i ...
- jquery图片延迟加载方案解决图片太多加载缓慢问题
当在做一个图片展示站的时候,一个页面加载的图片过多会,如果服务器的带宽跟不上,明显会感觉到页面很卡,严重的浏览器也会崩溃,所以我推荐采用即看即所得的模式,当滚动到下一屏时才进行加载图片. 注意:即便如 ...
- Sample ASP.NET IHttpHandler
LoggerHandler.cs using System; using System.Collections.Generic; using System.Diagnostics; using Sys ...
- redhat重置密码
当忘记虚拟机密码时怎么办? 1.启动虚拟机,当虚拟机显示输入enter启动时输入e 2.再次用上下键选中你平时启动linux的那一项(类似于kernel /boot/vmlinuz-2.4.18-14 ...
- Ionic Js五:单选框操作
实例中,根据选中的不同选项,显示不同的值. HTML 代码 <ion-header-bar class="bar-positive"> <h1 class=&qu ...
- java 里的内部类
java里的内部类通常能帮我们隐藏一些具体实现,体现良好的封装效果. 内部类又分几种: 1.普通内部类 2.局部内部类 3.匿名内部类 4.静态内部类 普通内部类 先来看第一种普通的内部类,这种内部类 ...
- CI框架的事务开启、提交和回滚
1.运行事务 $this->db->trans_start(); // 开启事务$this->db->query('一条SQL查询...');$this->db-> ...
- 2018年全国多校算法寒假训练营练习比赛(第二场)B - TaoTao要吃鸡
链接:https://www.nowcoder.com/acm/contest/74/B来源:牛客网 题目描述 Taotao的电脑带不动绝地求生,所以taotao只能去玩pc版的荒野行动了, 和绝地求 ...
- react篇章-React State(状态)-将生命周期方法添加到类中
将生命周期方法添加到类中 在具有许多组件的应用程序中,在销毁时释放组件所占用的资源非常重要. 每当 Clock 组件第一次加载到 DOM 中的时候,我们都想生成定时器,这在 React 中被称为挂载. ...
- 【GO基础】神奇的iota特殊常量
最近在学习GO语言,然后发现有一个特殊常量是以前没有接触过的,比较感兴趣,这里给大家介绍一下. iota,特殊常量,可以被认为是一个可以被编译器修改的常量. 核心概念:iota在const关键字出现时 ...