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,大功告成!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM