当前位置: 首页 > news >正文

衡阳网站建设如何做网页

衡阳网站建设,如何做网页,企业网站建设学习,企业网络营销项目ansible最佳实践 优化ansible速度 开启SSH长连接 修改 /etc/ansible/ansible.cfg里面的参数 ssh_args -C -o ControlMasterauto -o ControlPersist5d ControlPersist5d这个参数是设置整个长连接保持时间设置为5天,如果开启,通过SSH连接过的设备都会…

ansible最佳实践

优化ansible速度
开启SSH长连接

修改 /etc/ansible/ansible.cfg里面的参数

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

ControlPersist=5d这个参数是设置整个长连接保持时间设置为5天,如果开启,通过SSH连接过的设备都会在/ansible/cp目录下生成一个socket文件

开启pipelining

修改 /etc/ansible/ansible.cfg里面的参数pipelining=True

pipelining=True需要修改被控制主机的/etc/sudoerssed -i '/Defaults.*requiretty/a\Defaults:\ test\ !requiretty' /etc/sudoers #添加用户test !requiretty
sed -i "$a Defaults\:\ test\ \!requiretty" /etc/sudoers   #添加用户test !requiretty
编辑当前SSH用户配置为requiretty
开启ansible加速模式accelerate
1)  需要开启时首先要在远端机器安装 python-keyczar软件包
2)  需要在ansible-playbook的剧本文件中加入 accelerate: true
还需加入:[accelerate]
accelerate_port = 5099
accelerate_timeout = 30
accelerate_connect_timeout = 5.0
设置facts缓存
1)需要在ansible-playbook的剧本文件中加入 gather_facts: False  #可以直接关闭facts不收集远程主机信息2)设置facts缓存: /etc/ansible/ansible.cfg第一种方式:使用文件缓存gathering = smartfacts_caching_timeout = 86400  #  设置缓存过期时间86400秒facts_caching = jsonfile              #  cache文件是json格式facts_caching_connection = /tmp/ansible/ansible_facts_cache   #缓存文件的存储路径第二种方式:使用redis存储facts文件需安装redis;yum install redis ;还需要安装pip install redis的python库gathering = smartfacts_caching_timeout = 86400  #  设置缓存过期时间86400秒facts_caching = redis              # 使用redis          或者        facts_caching = memcached              #使用memcached#查看redis存储情况redis-cli               #登陆rediskeyd *                 #找到所有键select 0              #切换库get   键的名字    #查看值

