ansible介绍
自动化运维工具,一般2000台以下按照ssh协议进行管理其他机器。
由python编码制作,其中带了非常多的模块,常用的模块
- file
- service
- yum
- copy
- fetch
- shell
- mysql
ansible的安装
yum -y install ansbile
或者在centos8下
yum -y install ansible-core
ansible的配置常用由2个
- /etc/ansible/hosts
host文件当中是可以分组的,比如
[mysql]
192.168.10.[10:20]
[web-servers]
192.168.10.132
192.168.10.123
默认的所有的主机都是all
- /etc/ansibe/ansible.cfg
ansible 免密功能
添加控制机和从机信任关系
在控制机器上生成公钥密钥
sshkey-gen
默认得生成得文件这里
~/.ssh
ssh_copy_id
以下参数可以避免客户端询问是不是接受公钥。
ssh -o StrictHostKeyChecking=no root@192.168.10.146
tee hosts <<EOF
192.168.10.233
192.168.10.224
EOF
for ip in `cat hosts` ; do sshpass -p 123456 ssh-copy-id -o StrictHostKeyChecking=no root@$ip ; done
测试安装模块
tee hosts <<EOF
[webserver]
192.168.10.127
192.168.10.128
192.168.10.122
[mysql]
192.168.10.145
192.168.10.146
EOF
ansible -i hosts mysql -m shell -a " yum -y install net-tools"
ansible -i hosts mysql -m yum -a "name=sysstat state=absent"
ansible -i hosts mysql -m yum -a “name=mariadb state=present”
ansible -i hosts mysql -m service -a “name=mariadb enabled=yes state=started”
作者:严锋 创建时间:2023-10-11 15:57
最后编辑:严锋 更新时间:2025-05-09 15:48
最后编辑:严锋 更新时间:2025-05-09 15:48