服务器批量管理软件ansible安装以及配置

1.yum安装(管理主机以及被管理主机都需要安装)yum install epel-release yum install ansible

2.配置管理主机vim /etc/ansible/hosts

这里添加被管理主机的IP,可以是外网IP和内网IP

3.在管理主机中生成ssh密钥对ssh-keygen -t rsa一路回车即可在$HOME/.ssh目录下生成id_rsa和id_rsa.put私钥和公钥两个文件。注: 如果在生成密钥的时候设置了密码,ansible每次执行命令的时候,都会提示输入密钥密码,可通过下面的命令记住密码。ssh-agent bsh ssh-add ~/.ssh/id_rsa4.将公钥拷贝到管理主机中.ssh/authorized_keys文件中,实现免密码登录远程管理主机ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.200 ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.201 ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.203注:ssh-copy-id命令会自动将id_rsa.pub文件的内容追加到远程主机root用户下.ssh/authorized_keys文件中。5.ansible配置vim /etc/ansible/ansible.cfg1> 禁用每次执行ansbile命令检查ssh key host 
host_key_checking = False2> 开启日志记录 
log_path = /var/log/ansible.log3> ansible连接加速配置[accelerate] #accelerate_port = 5099 accelerate_port = 10000 #accelerate_timeout = 30 #accelerate_connect_timeout = 5.0 # If set to yes, accelerate_multi_key will allow multiple # private keys to be uploaded to it, though each user must # have access to the system via SSH to add a new key. The default # is "no". accelerate_multi_key = yes6.测试最后测试下在三台管理机器批量执行一个ping命令 ansible all -m ping

从上图可以看出,在每台管理机器上都成功执行了ping命令。

常用的一些批量执行命令:
ansible all -m command -a 'pwd'



 

相关内容推荐