• 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'

    安装结束

  • 相关阅读:
    WinHex(三)
    HDFS 联邦
    Ruby中Rack中间件的使用场景和注意事项
    驱动——串口工具点灯实验
    Spring AOP底层实现原理
    openlayes + vue 最新版本 实现 轨迹移动动画
    布隆过滤器
    position left设置居中,除了auto以外,还有什么方式
    HTTP返回状态值详解整理
    Debian安装Docker环境
  • 原文地址:https://blog.csdn.net/weixin_45861372/article/details/126885693