【devops】devops-ansible之介绍和基础使用

 本站以分享各种运维经验和运维所需要的技能为主

《python零基础入门》:python零基础入门学习

《python运维脚本》: python运维脚本实践

《shell》:shell学习

《terraform》持续更新中:terraform_Aws学习零基础入门到最佳实战

《k8》从问题中去学习k8s

《docker学习》暂未更新

《ceph学习》ceph日常问题解决分享

《日志收集》ELK+各种中间件

《运维日常》运维日常

《linux》运维面试100问

《DBA》db的介绍使用(mysql、redis、mongodb...)

 

Ansible概述

Ansible是什么

# 介绍
Ansible是一个自动化统一配置管理工具,自动化主要体现在Ansible集成了丰富模块以及功能组件,可以通过一个命令完成一系列的操作,进而能减少重复性的工作和维护成本,可以提高工作效率。
​
# 主要功能:
· 批量命令执行
· 批量安装服务
· 批量配置同步
· 批量任务执行
· 批量代码部署
​
# 优势及功能
1.远程执行
批量执行远程命令,可以对多台主机进行远程操作
​
2.配置管理
批量配置软件服务,可以进行自动化方式配置,服务的统一配置管理,和启停
​
3.事件驱动
通过Ansible的模块,对服务进行不同的事件驱动
比如:
1)修改配置后重启
2)只修改配置文件,不重启
3)修改配置文件后,重新加载
4)远程启停服务管理
​
4.管理公有云
通过API接口的方式管理公有云,不过这方面做的不如saltstack.
saltstack本身可以通过saltcloud管理各大云厂商的云平台。
​
5.二次开发
因为语法是Python,所以便于运维进行二次开发。
​
6.任务编排
可以通过playbook的方式来统一管理服务,并且可以使用一条命令,实现一套架构的部署
​
7.跨平台,跨系统
几乎不受到平台和系统的限制,比如安装apache和启动服务
在Ubuntu上安装apache服务名字叫apache2
在CentOS上安装apache服务名字叫httpd
在CentOS6上启动服务器使用命令:/etc/init.d/nginx start
在CentOS7上启动服务器使用命令:systemctl start nginx
​
# ansible读取顺序
1、$ANSIBLE_CONFIG
2、./ansible.cfg
3、~/.ansible.cfg
4、/etc/ansible/ansible.cfg

Ansible的架构

# 架构组成
1、连接插件connection plugins用于连接主机 用来连接被管理端
2、核心模块core modules连接主机实现操作, 它依赖于具体的模块来做具体的事情
3、自定义模块custom modules根据自己的需求编写具体的模块
4、插件plugins完成模块功能的补充
5、剧本playbookansible的配置文件,将多个任务定义在剧本中,由ansible自动执行
6、主机清单inventor定义ansible需要操作主机的范围,让ansible知道我都需要维护哪些主机
最重要的一点是 ansible是模块化的 它所有的操作都依赖于模块# ansible执行流程
1.Ansible读取playbook剧本,剧本中会记录对哪些主机执行哪些任务。
2.首先Ansible通过主机清单找到要执行的主机,然后调用具体的模块。
3.其次Ansible会通过连接插件连接对应的主机并推送对应的任务列表。
4.最后被管理的主机会将Ansible发送过来的任务解析为本地Shell命令执行。

img

Ansible同类型产品优缺点

