Ansible服務器 | 192.168.0.113 |
主機1 | 192.168.0.104 |
主機2 | 192.168.0.105 |
主機3 | 192.168.0.106 |
1.安裝(依賴於epel源,版本2.0.1.0-2.el7)
~]# yum install ansible
配置文件:/etc/ansible/ansible.cfg
Invertory:/etc/ansible/hosts
2.編輯Invertory(編輯前備份默認hosts文件)
~]# /etc/ansible/hosts
注:支持定義單個主機和主機組
[websrvs] 192.168.0.104 192.168.0.105 [dbsrvs] 192.168.0.106
3.基於密鑰進行認證(Ansible服務器生成密鑰)
~]# ssh-keygen -t rsa ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected] #拷貝至客戶端,訪問不再需要口令
~]# ssh '[email protected]' #使用ssh驗證登錄是否通過密鑰認證,exit登出
4.同步時間(默認CentOS7未安裝ntp)
~]# yum -y install ntp ~]# systemctl start ntpd.service ~]# iptables -F ~]# ssh [email protected] 'ntpdate 192.168.0.113'