ansible速度优化

栏目: 服务器 · 发布时间: 6年前

内容简介:ansible速度优化

有人说 ansible 的执行效率比价差,但是可以通过很多的优化去调整执行速度

$ time ansible centos -m ping -o
192.168.56.101 | SUCCESS => {"changed": false, "ping": "pong"}
192.168.56.102 | SUCCESS => {"changed": false, "ping": "pong"}

real	0m1.298s
user	0m0.479s
sys	0m0.217s

开启ssh长连接

OpenSSH 5.6 版本后 SSH 支持了 Multiplexing ,关于这个特性可以参考文章 Multiplexing

修改 ansible.cfg 文件

设置参数

ssh_args = -C -o ControlMaster=auto -o ControlPersist=5d

ControlPersist=5d //长连接时间保持5天

开启后,通过 SSH 连接过的设备会在当前目录 .ansible/cp/ 目录下生成一个 socket 文件,通过 netstat 命令会看到,有 ESTABLISHED 状态的连接一直与远端社保进行 tcp 连接

开启pipelining

执行流程优化

需要被控制主机 /etc/sudoers 文件编辑当前 ansible ssh 用户的配置为 requiretty 。否则在执行的时候会提示 sudo: sorry, you must have a tty to run sudo

设置参数

pipelining = True

开启accelerate模式

accelerate 在远端服务器上运行一个守护进程。

注意:开启 accelerate 需要在管理与被管理端都安装 python-keyczar 软件包。

设置参数

[accelerate]
#accelerate_port = 5099
#accelerate_timeout = 30
#accelerate_connect_timeout = 5.0

开启facts缓存

如果你不使用 facts 里的信息,可以在 playbook 中设置 gather_facts: False 来提交效

设置参数

使用 json 文件存储 facts 信息

gathering = smart
fact_caching_timeout = 86400 
fact_caching = jsonfile 
fact_caching_connection = /dev/shm/ansible_fact_cache

目前 facts 存储还不支持远端,所以需要在 ansible 管理机上安装 redis 服务,然后安装 redis python 库。 pip install redis
设置参数

gathering = smart
fact_caching_timeout = 86400
fact_caching = redis

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Machine Learning

Machine Learning

Kevin Murphy / The MIT Press / 2012-9-18 / USD 90.00

Today's Web-enabled deluge of electronic data calls for automated methods of data analysis. Machine learning provides these, developing methods that can automatically detect patterns in data and then ......一起来看看 《Machine Learning》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具