# 同类产品介绍
1.puppet 学习难,安装ruby环境难,没有远程执行功能
2.ansible 轻量级,大规模环境下只通过ssh会很慢,串行的
3.saltstack 一般选择salt会使用C/S结构的模式,salt-master和salt-minion,并行的,大规模批量操作的情况下,会比Ansible速度快一些,底层使用的是zero-MQ消协队列# 面试提问:你们公司使用什么自动化运维工具
可针对saltstack和ansible做比较,两者各有优缺点
· 如saltstack不需要依赖ssh服务,当ssh服务停止,远程无法连接至服务器,还可通过saltstack对ssh服务启动,但需要依赖客户端,每台客户端中都需要安装saltstack,emmmmm也不绝对,比如saltstack安装时仅安装salt-ssh就和ansible一样支持ssh服务(这种方式很少使用,一般都是C/S结构),这样就不需要进行客户端安装。
· ansible不需要依赖客户端,但依赖ssh服务,一旦ssh服务停止,那么ansible也无法使用,并且修改任何相关文件,ansible也不需要启动任何服务,即改及用。
同类型产品saltstack介绍
# 注意:saltstack三个重要组成· salt-master 服务端安装· alt-minion 客户端安装· salt-ssh 使saltstack不需要依赖客户端,依赖ssh服务,和ansible一样# 1.安装服务端和客户端
[root@m01 ~]# yum install -y salt-master salt-minion# 2.客户端
[root@web01 ~]# yum install -y  salt-minion# 3.修改客户端的配置文件(客户端指定服务端ip)
[root@web01 ~]# vim /etc/salt/minion
master: 10.0.0.61
[root@m01 ~]# vim /etc/salt/minion
master: 10.0.0.61# 4.启动服务端,再启动客户端
[root@m01 ~]# systemctl start salt-master salt-minion
[root@web01 ~]# systemctl start salt-minion# 认证key
[root@m01 ~]# salt-key 
Accepted Keys:
Denied Keys:
Unaccepted Keys:
m01
web01
Rejected Keys:### 认证1个key
[root@m01 ~]# salt-key -a web01
### 全部认证
[root@m01 ~]# salt-key -A# salt使用方法
## ping认证主机,*代表所有认证主机
[root@m01 ~]# salt '*' test.ping## 对所有认证主机执行创建文件操作
[root@m01 ~]# salt '*' cmd.run 'touch /root/zls123_456.txt'# 简单模块介绍
test
cmd
service

Ansible安装及主配置文件介绍

# 1.ansible使用必须具备epel源
[root@m01 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo# 2.安装ansible
[root@m01 ~]# yum install -y ansible# 3.ansible配置文件介绍(一般只需要开启跳过检查主机指纹,其他按照默认即可)
[root@m01 ~]# cat /etc/ansible/ansible.cfg 
#inventory      = /etc/ansible/hosts      #主机列表配置文件
#library        = /usr/share/my_modules/  #库文件存放目录
#remote_tmp     = ~/.ansible/tmp          #临时py文件存放在远程主机目录
#local_tmp      = ~/.ansible/tmp          #本机的临时执行目录
#forks          = 5                       #默认并发数
#sudo_user      = root                    #默认sudo用户
#ask_sudo_pass = True                     #每次执行是否询问sudo的ssh密码
#ask_pass      = True                     #每次执行是否询问ssh密码
#remote_port    = 22                      #远程主机端口
host_key_checking = False                 #跳过检查主机指纹(首次通过ssh服务连接,false为跳过)
log_path = /var/log/ansible.log           #ansible日志# 4.查看Ansible版本及模块路径
[root@m01 ~]# ansible --version
ansible 2.9.9config 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, Oct 30 2018, 23:45:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]

Ansible Inventory

