做運維的同學很多都用過ansible吧,開源批量部署工具排名前三的:puppet, saltstack, ansible。
ansible的特點是沒有agent,採用ssh協議來通訊,輕量級,採用python編寫,既可以寫playbook,也可以做一些ad-hoc的批量命令執行操作。
最近在兩臺ansible主機上執行ansible命令時發現對同樣的客戶機執行同樣的命令,所用的時間相差卻很大,兩臺ansible主機配置性能都一樣。我感到很奇怪,於是想一探究竟。
當然首先是用time命令來查看準確的時間消耗。
Result: on host1
real 150.42
user 27.80
sys 11.97
Result on host2
real 59.40
user 31.80
sys 12.96
從real time可以看出,差了將近3倍。
用top看機器的cpu和memory都比較空,於是想到有沒有可能是IO的問題,用如下命令查看
iostat -x 5 3
發現IO佔用也很小,於是又想會不會是誰調整了系統參數導致的問題,於是用time命令輸出很多詳細參數
/usr/bin/time -f 'Number of waits %w \nNumber of file system inputs by the process %I \nNumber of file system outputs by the process %O \nNumber of socket messages received by the process %r \nNumber of socket messages sent by the process %s \nSystem’s page size %Z \nPercentage of the CPU that this job got %P \nAverage total (data+stack+text) memory use of the process, in Kbytes %K \nMaximum resident set size of the process during its lifetime, in Kbytes %M \nNumber of major page faults that occurred while the process was running %F \nNumber of times the process was swapped out of main memory %W \nreal %e \nuser %U \nsys %S \n' ansible -i hosts/cluster regionservers -kK -U root -u username -m command -a "uptime" -f 100
對比之後發現也沒有大問題,最後把目光聚焦到ansible本身身上。
查看ansible配置文件/etc/ansible/ansible.cfg,對比後發現有一行被注視掉了
host_key_checking = False
修改後,在跑ansible命令,速度起來了!
至此問題解決。
本文提供一個解決問題的一般性思路,當然,這裏面還有可能是網絡問題,一步一步的排查。
大家有什麼問題可以留言討論。