Ansible_编写循环和条件任务
一、利用循环迭代任务
1️⃣:Ansible支持使用loop关键字对一组项目迭代任务,可以配置循环以利用列表中的各个项目、列表中各个文件的内容、生成的数字序列或更为复杂的结构来重复任务
1、简单循环
1️⃣:简单循环对一组项目迭代任务。loop关键字添加到任务中,将应对其迭代任务的项目列表取为值。循环变量item保存每个迭代过程中使用的值
- 演示实例:
- //查看playbook
- [root@localhost project]# cat playbook.yaml
- ---
- - hosts: all
- tasks:
- - name: create user
- user:
- name: "{{ item }}"
- state: present
- loop:
- - zhangsan
- - lisi
- //测试执行play
- [root@localhost project]# ansible-playbook playbook.yaml -C
- PLAY [all] ****************************************************************************************************************************************************************
- TASK [Gathering Facts] ****************************************************************************************************************************************************
- ok: [client.example.com]
- TASK [create user] ********************************************************************************************************************************************************
- changed: [client.example.com] => (item=zhangsan)
- changed: [client.example.com] => (item=lisi)
- PLAY RECAP ****************************************************************************************************************************************************************
- client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- //查看playbook
2️⃣:此外、还可以通过变量给loop提供所使用的的列表
- 演示实例:
- //查看playbook
- [root@localhost project]# cat playbook.yaml
- ---
- - hosts: all
- vars:
- users:
- - zhangsan
- - lisi
- - wangwu
- tasks:
- - name: create user
- user:
- name: "{{ item }}"
- state: present
- loop: "{{ users }}"
- //执行play
- [root@localhost project]# ansible-playbook playbook.yaml -C
- PLAY [all] ****************************************************************************************************************************************************************
- TASK [Gathering Facts] ****************************************************************************************************************************************************
- ok: [client.example.com]
- TASK [create user] ********************************************************************************************************************************************************
- changed: [client.example.com] => (item=zhangsan)
- changed: [client.example.com] => (item=lisi)
- changed: [client.example.com] => (item=wangwu)
- PLAY RECAP ****************************************************************************************************************************************************************
- client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- //查看playbook
2、循环散列或字典列表
1️⃣: loop列表不需要是简单值列表
- 演示实例:item标识一个循环的项目(任务),item.name和item.group表示item的两个键值(键值可自定义,但必须与loop中的项目匹配)
- //查看playbook文件
- [root@localhost project]# cat playbook.yaml
- ---
- - hosts: all
- tasks:
- - name: create user
- user:
- name: "{{ item.name }}"
- group: "{{ item.group}}"
- state: present
- loop:
- - name: zhangsan
- group: zhangsan
- - name: lisi
- group: lisi
- //测试是否可play
- [root@localhost project]# ansible-playbook playbook.yaml -C
- PLAY [all] ****************************************************************************************************************************************************************
- TASK [Gathering Facts] ****************************************************************************************************************************************************
- ok: [client.example.com]
- TASK [create user] ********************************************************************************************************************************************************
- changed: [client.example.com] => (item={'name': 'zhangsan', 'group': 'zhangsan'})
- changed: [client.example.com] => (item={'name': 'lisi', 'group': 'lisi'})
- PLAY RECAP ****************************************************************************************************************************************************************
- client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- //查看playbook文件
3、将Register变量于Loop一起使用
- 演示实例:
- //查看playbook
- [root@localhost project]# cat playbook.yaml
- ---
- - hosts: all
- tasks:
- - name: show some user
- shell: 'echo this user is {{ item }}'
- loop:
- - zhangsan
- - lisi
- - wangwu
- register: result
- - name: show these user
- debug:
- var: result
- //测试是否执行play
- [root@localhost project]# ansible-playbook playbook.yaml -C
- PLAY [all] ****************************************************************************************************************************************************************
- TASK [Gathering Facts] ****************************************************************************************************************************************************
- ok: [client.example.com]
- TASK [show some user] *****************************************************************************************************************************************************
- skipping: [client.example.com] => (item=zhangsan)
- skipping: [client.example.com] => (item=lisi)
- skipping: [client.example.com] => (item=wangwu)
- TASK [show these user]
- ............
- "item": "zhangsan",
- "msg": "skipped, running in check mode",
- "skipped": true
- ............
- "item": "lisi",
- "msg": "skipped, running in check mode",
- "skipped": true
- .............
- "item": "wangwu",
- "msg": "skipped, running in check mode",
- "skipped": true
- .............
- //查看playbook
1️⃣: 在上面的例子中,results键包含一个列表。在下面,修改了playbook,使第二个任务迭代此列表
- 演示实例:
- //查看playbook
- [root@localhost project]# cat playbook.yaml
- ---
- - hosts: all
- tasks:
- - name: show some user
- shell: 'echo this user is {{ item }}'
- loop:
- - zhangsan
- - lisi
- - wangwu
- register: magic
- - name: show these user
- debug:
- msg: "{{ item.stdout }}"
- loop: "{{ magic['results'] }}"
- //执行play
- [root@localhost project]# ansible-playbook playbook.yaml
- PLAY [all] ****************************************************************************************************************************************************************
- TASK [Gathering Facts] ****************************************************************************************************************************************************
- ok: [client.example.com]
- TASK [show some user] *****************************************************************************************************************************************************
- changed: [client.example.com] => (item=zhangsan)
- changed: [client.example.com] => (item=lisi)
- changed: [client.example.com] => (item=wangwu)
- TASK [show these user] ****************************************************************************************************************************************************
- ok: [client.example.com] => (item={'cmd': 'echo this user is zhangsan', 'stdout': 'this user is zhangsan', 'stderr': '', 'rc': 0, 'start': '2020-09-03 15:28:50.767109', 'end': '2020-09-03 15:28:50.774188', 'delta': '0:00:00.007079', 'changed': True, 'invocation': {'module_args': {'_raw_params': 'echo this user is zhangsan', '_uses_shell': True, 'warn': True, 'stdin_add_newline': True, 'strip_empty_ends': True, 'argv': None, 'chdir': None, 'executable': None, 'creates': None, 'removes': None, 'stdin': None}}, 'stdout_lines': ['this user is zhangsan'], 'stderr_lines': [], 'failed': False, 'item': 'zhangsan', 'ansible_loop_var': 'item'}) => {
- "msg": "this user is zhangsan"
- }
- ok: [client.example.com] => (item={'cmd': 'echo this user is lisi', 'stdout': 'this user is lisi', 'stderr': '', 'rc': 0, 'start': '2020-09-03 15:28:51.542241', 'end': '2020-09-03 15:28:51.547953', 'delta': '0:00:00.005712', 'changed': True, 'invocation': {'module_args': {'_raw_params': 'echo this user is lisi', '_uses_shell': True, 'warn': True, 'stdin_add_newline': True, 'strip_empty_ends': True, 'argv': None, 'chdir': None, 'executable': None, 'creates': None, 'removes': None, 'stdin': None}}, 'stdout_lines': ['this user is lisi'], 'stderr_lines': [], 'failed': False, 'item': 'lisi', 'ansible_loop_var': 'item'}) => {
- "msg": "this user is lisi"
- }
- ok: [client.example.com] => (item={'cmd': 'echo this user is wangwu', 'stdout': 'this user is wangwu', 'stderr': '', 'rc': 0, 'start': '2020-09-03 15:28:52.292883', 'end': '2020-09-03 15:28:52.298768', 'delta': '0:00:00.005885', 'changed': True, 'invocation': {'module_args': {'_raw_params': 'echo this user is wangwu', '_uses_shell': True, 'warn': True, 'stdin_add_newline': True, 'strip_empty_ends': True, 'argv': None, 'chdir': None, 'executable': None, 'creates': None, 'removes': None, 'stdin': None}}, 'stdout_lines': ['this user is wangwu'], 'stderr_lines': [], 'failed': False, 'item': 'wangwu', 'ansible_loop_var': 'item'}) => {
- "msg": "this user is wangwu"
- }
- PLAY RECAP ****************************************************************************************************************************************************************
- client.example.com : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- //查看playbook
二、有条件的运行任务
Ansible可使用conditionals在符合特定条件时执行任务或play。例如,可以利用一个条件在Ansible安装或配置服务前确定受管主机上的可用内存
1、条件任务语法
1️⃣:when语句用于有条件地运行任务;它取要测试的条件为值。如果条件满足,则运行任务。如果条件不满足,则跳过任务
- 演示实例:
- //查看playbook
- [root@localhost project]# cat playbook.yaml
- ---
- - hosts: all
- vars:
- package: True
- tasks:
- - name: install httpd
- yum:
- name: httpd
- state: installed
- when: package
- //测试执行play
- [root@localhost project]# ansible-playbook playbook.yaml
- PLAY [all] ****************************************************************************************************************************************************************
- TASK [Gathering Facts] ****************************************************************************************************************************************************
- ok: [client.example.com]
- TASK [install httpd] ******************************************************************************************************************************************************
- changed: [client.example.com]
- PLAY RECAP ****************************************************************************************************************************************************************
- client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- //查看playbook
2️⃣:处理条件时可使用的一些运算示例:
操作 | 示例 |
---|---|
等于(值为字符串) | ansible_machine == "x86_64" |
等于(值为数字) | max_memory == 512 |
小于 | min_memory < 128 |
大于 | min_memory > 256 |
小于等于 | min_memory <= 256 |
大于等于 | min_memory >= 512 |
不等于 | min_memory != 512 |
变量存在 | min_memory is defined |
变量不存在 | min_memory is not defined |
布尔变量是True。1、True或yes的求值为True | memory_available |
布尔变量是False。0、False或no的求值为False | not memory_available |
第一个变量的值存在,作为第二个变量的列表中的值 | ansible_distribution in supported_distros |
- 演示实例一:
- //查看playbook
- [root@localhost project]# cat playbook.yaml
- ---
- - hosts: all
- vars:
- package: httpd
- tasks:
- - name: install {{ package }}
- yum:
- name: "{{ package }}"
- state: present
- when: package is defined
- //执行play
- [root@localhost project]# ansible-playbook playbook.yaml
- PLAY [all] ****************************************************************************************************************************************************************
- TASK [Gathering Facts] ****************************************************************************************************************************************************
- ok: [client.example.com]
- TASK [install httpd] ******************************************************************************************************************************************************
- changed: [client.example.com]
- PLAY RECAP ****************************************************************************************************************************************************************
- client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- //查看playbook
- 演示实例二:第一个变量的值存在(一般是事实),且作为第二个变量列表中的值
- //查看playbook
- [root@localhost project]# cat playbook.yaml
- ---
- - hosts: all
- vars:
- version:
- - RedHat
- - CentOS
- tasks:
- - name: install httpd
- yum:
- name: httpd
- state: present
- when: ansible_facts['distribution'] in version //ansible_facts['distribution']该变量的值与versionversion中的值匹配
- //执行play
- [root@localhost project]# ansible-playbook playbook.yaml
- PLAY [all] ****************************************************************************************************************************************************************
- TASK [Gathering Facts] ****************************************************************************************************************************************************
- ok: [client.example.com]
- TASK [install httpd] ******************************************************************************************************************************************************
- changed: [client.example.com]
- PLAY RECAP ****************************************************************************************************************************************************************
- client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- //查看playbook
- 演示实例三:(判断大小)
- //查看playbook
- [root@localhost project]# cat playbook.yaml
- ---
- - hosts: all
- vars:
- number: 800
- tasks:
- - name: install httpd
- yum:
- name: httpd
- state: present
- when: number >= 800
- //执行play
- [root@localhost project]# ansible-playbook playbook.yaml
- PLAY [all] ****************************************************************************************************************************************************************
- TASK [Gathering Facts] ****************************************************************************************************************************************************
- ok: [client.example.com]
- TASK [install httpd] ******************************************************************************************************************************************************
- changed: [client.example.com]
- PLAY RECAP ****************************************************************************************************************************************************************
- client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- //查看playbook
2、测试多个条件
1️⃣:一个when语句可用于评估多个条件:使用and和or关键字组合条件,并使用括号分组条件
2️⃣:使用and语句运算时,两个条件必须为真,才能满足整个条件语句
- 演示实例一:and 语句第一种写法
- //查看playbook
- [root@localhost project]# cat playbook.yaml
- ---
- - hosts: all
- tasks:
- - name: install httpd
- yum:
- name: httpd
- state: present
- when: ansible_facts['distribution_version'] == "8.1" and ansible_facts['distribution'] == "RedHat"
- //执行play
- [root@localhost project]# ansible-playbook playbook.yaml
- PLAY [all] ****************************************************************************************************************************************************************
- TASK [Gathering Facts] ****************************************************************************************************************************************************
- ok: [client.example.com]
- TASK [install httpd] ******************************************************************************************************************************************************
- changed: [client.example.com]
- PLAY RECAP ****************************************************************************************************************************************************************
- client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- //查看playbook
- 演示实例二:and 语句第二种写法
- //查看playbook
- [root@localhost project]# cat playbook.yaml
- ---
- - hosts: all
- tasks:
- - name: install httpd
- yum:
- name: httpd
- state: present
- when:
- - ansible_facts['distribution_version'] == "8.1"
- - ansible_facts['distribution'] == "RedHat"
- //执行play
- [root@localhost project]# ansible-playbook playbook.yaml
- PLAY [all] ****************************************************************************************************************************************************************
- TASK [Gathering Facts] ****************************************************************************************************************************************************
- ok: [client.example.com]
- TASK [install httpd] ******************************************************************************************************************************************************
- changed: [client.example.com]
- PLAY RECAP ****************************************************************************************************************************************************************
- client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- //查看playbook
- 演示实例三:and 语句第三中写法
- //查看playbook
- [root@localhost project]# cat playbook.yaml
- ---
- - hosts: all
- tasks:
- - name: install httpd
- yum:
- name: httpd
- state: present
- when:
- ( ansible_facts['distribution_version'] == "8.1" )
- and
- ( ansible_facts['distribution'] == "RedHat" )
- //执行play
- [root@localhost project]# ansible-playbook playbook.yaml
- PLAY [all] ****************************************************************************************************************************************************************
- TASK [Gathering Facts] ****************************************************************************************************************************************************
- ok: [client.example.com]
- TASK [install httpd] ******************************************************************************************************************************************************
- changed: [client.example.com]
- PLAY RECAP ****************************************************************************************************************************************************************
- client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- //查看playbook
3️⃣:使用or语句时,其中任一条件为真时,就能满足条件语句
- 演示实例一:or 语句第一种写法
- //查看playbook
- [root@localhost project]# cat playbook.yaml
- ---
- - hosts: all
- tasks:
- - name: install httpd
- yum:
- name: httpd
- state: present
- when: ansible_facts['distribution'] == "RedHat" or ansible_facts['distribution_version'] == "7.9"
- //执行play
- [root@localhost project]# ansible-playbook playbook.yaml
- PLAY [all] ****************************************************************************************************************************************************************
- TASK [Gathering Facts] ****************************************************************************************************************************************************
- ok: [client.example.com]
- TASK [install httpd] ******************************************************************************************************************************************************
- changed: [client.example.com]
- PLAY RECAP ****************************************************************************************************************************************************************
- client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- //我当前使用的是RHEL8.1版本
- //查看playbook
- 演示实例二:or 语句第二种写法
- [root@localhost project]# cat playbook.yaml
- ---
- - hosts: all
- tasks:
- - name: install httpd
- yum:
- name: httpd
- state: present
- when: > //这里可以加,也可以不加;>:是允许下面的变量可以换行写
- ( ansible_facts['distribution'] == "RedHat" )
- or
- ( ansible_facts['distribution_version'] == "7.9 )"
- //执行play
- [root@localhost project]# ansible-playbook playbook.yaml
- PLAY [all] ****************************************************************************************************************************************************************
- TASK [Gathering Facts] ****************************************************************************************************************************************************
- ok: [client.example.com]
- TASK [install httpd] ******************************************************************************************************************************************************
- changed: [client.example.com]
- PLAY RECAP ****************************************************************************************************************************************************************
- client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- [root@localhost project]# cat playbook.yaml
- 演示实例三:or 语句的第三种写法(与and语句嵌套使用)
- //查看playbook
- [root@localhost project]# cat playbook.yaml
- ---
- - hosts: all
- tasks:
- - name: install httpd
- yum:
- name: httpd
- state: present
- when:
- ( ansible_facts['distribution'] == "RedHat" and ansible_facts['kernel'] == "4.18.0-147.el8.x86_64" )
- or
- ( ansible_facts['distribution_version'] == "7.9" and ansible_facts['distribution_major_version'] == "7" )
- //执行play
- [root@localhost project]# ansible-playbook playbook.yaml
- PLAY [all] ****************************************************************************************************************************************************************
- TASK [Gathering Facts] ****************************************************************************************************************************************************
- ok: [client.example.com]
- TASK [install httpd] ******************************************************************************************************************************************************
- changed: [client.example.com]
- PLAY RECAP ****************************************************************************************************************************************************************
- client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- //查看playbook
三、组合循环和有条件任务
1、使用Loop和When组合使用
- 演示实例:
- //查看playbook
- [root@localhost project]# cat playbook.yaml
- ---
- - hosts: all
- tasks:
- - name: install httpd
- yum:
- name: httpd
- state: present
- loop: "{{ ansible_facts['mounts'] }}"
- when:
- - item.mount == "/"
- - item.size_available > 50000000000
- //执行paly
- [root@localhost project]# ansible-playbook playbook.yaml
- PLAY [all] ****************************************************************************************************************************************************************
- TASK [Gathering Facts] ****************************************************************************************************************************************************
- ok: [client.example.com]
- TASK [install httpd] ******************************************************************************************************************************************************
- changed: [client.example.com] => (item={'mount': '/', 'device': '/dev/mapper/rhel-root', 'fstype': 'xfs', 'options': 'rw,seclabel,relatime,attr2,inode64,noquota', 'size_total': 53660876800, 'size_available': 51805659136, 'block_size': 4096, 'block_total': 13100800, 'block_available': 12647866, 'block_used': 452934, 'inode_total': 26214400, 'inode_available': 26178405, 'inode_used': 35995, 'uuid': '6a525cf5-3f23-4639-81cb-04fcdb764eb6'})
- skipping: [client.example.com] => (item={'mount': '/home', 'device': '/dev/mapper/rhel-home', 'fstype': 'xfs', 'options': 'rw,seclabel,relatime,attr2,inode64,noquota', 'size_total': 28922376192, 'size_available': 28686655488, 'block_size': 4096, 'block_total': 7061127, 'block_available': 7003578, 'block_used': 57549, 'inode_total': 14129152, 'inode_available': 14129137, 'inode_used': 15, 'uuid': '2840f839-89b2-4717-b1d0-c74c46d05019'})
- skipping: [client.example.com] => (item={'mount': '/boot', 'device': '/dev/nvme0n1p1', 'fstype': 'xfs', 'options': 'rw,seclabel,relatime,attr2,inode64,noquota', 'size_total': 1063256064, 'size_available': 882565120, 'block_size': 4096, 'block_total': 259584, 'block_available': 215470, 'block_used': 44114, 'inode_total': 524288, 'inode_available': 523987, 'inode_used': 301, 'uuid': '234365dc-2262-452e-9cbb-a6acfde04385'})
- skipping: [client.example.com] => (item={'mount': '/mnt', 'device': '/dev/sr0', 'fstype': 'iso9660', 'options': 'ro,relatime,nojoliet,check=s,map=n,blocksize=2048', 'size_total': 7851202560, 'size_available': 0, 'block_size': 2048, 'block_total': 3833595, 'block_available': 0, 'block_used': 3833595, 'inode_total': 0, 'inode_available': 0, 'inode_used': 0, 'uuid': '2019-10-15-13-34-03-00'})
- PLAY RECAP ****************************************************************************************************************************************************************
- client.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- //查看playbook
2、使用Register和When组合使用
- 演示实例:
- //查看playbook
- [root@localhost project]# cat playbook.yaml
- ---
- - hosts: all
- tasks:
- - name: install httpd
- yum:
- name: httpd
- state: present
- ignore_errors: yes //在运行时,如果出现错误且命令失败,将不会停止,继续执行其他的命令
- register: result //将安装成功后的结果注册到result变量中
- - name: start httpd
- service:
- name: httpd
- state: started
- when: result.rc == 0 //在该变量中匹配到返回值rc=0执行该命令
- //执行play
- [root@localhost project]# ansible-playbook playbook.yaml
- PLAY [all] ****************************************************************************************************************************************************************
- TASK [Gathering Facts] ****************************************************************************************************************************************************
- ok: [client.example.com]
- TASK [install httpd] ******************************************************************************************************************************************************
- changed: [client.example.com]
- TASK [start httpd] ********************************************************************************************************************************************************
- changed: [client.example.com]
- PLAY RECAP ****************************************************************************************************************************************************************
- client.example.com : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- //查看playbook
下一篇:实施处理程序
Ansible_编写循环和条件任务的更多相关文章
- python Django教程 之模板渲染、循环、条件判断、常用的标签、过滤器
python3.5 manage.py runserver python Django教程 之模板渲染.循环.条件判断.常用的标签.过滤器 一.Django模板渲染模板 1. 创建一个 zqxt_tm ...
- Java循环和条件
下列程序的输出结果是什么? 1.Java循环和条件 /** * @Title:IuputData.java * @Package:com.you.data * @Description:TODO * ...
- 第二天:python的函 数、循环和条件、类
https://uqer.io/community/share/54c8af17f9f06c276f651a54 第一天学习了Python的基本操作,以及几种主要的容器类型,今天学习python的函数 ...
- Java 控制语句:循环、条件判断
基础很重要,基础很重要,基础很重要.重要的事情说三遍,. 程序设计中的控制语句主要有三种:顺序.分支和循环.我们每天写的代码,除了业务相关,里面会包含大量的控制语句.但是控制语句的基本使用,是否有些坑 ...
- javascript面向对象编程笔记(基本数据类型,数组,循环及条件表达式)
javascript面向对象编程指南 最近在看这本书,以下是我的笔记,仅供参考. 第二章 基本数据类型.数组.循环及条件表达式 2.1 变量 区分大小写 2.3 基本数据类型 数字:包括浮点数与整数 ...
- SQL中循环和条件语句
.if语句使用示例: declare @a int begin print @a end else begin print 'no' end .while语句使用示例: declare @i int ...
- Ansible系列(六):循环和条件判断
本文目录:1. 循环 1.1 with_items迭代列表 1.2 with_dict迭代字典项 1.3 with_fileglob迭代文件 1.4 with_lines迭代行 1.5 with_ne ...
- PHP和JS在循环、条件判断中的不同之处
一.条件判断: php中算 false 的情况 1. boolean:false 2. 整形:0 3.浮点型:0 4.字符串:"" "0"(其他都对) 5.空 ...
- SqlServer中循环和条件语句
if语句使用示例 declare @a int set @a=12 if @a>100 begin ...
随机推荐
- [Fundamental of Power Electronics]-PART II-8. 变换器传递函数-8.3 阻抗和传递函数图形的构建
8.3 阻抗和传递函数图形的构建 通常,我们可以通过观察来绘制近似的bode图,这样没有大量混乱的代数和不可避免的有关代数错误.使用这种方法可以对电路运行有较好的了解.在各种频率下哪些元件主导电路的响 ...
- java面试-JVM常用的基本配置参数有哪些?
1.-Xms 初始大小内存,默认为物理内存 1/64,等价于 -XX:InitialHeapSize 2.-Xmx 最大分配内存,默认为物理内存的 1/4,等价于 -XX:MaxHeapSize 3. ...
- 一文彻底搞定Hystrix!
前言 Netflix Hystrix断路器是什么? Netflix Hystrix是SOA/微服务架构中提供服务隔离.熔断.降级机制的工具/框架.Netflix Hystrix是断路器的一种实现,用于 ...
- DDD实战让中台和微服务的落地如虎添翼
微服务到底怎么拆分和设计才算合理,拆多小才叫微服务?有没有好的方法来指导微服务和中台的设计呢? 深入DDD的核心知识体系与设计思想,带你掌握一套完整而系统的基于DDD的微服务拆分与设计方法,助力落地边 ...
- 用递归求出n的全排列
1 include<cstdio> 2 const int maxn = 11; 3 int n,p[maxn], hashTable[maxn] = { false };//hashta ...
- 浅谈 Fresco 框架结构
在前面的文章 Fresco 源码分析 -- 图片加载流程 里面详细说明了图片加载的整个流程,但是除了理解源码之外,对于源码的框架层面的设计也是需要去了解的,不能只是简单的读源码,好的源码的框架设计也是 ...
- 深入学习spring cloud gateway 限流熔断
前言 Spring Cloud Gateway 目前,Spring Cloud Gateway是仅次于Spring Cloud Netflix的第二个最受欢迎的Spring Cloud项目(就GitH ...
- QT程序发布
1.新建一个脚本文件,后缀为.bat 2.查看自己qt的windeployqt.exe路径,一般在QT安装的bin目录,而且脚本程序中需要去掉其后缀, 前面部分是windeployqt.exe的路径以 ...
- shell脚本 4 函数与正则
shell函数 shell中允许将一组命令集合或语句形成一段可用代码,这些代码块称为shell函数.给这段代码起个名字称为函数名,后续可以直接调用该段代码. 格式 func() { #指定函数名 ...
- Floyd算法C++实现与模板题应用
简介 Floyd算法算是最简单的算法,没有之一. 其状态转移方程如下map[i , j] =min{ map[i , k] + map[k , j] , map[i , j] }: map[i , j ...