# ansible inventory 主机清单介绍
/etc/ansible/hosts是ansible默认主机资产清单文件,用于定义被管理主机的认证信息, 例如ssh登录用户名、密码以及key相关信息。Inventory文件中填写需要被管理的主机与主机组信息。还可以自定义Inventory主机清单的位置,使用-i指定文件位置即可。建议使用方式:场景三:主机组变量+主机+密钥
场景一:基于密码连接
[root@m01 ~]# cat /etc/ansible/hosts
建议:不要使用#方式一、IP+端口+用户+密码
[webs]
10.0.0.7 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass='1'
10.0.0.8 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass='1'#方式二、主机名+密码,此方式需要在/etc/hosts文件中写入web01和web02的对应ip地址信息
。。。。解释一下:下方web0[1:2]代表两个主机名web01和web02
[webs]
web0[1:2] ansible_ssh_pass='123456'#方式三、主机+端口+密码
[webs]
web0[1:2]
[webs:vars]
ansible_ssh_pass='123456'[root@m01 ~]# ansible webs -m ping -i ./hosts
10.0.0.8 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": false,"ping": "pong"
}
10.0.0.7 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": false,"ping": "pong"
}
场景二:基于密钥连接,需要先创建公钥和私钥,并下发公钥至被控端
#创建秘钥对
[root@m01 ~]# ssh-keygen#推送公钥
[root@m01 ~]# ssh--id -i ~/.ssh/id_rsa.pub root@172.16.1.7
[root@m01 ~]# ssh--id -i ~/.ssh/id_rsa.pub root@172.16.1.8
#方式一、主机+端口+密钥
[webs]
10.0.0.7:22
10.0.0.8[root@m01 ~]# ansible webs -m ping -i ./hosts
10.0.0.8 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": false,"ping": "pong"
}
10.0.0.7 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": false,"ping": "pong"
}#方式二、别名+主机+端口+密钥
[webs]
web01 ansible_ssh_host=10.0.0.7 ansible_ssh_port=22
web02 ansible_ssh_host=10.0.0.8[root@m01 ~]# ansible webs -m ping -i ./hosts
web02 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": false,"ping": "pong"
}
web01 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": false,"ping": "pong"
}
场景三:主机组使用方式
[root@m01 ~]# vim hosts
[db_group]
db01 ansible_ssh_host=10.0.0.51
db02 ansible_ssh_host=10.0.0.52[web_group]
web01 ansible_ssh_host=10.0.0.7
web02 ansible_ssh_host=10.0.0.8#查看指定组内主机数量
[root@m01 ~]# ansible web_group -m ping -i ./hosts  --list-hosthosts (2):web01web02[root@m01 ~]# ansible db_group -m ping -i ./hosts  --list-hosthosts (2):db01db02#方式一、主机组变量+主机+密码
[db_group]
db01 ansible_ssh_host=10.0.0.51
db02 ansible_ssh_host=10.0.0.52
[db_group:vars]
ansible_ssh_pass='1'#方式二、主机组变量+主机+密钥
[web_group]
web01 ansible_ssh_host=10.0.0.7
web02 ansible_ssh_host=10.0.0.8#定义多组,多组汇总整合
# lnmp组包括两个子组[db,web]
[lnmp:children]
db_group
web_group#最终配置文件
[root@m01 ~]# cat hosts
[db_group]
db01 ansible_ssh_host=10.0.0.51
db02 ansible_ssh_host=10.0.0.52[web_group]
web01 ansible_ssh_host=10.0.0.7
web02 ansible_ssh_host=10.0.0.8[lnmp:children]
db_group
web_group#查看多组
[root@m01 ~]# ansible all -m ping -i ./hosts  --list-hosthosts (4):db01db02web01web02
[root@m01 ~]# ansible lnmp -m ping -i ./hosts  --list-hosthosts (4):db01db02web01web02

ansible 的 ad-hoc(临时命令)

  • ad-hoc简而言之就是“临时命令”,执行完即结束,并不会保存

## ansible的选项
-m:指定模块
-a:指定动作
-i: 指定主机清单

img

# 查看指定模块帮助(输入后按EXAMPLE查找案例操作)
ansible-doc 模块名# 查看web_group组内对应主机
[root@m01 ~]# ansible web_group --list-host# 临时命令返回颜色指南:
绿色:被控端,主机没有发生更改
黄色:被控端,主机发生变更
粉色:ansible发出警告
红色:报错

模块

  • command

## 作用:执行系统命令
但是,不认识管道符等一些特殊字符
使用shell取代
  • shell

# 功能强大,很多命令都支持,但是不建议使用,不同功能用不同模块,必须cp可以用shell模块实现,但建议使用指定cp模块
[root@m01 ~]# ansible web01 -m shell -a 'df -h'
  • script

# 可使用管理端的脚本,直接对被管理端生效,无需将脚本复制到到被管理端,比如:客户端有100来台,只需将脚本保存在管理端,在管理端执行脚本,客户端都能受用。
[root@m01 ~]# ansible web01 -m script -a '/root/a.sh'
  • yum

# yum update -y nfs-utils
ansible web_group -m yum -a 'name=nfs-utils state=latest'# yum install -y net-tools
[root@m01 ~]# ansible web_group -m yum -a 'name=net-tools state=present'# yum remove -y tree
[root@m01 ~]# ansible web_group -m yum -a 'name=tree state=absent'# yum 指定网络的rpm包
yum install -y https://mirrors.aliyun.com/zabbix/zabbix/4.4/rhel/7/x86_64/zabbix-agent-4.4.4-1.el7.x86_64.rpm 
[root@m01 ~]# ansible web_group -m yum -a 'name=https://mirrors.aliyun.com/zabbix/zabbix/4.4/rhel/7/x86_64/zabbix-agent-4.4.4-1.el7.x86_64.rpm state=present'# yum localinstall -y nginx-1.18.0-1.el7.ngx.x86_64.rpm
[root@m01 ~]# ansible backup -m yum -a 'name=/root/nginx-1.18.0-1.el7.ngx.x86_64.rpm state=present'## 掌握的方法:
name:指定服务名:yum install -y tree指定网络包:yum install -y https://mirrors.aliyun.com/zabbix/zabbix/4.4/rhel/7/x86_64/zabbix-agent-4.4.4-1.el7.x86_64.rpm指定本地包:yum local install -y nginx-1.18.0-1.el7.ngx.x86_64.rpmstate:present:正经安装absent:删除,卸载latest:安装最新版本
  • yum_repository

