

基于ansible在docker环境安装redis集群(3主3从)
source link: https://blog.51cto.com/cuiyingfeng/5359437
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

基于ansible在docker环境安装redis集群(3主3从)
原创本文档主要介绍如何使用ansible在远程centos服务器docker环境快速安装redis集群(3主3从),目标服务器为一台本地虚拟机,安装操作系统为官方的Centos7.9-64,语言环境选择简体中文,安装类型选择最小化安装,不预装任何软件。
- 一台虚机:4c8g40g
- 一台可以连接该虚机的mac pro,预装ansible和git,其中ansible版本为2.12.4
服务器类型 | OS | 内网IP | 备注 |
---|---|---|---|
目标服务器 | Centos7.9 | 10.0.1.121 | root/root1234 |
主控端 | mac pro |
- 准备hosts文件
#redis-cluster-hosts
server1 ansible_ssh_user=root ansible_ssh_host=10.0.1.121 ansible_ssh_pass='root1234'
系统配置调优
最小化安装的centos7.9一般需要做一些才能充分发挥系统性能,ansible安装脚本里有roles可以用来修改ulimit、关闭防火墙和关闭selinux。
cuiyingfeng@bogon ~ % git clone https://gitee.com/pi4k8s/ansible-exmaples.git
cuiyingfeng@bogon ~ % cd ansible-exmaples
# 用准备好的redis-cluster-hosts文件替换下载的hosts
cuiyingfeng@MacBook-Pro-2 ansible-exmaples % cat hosts
server1 ansible_ssh_user=root ansible_ssh_host=10.0.1.121 ansible_ssh_pass='root1234'
cuiyingfeng@MacBook-Pro-2 ansible-exmaples % ANSIBLE_HOST_KEY_CHECKING=false ansible-playbook base-centos7.9/playbook/install-os-enforce.yaml -i hosts -e env_hosts=server1
安装docker
cuiyingfeng@bogon ~ % git clone https://gitee.com/pi4k8s/ansible-exmaples.git
cuiyingfeng@bogon ~ % cd ansible-exmaples
# 用准备好的redis-cluster-hosts文件替换下载的hosts
cuiyingfeng@MacBook-Pro-2 ansible-exmaples % cat hosts
server1 ansible_ssh_user=root ansible_ssh_host=10.0.1.121 ansible_ssh_pass='root1234'
cuiyingfeng@MacBook-Pro-2 ansible-exmaples % ANSIBLE_HOST_KEY_CHECKING=false ansible-playbook common-centos7.9/playbook/install-docker.yaml -i hosts -e env_hosts=server1
cuiyingfeng@MacBook-Pro-2 ansible-exmaples % ansible -m shell -a 'docker --version' -o -i hosts server1
server1 | CHANGED | rc=0 | (stdout) Docker version 20.10.16, build aa7e414
安装python3
目标服务器安装的Centos7.9操作系统默认安装的python版本比较低,其实并不支持ansible的docker容器相关指令;这里我们需要先在目标服务器远程安装一个高版本的python,后续再通过指定python路径的方式去执行ansible脚本就可以成功操作docker容器了。
本步骤中我们可以直接通过yum方式安装pyhon3(centos7.9默认安装的版本是3.6.8),然后再用pip3安装docker,后续就可以正常启动docker容器了,只是需要指定ansible_python_interpreter为/usr/bin/python3。
另外要注意一下主控端的ansible版本号,本实践使用的ansible版本为2.12.4(2.9.27版本也可以通过),如果ansible版本过低可能会导致基于本实践的安装python3失败。
# 在安装docker的步骤中我们已经同步下载了安装python3的ansible脚本,可以直接执行如下
cuiyingfeng@MacBook-Pro-2 ansible-exmaples % ansible-playbook common-centos7.9/playbook/install-python3.yaml -i hosts -e env_hosts=server1
cuiyingfeng@MacBook-Pro-2 ansible-exmaples % ansible -m shell -a 'python3 --version' -o -i hosts server1
server1 | CHANGED | rc=0 | (stdout) Python 3.6.8
安装redis集群
cuiyingfeng@MacBook-Pro-2 ~ % git clone https://gitee.com/cuiyingfeng/jenkins-ansible-examples.git
cuiyingfeng@MacBook-Pro-2 ~ % cd jenkins-ansible-examples/redis-cluster
# 用准备好的redis-cluster-hosts文件替换下载的redis-cluster-hosts
cuiyingfeng@MacBook-Pro-2 redis-cluster % cat redis-cluster-hosts
server1 ansible_ssh_user=root ansible_ssh_host=10.0.1.121 ansible_ssh_pass='root1234'
cuiyingfeng@MacBook-Pro-2 redis-cluster % ansible-playbook playbook/install-redis-cluster.yaml -i redis-cluster-hosts -e env_hosts=server1
cuiyingfeng@MacBook-Pro-2 redis-cluster % ansible -m shell -a 'docker exec redis-6379 redis-cli -a 1234 cluster info' -i redis-cluster-hosts server1
server1 | CHANGED | rc=0 >>
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_ping_sent:252
cluster_stats_messages_pong_sent:242
cluster_stats_messages_sent:494
cluster_stats_messages_ping_received:242
cluster_stats_messages_pong_received:248
cluster_stats_messages_received:490Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
pipeline
https://gitee.com/cuiyingfeng/jenkins-ansible-examples 下有一枚彩蛋redis-cluster/install-redis-cluster-from-scratch.groovy,熟悉jenkins的同学可以上车了。
- 打赏
- 赞
- 收藏
- 评论
- 分享
- 举报
Recommend
-
34
这次开始动手操作,首先是Mesos的安装,怎么来安装Mesos。源码:https://github.com/limingios/msA-docker/mac https://github.com/limingios/msA-docker/vagrant/Mesos
-
18
使用kubeadm安装基于虚拟主机的Kubernetes 集群 ...
-
11
上一篇文章《Kubernetes安装篇(上):基于Minikube方式部署本地环境》介绍了基于本地环境下的 Kubernetes 安装,目的在于搭建本地开发环境。但在实际生产环境中,Kubernetes
-
15
操作系统:CentOS8,由Vmware虚拟机创建,网络使用桥接模式 Docker版本:19.03.12 Redis版本:5.0.3 安装并启动Dockersudo yum install docker -ysudo service docker start
-
6
分布式锁 Redlock由于前面介绍的基于单Redis节点的分布式锁在failover的时候会产生解决不了的安全性问题,因此antirez提出了新的分布式锁的算法Redlock,它基于N个完全独立的Redis节点(通常情况下N可以设置成5)。 运行Redlock算法的客户端依...
-
3
基于ansible在远程centos服务器docker环境安装kafka 推荐 原创 本文档主要介绍如何使用ansible...
-
6
kafka镜像 zookeeper镜像 创建docker网络# 命...
-
14
FLINK 基于1.15.2的Java开发-搭建2主3从的生产集群环境
-
3
通过前面两篇,我们学会了三主三从的Redis集群搭建及主从容错切换迁移,随着业务增加,可能会有主从扩容的,所以,本文我们来实战主从扩容PS本系列:《Docker学习系列》教程已经发布的内容,凯哥会在文末加上。在之前3主3从的架构,随...
-
2
Ansible AWX 是一个强大的开源工具,用于管理和自动化 IT 基础设施。AWX 为 Ansible 提供图形用户界面,使你...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK