首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
清单首页运维文章详情

ansible调优

ansible性能降低的原因分析及解决方法

  1. ansible以ssh实现远程管理, 在连接时会检查/root/.ssh/known_host文件

解决方法: 修改ansible.cfg host_key_checking = False

  1. ssh的usedns选项

A主机在连接B时, B会根据A的ip地址进行ptr查询出A的主机名, 再利用A的主机名进行DNS查询, 确认其ip地址是否就是A的ip

解决方法:

代码语言:txt
复制

vim /etc/ssh/sshd_config

UseDNS no

GSSAPIAuthentication no # 一个认证方式, 具体没找到资料

代码语言:txt
复制
  1. ansible默认会获取受管主机的硬软件信息

解决方法: 1. 在playbook加上 gather_facts: False

代码语言:txt
复制
  					2. 使用facts缓存
代码语言:txt
复制

以硬盘缓存

gathering = smart

fact_caching_timeout = 86400

fact_caching = jsonfile

fact_caching_connection = /dev/shm/ansible_fact_cache #在该文件夹, facts以ip的文件的形式存储

以Redis缓存

gathering = smart

fact_caching_timeout = 86400

fact_caching = redis

fact_caching_connection = localhost:6379:0:passwd

代码语言:txt
复制
  1. ansible执行任务的流程是利用sftp上传任务文件到受管机, 然后远程执行

解决方法: 开启pipelining

注释: 在ansible需要使用sudo时不可使用, 原因: ssh源执行时登录的是非交互式shell, 不会分配tty, 因此无法输入密码, 可以通过sudo免密规避

  1. 开启ssh长连接

修改ansible.cfg

ssh_args = -C -o ControlMaster=auto -o ControlPersist=60sc

此时netstat可以看到连接状态一直是established

  1. ansible -t 将执行结果按主机名保存在指定目录下
下一篇
举报
领券