##添加yum仓库
[root@m01 ~]# ansible web_group -m yum_repository -a 'name=zls description=xxx baseurl=http://www.baidu.com gpgcheck=no enabled=yes'## 文件名跟仓库名不一样
[root@m01 ~]# ansible web_group -m yum_repository -a 'file=nginx name=zls description=xxx baseurl=http://www.baidu.com gpgcheck=no enabled=yes'## 删除yum仓库
[root@m01 ~]# ansible web_group -m yum_repository -a 'file=nginx name=zls state=absent'## 往同一个文件中添加不同的仓库
[root@m01 ~]# ansible web_group -m yum_repository -a 'file=zls name=zls2 description=ooo baseurl=http://www.google.com gpgcheck=no enabled=yes'#开起gpgcheck
[root@m01 ~]# ansible web_group -m yum_repository -a 'name=zls_epel description=EPEL file=test_zls baseurl=https://download.fedoraproject.org/pub/base/$releasever/$basearch/ gpgcheck=yes gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7' -i ./hosts## 掌握的方法:
name:指定仓库名字
state:present 创建absent 删除
file:指定文件名字
baseurl:指定镜像源
description:指定描述(repo文件中的name)
gpgcheck:秘钥检查yes:开启no:关闭
enabled:是否开启仓库yes:开启no:关闭

案例操作:

要求

通过61机器,给所有其他机器,添加nginx官方源。安装nginx

环境准备

主机名外网ip角色
m0110.0.0.61管理端
web0110.0.0.7被管理端
web0210.0.0.8被管理端

操作流程

1.安装ansible
# 1.修改epel源 
[root@m01 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo# 2.安装ansible
[root@m01 /]# yum install -y ansible
2.秘钥创建分发
# 1.在管理端生成密钥对
[root@m01 ~]# ssh-keygen# 2.将公钥发送到web01和web02
[root@m01 /]# ssh--id -i ~/.ssh/id_rsa.pub root@10.0.0.7
[root@m01 /]# ssh--id -i ~/.ssh/id_rsa.pub root@10.0.0.8
3.书写inventory(主机清单)
[root@m01 /]# vim /etc/ansible/hosts 
[web]
web01 ansible_ssh_host=10.0.0.7 ansible_ssh_port=22
web02 ansible_ssh_host=10.0.0.8 ansible_ssh_port=22# 查看web组内有哪些主机
[root@m01 /]# ansible web --list-hosthosts (2):web01web02
4.添加nginx官方yum源
# 指定模块yum_repository,指定nginx源到web主机文件名为nginx,指定仓库名为nginx,指定注释信息为666,baseurl源,开启gpgcheck,开启yum源# 1.在管理机中批量创建repo文件,file就算不指定.repo结尾,默认也会自动帮忙加上.repo结尾
[root@m01 /]# ansible web -m yum_repository -a 'file=nginx.repo name=nginx description=666 baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=yes gpgkey=https://nginx.org/keys/nginx_signing.key enabled=yes'
web01 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": true, "repo": "nginx", "state": "present"
}
web02 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": true, "repo": "nginx", "state": "present"
}# 2.查看web主机中是否成功推送
[root@web01 yum.repos.d]# ll
total 12
-rw-r--r--. 1 root root 1913 May 27 23:54 CentOS-Base.repo
-rw-r--r--. 1 root root  664 May 11  2018 epel.repo
-rw-r--r--  1 root root  161 Jun  9 01:04 nginx.repo.repo
[root@web01 yum.repos.d]# cat nginx.repo.repo 
[nginx]
baseurl = http://nginx.org/packages/centos/$releasever/$basearch/
enabled = 1
gpgcheck = 1
gpgkey = https://nginx.org/keys/nginx_signing.key
name = 666
[root@web02 yum.repos.d]# ll
total 12
-rw-r--r--. 1 root root 1913 May 27 23:54 CentOS-Base.repo
-rw-r--r--. 1 root root  664 May 11  2018 epel.repo
-rw-r--r--  1 root root  161 Jun  9 01:04 nginx.repo.repo
5.批量安装nginx
# 1.管理端批量对web安装nginx
[root@m01 ~]# ansible web -m yum -a 'name=nginx state=present'# 2.客户端检查是否安装
[root@m01 ~]# ansible web -m shell -a 'rpm -qa|grep nginx'
[WARNING]: Consider using the yum, dnf or zypper module rather than running 'rpm'.  If you need to use command because yum, dnf or zypper 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.
web01 | CHANGED | rc=0 >>
nginx-1.18.0-1.el7.ngx.x86_64
web02 | CHANGED | rc=0 >>
nginx-1.18.0-1.el7.ngx.x86_64

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.xdnf.cn/news/1541036.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

