1:Ansible的搭建
接下来我们来学习Ansible的安装和部署。Ansible的安装部署非常简单,以RPM安装为例,配置好阿里云的yum源直接安装就可以了, Ansible 的管理端只能是Linux,如Redhat,Debian.CentOS。下面介绍在CentOS7.x上安装部署Ansible。
实验环境
环境准备(主机能够上网)
Ansible
《1》:cd /etc/yum.repos/ 切换目录
《2》:wget http://mirrors.aliyun.com/repo/Centos-7.repo
wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 下载镜像
《3》:rpm -ivh epel-release-latest-7.noarch.rpm
《4》:yum -y install ansible
《5》:vim /etc/hosts 编辑
《6》:写入:
192.168.100.10 ansible
192.168.100.20 client1
192.168.100.30 client2
《7》:scp /etc/hosts 192.168.100.20:/etc/hosts
scp /etc/hosts 192.168.100.30:/etc/hosts
《8》:hostname ansible 修改名称
hostname client1
hostname client2
bash
《9》:systemctl stop firewalld
iptables -F
setenforce 0
《10》:vim /etc/ansible/hosts 编辑文件
《11》:写入:
[webserver]
192.168.100.20
192.168.100.30
《12》:ansible webserver -m ping 测试
报错说明,没有创建密钥对
《13》:ssh-keygen 创建密钥对
《14》:ssh-copy-id root@192.168.100.20 发送密钥对
ssh-copy-id root@192.168.100.30
《15》:ansible webserver -m ping
《16》:ansible webserver -a "df -Th" 查看后两台主机的磁盘
《17》:ansible webserver -a "free -m" 查看后两台主机的内存
《18》:ansible --version 查看版本
《19》:ssh-keygen -t rsa -P " " -f .ssh/id_rsa 创建密钥对时,,不需要回车,一气呵成