• ansible批量安装docker


    设备4台
    设备1 ansibie 192.168.70.80

    设备2  web1   192.168.70.70

    设备3  web2   192.168.70.60

    设备4  web3   192.168.70.50

    设备1

    [root@localhost ~]# hostnamectl set-hostname server

    设备2、3、4

    [root@localhost ~]# hostnamectl set-hostname web1

    [root@localhost ~]# hostnamectl set-hostname web2

    [root@localhost ~]# hostnamectl set-hostname web3

    设备1

    关闭防火墙、内核

    [root@server ~]# systemctl stop firewalld

    [root@server ~]# systemctl disable firewalld

    [root@server ~]# setenforce 0

    [root@server ~]# sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config

    生成秘钥

    [root@server ~]# ssh-keygen
    Generating public/private rsa key pair.
    Enter file in which to save the key (/root/.ssh/id_rsa): 
    Created directory '/root/.ssh'.
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in /root/.ssh/id_rsa.
    Your public key has been saved in /root/.ssh/id_rsa.pub.
    The key fingerprint is:
    SHA256:C/YMTOosyDFBDMPLaGdYApQix2kemBNn24OEgiIvFMg root@server
    The key's randomart image is:
    +---[RSA 2048]----+
    |#X*.             |
    |#E*=             |
    |XBB.o .          |
    |o=+o =           |
    |.+o . = S        |
    |..oo . = .       |
    |... o   +        |
    |   .             |
    |                 |
    +----[SHA256]-----+

    hosts解析

    [root@server ~]# vi /etc/hosts

    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    192.168.70.70 web1
    192.168.70.60 web2
    192.168.70.50 web3

    批量修改web1 web2 web3 防火墙 、内核、复制秘钥

    [root@server ~]# for i in web1 web2 web3

    > do
    > ssh-copy-id $i

    > ssh $i systemctl stop firewalld

    > ssh $i setenforce 0

    > ssh $i sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/SELINUX/config;

    > done

    安装ansible

    [root@server ~]# yum -y install epel-release

    [root@server ~]# yum -y install ansible

    查看版本

    [root@server ~]# ansible --version

    [root@server ~]# vi /etc/ansible/hosts   #添加以下信息

    [test-servers]
    192.168.70.70
    192.168.70.60
    192.168.70.50

    测试连通性

    1. [root@server ~]# ansible -m ping 'test-servers'
    2. [WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
    3. 192.168.70.50 | SUCCESS => {
    4.     "ansible_facts": {
    5.         "discovered_interpreter_python": "/usr/bin/python"
    6.     }, 
    7.     "changed": false
    8.     "ping": "pong"
    9. }
    10. 192.168.70.70 | SUCCESS => {
    11.     "ansible_facts": {
    12.         "discovered_interpreter_python": "/usr/bin/python"
    13.     }, 
    14.     "changed": false
    15.     "ping": "pong"
    16. }
    17. 192.168.70.60 | SUCCESS => {
    18.     "ansible_facts": {
    19.         "discovered_interpreter_python": "/usr/bin/python"
    20.     }, 
    21.     "changed": false
    22.     "ping": "pong"
    23. }

    利用shell模块批量安装

    安装必要的一些系统工具

    [root@server ~]# ansible test-servers -m shell -a 'yum install -y yum-utils device-mapper-persistent-data lvm2'

    添加软件源信息

    [root@server ~]# ansible test-servers -m shell -a 'yum install -y yum-utils device-mapper-pe'
    rs.aliyun.com/docker-ce/linux/centos/docker-ce.repo'

    [root@server ~]# ansible test-servers -m shell -a 'sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo'

     更新并安装Docker-CE

    [root@server ~]# ansible test-servers -m shell -a 'yum makecache fast'

    [root@server ~]# ansible test-servers -m shell -a 'yum -y install docker-ce'

    查看版本

    [root@server ~]# ansible test-servers -m shell -a 'docker -v'

    开启Docker服务

    [root@server ~]# ansible test-servers -m shell -a 'systemctl start docker'

    安装结束

  • 相关阅读:
    第五章:Python的集合(下)
    C++:构造函数与析构函数
    SpringBoot 实现 阿里云语音通知(SingleCallByTts)
    RDB 做快照的时候数据能修改吗?
    VisualStudio2017社区版安装完毕后,找不到stdio.h等头文件的解决方案
    https原理
    Rsync学习笔记2
    MySQL bit类型增加索引后查询结果不正确案例浅析
    JVM | 第1部分:自动内存管理与性能调优《深入理解 Java 虚拟机》
    mock的基本用法
  • 原文地址:https://blog.csdn.net/weixin_45861372/article/details/126885693