常用模块

  1. ping 模块: 检查指定节点机器是否还能连通,用法很简单,不涉及参数,主机如果在线,则回复pong 。
  2. raw 模块: 执行原始的命令,而不是通过模块子系统。
  3. yum 模块: RedHat和CentOS的软件包安装和管理工具。
  4. apt 模块: Ubuntu/Debian的软件包安装和管理工具。
  5. pip 模块 : 用于管理Python库依赖项,为了使用pip模块,必须提供参数name或者requirements。
  6. synchronize 模块: 使用rsync同步文件,将主控方目录推送到指定节点的目录下。
  7. template 模块: 基于模板方式生成一个文件复制到远程主机(template使用Jinjia2格式作为文件模版,进行文档内变量的替换的模块。
  8. copy 模块: 在远程主机执行复制操作文件。
  9. user 模块 与 group 模块: user模块是请求的是useradd, userdel, usermod三个指令,goup模块请求的是groupadd, groupdel, groupmod 三个指令。
  10. service 或 systemd 模块: 用于管理远程主机的服务。
  11. get_url 模块: 该模块主要用于从http、ftp、https服务器上下载文件(类似于wget)。
  12. fetch 模块: 它用于从远程机器获取文件,并将其本地存储在由主机名组织的文件树中。
  13. file 模块: 主要用于远程主机上的文件操作。
  14. lineinfile 模块: 远程主机上的文件编辑模块
  15. unarchive模块: 用于解压文件。
  16. command模块 和 shell模块: 用于在各被管理节点运行指定的命令. shell和command的区别:shell模块可以特殊字符,而command是不支持
  17. hostname模块: 修改远程主机名的模块。
  18. script模块: 在远程主机上执行主控端的脚本,相当于scp+shell组合。
  19. stat模块: 获取远程文件的状态信息,包括atime,ctime,mtime,md5,uid,gid等信息。
  20. cron模块: 远程主机crontab配置。
  21. mount模块: 挂载文件系统。
  22. find模块: 帮助在被管理主机中查找符合条件的文件,就像 find 命令一样。
  23. selinux模块:远程管理受控节点的selinux的模块

环境变量

环境变量不生效

ansible-playbook register

---- hosts: allgather_facts: notasks:- name: register varsshell: hostnameregister: info- name: display varsdebug: msg="{{info.stdout}}"
     - shell: "uptime | awk '{print $5}' | awk -F',' '{print $1}'"register: temp_var - shell: "echo {{ temp_var.stdout_lines[0] }} >> /tmp/test.txt"

高版本兼容

版本内容

[root@l-opsmanager1 ~]# ansible --version
ansible 2.9.6config file = /etc/ansible/ansible.cfgconfigured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']ansible python module location = /usr/lib/python2.7/site-packages/ansibleexecutable location = /usr/bin/ansiblepython version = 2.7.5 (default, Aug  7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)][root@l-opsmanager1 ~]# ansible-playbook --version
ansible-playbook 2.9.6config file = /etc/ansible/ansible.cfgconfigured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']ansible python module location = /usr/lib/python2.7/site-packages/ansibleexecutable location = /usr/bin/ansible-playbookpython version = 2.7.5 (default, Aug  7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
ansible-playbook参数变化: -s参数变化
ansible-playbook 1.9.6
  -S, --su              run operations with su (deprecated, use become)-R SU_USER, --su-user=SU_USERrun operations with su as this user (default=root)(deprecated, use become)-s, --sudo            run operations with sudo (nopasswd) (deprecated, usebecome)-U SUDO_USER, --sudo-user=SUDO_USERdesired sudo user (default=root) (deprecated, usebecome)
ansible-playbook 2.9.6参数
Privilege Escalation Options:control how and which user you become as on target hosts--become-method BECOME_METHODprivilege escalation method to use (default=sudo), use`ansible-doc -t become -l` to list valid choices.--become-user BECOME_USERrun operations as this user (default=root)-K, --ask-become-passask for privilege escalation password-b, --become          run operations with become (does not imply passwordprompting)
范例
ansible-playbook 1.9.6

ansible-playbook -u root -k -s

ansible-playbook 2.9.6
Invalid characters were found in group names but not replaced, use -vvvv to see details
解决办法
pip install -i https://pypi.douban.com/simple --upgrade pip
pip install -i https://pypi.douban.com/simple  --upgrade setuptools
pip install -i https://pypi.douban.com/simple  chardet
pip install -i https://pypi.douban.com/simple urllib3
高版本 include_tasks替代了include
[WARNING]: While constructing a mapping from /data/ansible/playbooks/account/db/users.yml, line 2, column 3, found a duplicate dict key (dev). Using last defined value
only.
with_dict 变化: 值必须要 “{{}}” 这么处理
注意上面with_dict所提供的变量,使用引号包围起来。 如果直接写with_dict: files,会报"msg": "with_dict expects a dict", ansible版本2.6.x。对于1.9之前版本的应该可以。
key变化 相同/不同等级也不能有相同的key
[WARNING]: While constructing a mapping from /data/ansible/playbooks/account/db/users.yml, line 2, column 3, found a duplicate dict key (dev). Using last defined value
only.
group名 不能出现中横杆"-",警告如下
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
shell/command模块使用rm 会有警告信息,如下
[WARNING]: Consider using the file module with state=absent rather than running 'rm'.  If you need to use command because file is insufficient you can add 'warn: false'
to this command task or set 'command_warnings=False' in ansible.cfg to get rid of this message.

官网地址:
https://docs.ansible.com/ansible/latest/modules/shell_module.html#shell-module

范例
- name: rm -f reposhell: "rm -f $(find /etc/yum.repos.d/ -name '*.repo')"args:warn: no
主机组名
Invalid characters were found in group names but not replaced

警告如下

[DEPRECATION WARNING]: The TRANSFORM_INVALID_GROUP_CHARS settings is set to allow bad characters in group names by default, this will change, but still be user configurable on deprecation. This feature will be removedin version 2.10. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
主机组名 规范: 主机名内不能包含中横杆"-"

需要将 [bj4-k8s] 变更为 [bj4_k8s]

yum模块变更

原来的配置

- name: Install the monitor item dependency packageyum:name: "{{ item }}"state: latestwith_items:- 'sysstat'- 'php-cli'- 'php-mysql'

警告信息如下

[DEPRECATION WARNING]: Invoking "yum" only once while using a loop via squash_actions is deprecated. Instead of using a loop to supply multiple items and specifying `name: "{{ item }}"`, please use `name: 
['sysstat', 'php-cli', 'php-mysql']` and remove the loop. This feature will be removed in version 2.11. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.

解决办法

- name: Install the monitor item dependency packageyum:name: ['sysstat', 'php-cli', 'php-mysql']state: latest
内置变量
获取主机组的长度
- debug: msg={{ groups['ops'] | length }}
获取
{{ hostvars[groups['webservers'][0]]['ansible_eth0']['ipv4']['address'] }} 
ansible playbook Loops

loops循环使用

http://www.mmbaike.com/news/38145.html

相关文章:

  • 门户网站开发方案点击器原理
  • 宁波网站建设费用报价郑州网络推广公司
  • 安徽省住房建设厅网站篮网最新消息
  • 石家庄桥西网站制作公司百度推广开户费
  • 怎么做网站百度经验电脑培训网上课程
  • 网站搭建原理软文大全500篇
  • 东营招标建设信息网seo短期课程
  • 自己怎么做视频收费网站霸屏推广
  • 宣传推广计划seo流量软件
  • 英德网站建设十大最免费软件排行榜
  • 计算机网站建设推广策略包括哪些内容
  • 网页制作与网站建设宝典 pdf百度网盘官网登录入口
  • 网站跳转qq免费卖货平台
  • 新乡网站建设waterseo免费建站工具
  • 织梦 导航网站 模板网站查询域名解析
  • 如何自己做摄影网站网络营销实践总结报告
  • 网站建设服务协议书seo文章外包
  • 易网网站网站建设排名优化
  • 昆明公司网站太原企业网站建设
  • 做网站要多少钱联系方式小红书推广怎么做
  • 河北省建设信息中心网站培训班有哪些课程
  • 随机网站生成器域名注册平台哪个好
  • 网站用gbk还是utf8新品推广策划方案
  • 网站和做空间只需要手机号的广告
  • 青岛网站建设软件优化推广方案
  • 汽车行业网站设计网站在线制作
  • 哪里有网站制作价格百度世界排名
  • 做中英文网站免费视频网站推广软件
  • 邯郸教育网站建设seo优化推广
  • 长沙做网站建设公司湖南省最新疫情