SpringCloud构建工程

一、新建数据库和表&#xff0c;并填写测试数据 二、创建父级工程 1、创建maven工程 2、工程名字OfficeAutomation 3、pom.xml文件中添加依赖 <properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.encodin…

【PHP源码】匿名来信系统H5版本V1.0免费开源源码(含搭建教程)

你的匿名来信H5一封你的来信源码/表白祝福短信程序/往来信/传话短信源码支持邮件发信与手机短信发信“你的匿名来信”是最近某音上爆火的一个活动话题&#xff0c;可以通过H5网站&#xff0c;编辑自己想要对某人说的话或者祝福&#xff0c;网站会把您想说的发给您预留的号码&am…

Java 数据结构 最小栈的实现

在O&#xff08;N&#xff09;时间复杂度内找出最小值&#xff1a; 创建两个栈当普通栈只有一个数据时&#xff0c;把该数据放入最小栈往普通栈放入数据时&#xff0c;把要放入的数据和最小栈的栈顶数据相比较&#xff0c;若要放入的数据比最小栈的栈顶数据小&#xff0c;则把…

单元测试和unittest框架(超详细总结)

&#x1f345; 点击文末小卡片 &#xff0c;免费获取软件测试全套资料&#xff0c;资料在手&#xff0c;薪资嘎嘎涨 单元测试的定义 1. 什么是单元测试&#xff1f; 单元测试是指&#xff0c;对软件中的最小可测试单元在与程序其他部分相隔离的情况下进行检查和验证的工作&am…

上手一个RGBD深度相机:从原理到实践--ROS noetic+Astra S(中):RGB相机的标定和使用

前言 本教程涉及基础相机的原理&#xff0c;使用&#xff0c;标定&#xff0c;和读取。(注&#xff1a;本教程默认大家有ROS1基础&#xff0c;故不对程序进行详细解释) 上一期&#xff1a;[csdn博客]上手一个RGBD深度相机&#xff1a;从原理到实践–ROS noeticAstra S&#xf…

Python 低层多线程接口_thread的用法

_thread是python标准库中的一个低层多线程API&#xff0c;可以在进程中启动线程来处理任务&#xff0c;并且提供了简单的锁机制来控制共享资源的同步访问。本文就_thread模块的用法和特性做个简单的演示。 文章目录 一、进程和线程的区别二、_thread模块的用法2.1 派生线程2.2…

ElasticsearchRestTemplate DSL日志打印

ElasticsearchRestTemplate DSL日志打印 痛点解决方案打印基础文档查询信息打印最终DML语句 痛点 在使用 ElasticsearchRestTemplate 进行数据操作时&#xff0c;经常遇到的一个问题是线上问题排查困难。具体来说&#xff0c;在线上环境中&#xff0c;当出现问题时&#xff0c…

vue项目中——如何用echarts实现动态水球图

有时候UI的脑洞真的很大&#xff0c;总是设计出一些稀奇古怪的图形&#xff0c;但又不得不佩服他们的审美&#xff0c;确实还挺好看的。今天给大家介绍echarts如何实现动态水球图。如图所示&#xff1a; 实现步骤 一、引入 在vue页面中引入echarts&#xff0c;如未安装需要先…

Java面试篇基础部分-Synchronized关键字详解

Synchronized关键字用于对Java对象、方法、代码块等提供线程安全操作。Synchronized属于独占式的悲观锁机制,同时也是可重入锁。我们在使用Synchronized关键字的时候,可以保证同一时刻只有一个线程对该对象进行访问;也就是说它在同一个JVM中是线程安全的。   Java中的每个…

Golang | Leetcode Golang题解之第420题强密码检验器

