zoukankan      html  css  js  c++  java
  • ansible安装(批量执行命令

    rpm安装

    下载epl源 :  Download the latest epel-release rpm from:http://dl.fedoraproject.org/pub/epel/6/x86_64

      
       执行 wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
      安装epel-release :

        # rpm -Uvh epel-release*rpm

        安装ansible1.9

        # yum install ansible1.9
    ansible管理服务器(安装ansible的服务器)必须配置免密码登录其他需要管理的主机

    各主机执行ssh-keygen生成私钥和公钥,并把所有主机的公钥追加到authorized_keys中,然后分发到ansible管理服务器

    修改个主机的主机名,编辑/etc/hosts文件,把所有主机的ip和主机名写进去

    [root@node01 .ssh]# cat /etc/hosts
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    172.16.145.111 node01
    172.16.145.112 node02
    172.16.145.113 node03
    172.16.145.114 node04
    172.16.145.115 node05
    

    接下来就可以配置 hosts文件了,

    [root@node01 .ssh]# cat /etc/ansible/hosts
    [hadoop-all]
    node[01:05]
    
    
    [hadoop-master]
    node[04:05]
    
    [hadoop-slave]
    node[01:03]
    
    [zookeeper-all]
    node[01:03]
    
    
    [hdfs-nn]
    node[04:05]
    
    [hdfs-dn]
    node[01:03]
    
    [hdfs-jn]
    node[01:02]
    
    
    
    [yarn-rm]
    node[04:05]
    
    [yarn-nm]
    node[01:03]
    
    [hive-all]
    node[01:05]
    
    
    [hive-cli]
    node[01:05]
    
    [hive-meta]
    node[04:05]
    
    [hive-hs2]
    node[04:05]
    
    
    [impala-all]
    node[01:05]
    
    [impala-llama]
    node[04:05]
    
    [impala-catalog]
    node04
    
    [impala-state]
    node04
    
    [impala-impalad]
    node[01:03]
    

     执行命令测试ansible能否ping通

    [root@node01 .ssh]# ansible all -m ping
    node03 | success >> {
        "changed": false, 
        "ping": "pong"
    }
    
    node02 | success >> {
        "changed": false, 
        "ping": "pong"
    }
    
    node01 | success >> {
        "changed": false, 
        "ping": "pong"
    }
    
    node05 | success >> {
        "changed": false, 
        "ping": "pong"
    }
    
    node04 | success >> {
        "changed": false, 
        "ping": "pong"
    }
    

     执行服务停止重启命令

    [root@node01 .ssh]# ansible impala-impalad  -m service -a "name=impala-server state=restarted"
    node01 | success >> {
        "changed": true, 
        "name": "impala-server", 
        "state": "started"
    }
    
    node03 | success >> {
        "changed": true, 
        "name": "impala-server", 
        "state": "started"
    }
    
    node02 | success >> {
        "changed": true, 
        "name": "impala-server", 
        "state": "started"
    }
    

     ok,大功告成!

  • 相关阅读:
    医疗器械那些事
    内审员学习1
    BA
    GMP文件分类与编码管理规程
    杂-电工学
    产品学习1
    模拟电子技术1
    电路组装1
    Unable to simultaneously satisfy constraints.
    xcode
  • 原文地址:https://www.cnblogs.com/zwgblog/p/6067940.html
Copyright © 2011-2022 走看看