题目&#xff1a; 题解&#xff1a; func strongPasswordChecker(password string) int {hasLower, hasUpper, hasDigit : 0, 0, 0for _, ch : range password {if unicode.IsLower(ch) {hasLower 1} else if unicode.IsUpper(ch) {hasUpper 1} else if unicode.IsDigit(ch)…

TLC/TK Adv学习笔记1 - Py版本+美化

Python下重点 tkinter.ttk 模块自 Tk 8.5 开始引入&#xff0c;它提供了对 Tk 风格的部件集的访问。 它还带来了一些额外好处包括在 X11 下的反锯齿字体渲染和透明化窗口&#xff08;需要有 X11 上的混合窗口管理器&#xff09;。 tkinter.ttk 的基本设计思路&#xff0c;就是…

【Python】探索 Errbot:多功能聊天机器人框架

不是旅行治愈了你&#xff0c;是你在路上放过了自己。 在当今的数字化时代&#xff0c;聊天机器人已成为企业与客户互动、提升工作效率和增加乐趣的重要工具。Errbot是一个高度可扩展的聊天机器人框架&#xff0c;它允许开发者使用Python轻松创建和定制机器人。本文将介绍Errb…

乐观锁、悲观锁及死锁

乐观锁、悲观锁 1.概念 悲观锁(悲观锁定)&#xff1a;具有强烈的独占和排他特性。在整个执行过程中&#xff0c;将处于锁定状态。悲观锁在持有数据的时候总会把资源或者数据锁住&#xff0c;这样其他线程想要请求这个资源的时候就会阻塞&#xff0c;直到等到悲观锁把资源释放为…

如何基于Flink CDC与OceanBase构建实时数仓,实现简化链路,高效排查

本文作者&#xff1a;阿里云Flink SQL负责人&#xff0c;伍翀&#xff0c;Apache Flink PMC Member & Committer 众多数据领域的专业人士都很熟悉Apache Flink&#xff0c;它作为流式计算引擎&#xff0c;流批一体&#xff0c;其核心在于其强大的分布式流数据处理能力&…

DHCP协议原理(网络协议)

DHCP简介 定义 DHCP&#xff08;动态主机配置协议&#xff09;是一种网络管理协议&#xff0c;能够自动为局域网中的每台计算机分配IP地址及其他网络配置参数&#xff0c;包括子网掩码、默认网关和DNS服务器等。这一机制极大简化了网络管理&#xff0c;尤其在大型局域网中&am…

李沐 过拟合和欠拟合【动手学深度学习v2】

模型容量 模型容量的影响 估计模型容量 难以在不同的种类算法之间比较&#xff0c;例如树模型和神经网络 给定一个模型种类&#xff0c;将有两个主要因素&#xff1a; 参数的个数参数值的选择范围 VC维 线性分类器的VC维 VC维的用处 数据复杂度 多个重要因素&#xff1a; 样…

信息安全数学基础(20)中国剩余定理

前言 信息安全数学基础中的中国剩余定理&#xff08;Chinese Remainder Theorem&#xff0c;简称CRT&#xff09;&#xff0c;又称孙子定理&#xff0c;是数论中一个重要的定理&#xff0c;主要用于求解一次同余式组。 一、背景与起源 中国剩余定理最早见于我国南北朝时期的数学…

鸿蒙小技巧

1.子调用父的方法 子组件 父组件 2.使用emitter实现孙子传爷 孙子组件 import emitter from ohos.events.emitter;let event: emitter.InnerEvent {eventId: 1,priority: emitter.EventPriority.HIGH};let eventData: emitter.EventData {data: {"state": true,…

R语言APSIM模型进阶应用与参数优化、批量模拟实践技术

随着数字农业和智慧农业的发展&#xff0c;基于过程的农业生产系统模型在模拟作物对气候变化的响应与适应、农田管理优化、作物品种和株型筛选、农田固碳和温室气体排放等领域扮演着越来越重要的作用。APSIM (Agricultural Production Systems sIMulator)模型是世界知名的作物生…

帧率和丢帧分析实践

一、识别丢帧 1、使用AppAnalyzer检测性能问题 首先使用AppAnalyzer工具进行性能问题检测&#xff0c;AppAnalyzer是DevEco Studio中提供的检测评分工具&#xff0c;用于测试并评价HarmonyOS应用或元服务的质量&#xff0c;能快速提供评估结果和改进建议&#xff0c;当前支持的…