ansible roles常用用法

news2024/10/5 17:18:50

目录

一、说明

二、创建 ansible 环境

三、实验操作     

四、install_ansible.sh 脚本内容


一、说明

        该文档是日常经常使用的模板,通过该例子让更多的初学者了解ansible 剧本的写法,很多情况,可以按照该模版来套用即可。

        读者不需要下载或者复制全部内容,直接下载或者复制 install_ansible.sh 脚本文件即可,该脚本文件会自动安装ansible ,以及创建 ansible roles 结构和测试文件。

        roles用例,自动生成用安装redis、nginx以及httpd为例子的 roles 文件。以及使用了以下的常用功能:

  1.  通过 role 角色来执行不同的类型的剧本
  2. 剧本引用了自定义变量以及内置的 setup模块变量
  3. 剧本使用注册变量,输出部分debug返回值
  4. 使用COPY和template模块,更好比较两者区别
  5. 剧本 task 文件导入其他task文件的方法
  6. 剧本使用 触发器效果的功能 notify 和 handler
  7. 主机清单变量和剧本变量两种写法的区别
  8. template模块 Jinja2 常用语句写法,条件控制等
  9. 剧本里面使用循环的用法

        ansible日常开发和使用,还会用到 when 判断等指令,可能还是根据不同的 task 使用不同的tags 标签,方便后续根据 tags 执行指定部分的内容 ,读者还可以 自行 比较 vars 和 vars_files的区别、以及多种include 的区别:如:include 、include_tasks 、include_roles等;要巧用模块帮助命令:ansible-doc

注意:执行 install_ansible.sh 脚本后,一定要记得修改当前目录生成的 hosts 文件内容:将ansible主机清单以及账号信息等内容修改成你自己的信息

二、创建 ansible 环境

        1.下载或者复制 install_ansible.sh 脚本 到你的测试环境,并执行改脚本:

# 执行 install_ansible.sh 脚本;
# 确保你的服务器要能正常访问公网

chmod a+x install_ansible.sh 
sh install_ansible.sh

         2. 执行完成 install_ansible.sh 后,你不但已完成安装 ansible,还完成了 测试环境构建;执行脚本后生成的环境结构如下:

         3. 执行完成 install_ansible.sh 脚本后,根据提示即可完成测试

三、实验操作     

  1、执行 测试命令

ansible-playbook -i hosts test.yaml -C
[root@192 test]# ansible-playbook -i hosts test.yaml -C

PLAY [first palybook] *******************************************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************
ok: [192.168.51.140]

TASK [test : install apps] **************************************************************************************************************************************************
[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: ['nginx', 'redis', 'httpd']` 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.
changed: [192.168.51.140] => (item=[u'nginx', u'redis', u'httpd'])

TASK [test : copy nginx.conf] ***********************************************************************************************************************************************
changed: [192.168.51.140]

TASK [test : template for redis.conf] ***************************************************************************************************************************************
changed: [192.168.51.140]

TASK [test : template for httpd.con] ****************************************************************************************************************************************
changed: [192.168.51.140]

TASK [test : start apps] ****************************************************************************************************************************************************
changed: [192.168.51.140] => (item=nginx)
changed: [192.168.51.140] => (item=redis)
changed: [192.168.51.140] => (item=httpd)

TASK [test : 引用定义在主机清单的变量] **************************************************************************************************************************************************
ok: [192.168.51.140] => {
    "msg": "mytesthost.com"
}

TASK [test : 引用定义在vars目录文件的变量] **********************************************************************************************************************************************
ok: [192.168.51.140] => {
    "msg": "myhost1.com.cn"
}

TASK [test_ext 引用其他的tasks文件] ************************************************************************************************************************************************
included: /root/test/roles/test/tasks/mytest.yaml for 192.168.51.140

TASK [test : ping server for ext tasks] *************************************************************************************************************************************
ok: [192.168.51.140]

TASK [test : ping stdout ext task] ******************************************************************************************************************************************
ok: [192.168.51.140] => {
    "out": {
        "changed": false, 
        "failed": false, 
        "ping": "pong"
    }
}

RUNNING HANDLER [test : restart nginx] **************************************************************************************************************************************
changed: [192.168.51.140]

RUNNING HANDLER [test : restart redis] **************************************************************************************************************************************
changed: [192.168.51.140]

RUNNING HANDLER [test : restart httpd] **************************************************************************************************************************************
changed: [192.168.51.140]

PLAY RECAP ******************************************************************************************************************************************************************
192.168.51.140             : ok=14   changed=8    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

[root@192 test]# 

    2. 执行 剧本

ansible-playbook -i hosts test.yaml
[root@192 test]# 
[root@192 test]# ansible-playbook -i hosts test.yaml 

PLAY [first palybook] *******************************************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************
ok: [192.168.51.140]

TASK [test : install apps] **************************************************************************************************************************************************
[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: ['nginx', 'redis', 'httpd']` 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.
changed: [192.168.51.140] => (item=[u'nginx', u'redis', u'httpd'])

TASK [test : copy nginx.conf] ***********************************************************************************************************************************************
changed: [192.168.51.140]

TASK [test : template for redis.conf] ***************************************************************************************************************************************
changed: [192.168.51.140]

TASK [test : template for httpd.con] ****************************************************************************************************************************************
changed: [192.168.51.140]

TASK [test : start apps] ****************************************************************************************************************************************************
changed: [192.168.51.140] => (item=nginx)
changed: [192.168.51.140] => (item=redis)
changed: [192.168.51.140] => (item=httpd)

TASK [test : 引用定义在主机清单的变量] **************************************************************************************************************************************************
ok: [192.168.51.140] => {
    "msg": "mytesthost.com"
}

TASK [test : 引用定义在vars目录文件的变量] **********************************************************************************************************************************************
ok: [192.168.51.140] => {
    "msg": "myhost1.com.cn"
}

TASK [test_ext 引用其他的tasks文件] ************************************************************************************************************************************************
included: /root/test/roles/test/tasks/mytest.yaml for 192.168.51.140

TASK [test : ping server for ext tasks] *************************************************************************************************************************************
ok: [192.168.51.140]

TASK [test : ping stdout ext task] ******************************************************************************************************************************************
ok: [192.168.51.140] => {
    "out": {
        "changed": false, 
        "failed": false, 
        "ping": "pong"
    }
}

RUNNING HANDLER [test : restart nginx] **************************************************************************************************************************************
changed: [192.168.51.140]

RUNNING HANDLER [test : restart redis] **************************************************************************************************************************************
changed: [192.168.51.140]

RUNNING HANDLER [test : restart httpd] **************************************************************************************************************************************
changed: [192.168.51.140]

PLAY RECAP ******************************************************************************************************************************************************************
192.168.51.140             : ok=14   changed=8    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

[root@192 test]#

  3. 查看剧本安装结果

  4. 修改redis端口测试 handler 触发器效果,redis端口变量是 redis_port

ansible-playbook -i hosts test.yaml -e redis_port=6380
[root@192 test]# 
[root@192 test]# ansible-playbook -i hosts test.yaml -e redis_port=6380

PLAY [first palybook] *******************************************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************
ok: [192.168.51.140]

TASK [test : install apps] **************************************************************************************************************************************************
[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: ['nginx', 'redis', 'httpd']` 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.
ok: [192.168.51.140] => (item=[u'nginx', u'redis', u'httpd'])

TASK [test : copy nginx.conf] ***********************************************************************************************************************************************
ok: [192.168.51.140]

TASK [test : template for redis.conf] ***************************************************************************************************************************************
changed: [192.168.51.140]

TASK [test : template for httpd.con] ****************************************************************************************************************************************
ok: [192.168.51.140]

TASK [test : start apps] ****************************************************************************************************************************************************
ok: [192.168.51.140] => (item=nginx)
ok: [192.168.51.140] => (item=redis)
ok: [192.168.51.140] => (item=httpd)

TASK [test : 引用定义在主机清单的变量] **************************************************************************************************************************************************
ok: [192.168.51.140] => {
    "msg": "mytesthost.com"
}

TASK [test : 引用定义在vars目录文件的变量] **********************************************************************************************************************************************
ok: [192.168.51.140] => {
    "msg": "myhost1.com.cn"
}

TASK [test_ext 引用其他的tasks文件] ************************************************************************************************************************************************
included: /root/test/roles/test/tasks/mytest.yaml for 192.168.51.140

TASK [test : ping server for ext tasks] *************************************************************************************************************************************
ok: [192.168.51.140]

TASK [test : ping stdout ext task] ******************************************************************************************************************************************
ok: [192.168.51.140] => {
    "out": {
        "changed": false, 
        "failed": false, 
        "ping": "pong"
    }
}

RUNNING HANDLER [test : restart redis] **************************************************************************************************************************************
changed: [192.168.51.140]

PLAY RECAP ******************************************************************************************************************************************************************
192.168.51.140             : ok=12   changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

[root@192 test]#

  5. 修改redis端口后的结果

四、install_ansible.sh 脚本内容

# 一键 安装 ansible; 一键构建 ansible 测试剧本环境

# cat install_ansible.sh

#!/bin/bash
# 一键安装 ansible
# creator: @tudou
# date 2023-05-14
# Centos 7

####################################################################################################
#
# 使用说明: 直接复制或者下载 install_ansible.sh 脚本即可,其他目录和内容会自动形成,无需额外理会
#
####################################################################################################

# 关闭 selinux 要不然更改 应用默认端口后,可能会启动失败,影响测试
setenforce 0
sed -i '/^SELINUX/c SELINUX=disabled' /etc/selinux/config

# 1、安装 ansible
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
wget -O /etc/yum.repos.d/epel.repo http://mirrors.cloud.tencent.com/repo/epel-7.repo
yum clean all
yum makecache

yum install -y ansible tree
 
echo "=============================================================================================="
echo "已成功安装 ansible"
echo ""
echo "=============================================================================================="
echo "开始构建 ansible 测试剧本环境..."
echo "=============================================================================================="

# 2、此项为环境说明项,执行 install_ansible.sh 脚本,会自动生成相关的 roles 目录和文件;
# 使用说明: 直接复制或者 install_ansible.sh 脚本即可,其他目录和内容会自动形成,无需额外理会
# ansible 测试剧本目录结构为:
# [root@192 test]# tree 
# .
# ├── hosts
# ├── install_ansible.sh
# ├── roles
# │   └── test
# │       ├── defaults
# │       ├── files
# │       │   └── nginx.conf
# │       ├── handlers
# │       │   └── main.yaml
# │       ├── meta
# │       ├── tasks
# │       │   ├── main.yaml
# │       │   └── mytest.yaml
# │       ├── templates
# │       │   ├── httpd.conf.j2
# │       │   └── redis.conf.j2
# │       └── vars
# │           └── main.yaml
# └── test.yaml
# 
# 9 directories, 10 files
# ansible 测试剧本目录结构为

# 3、创建 hosts 清单文件,你也可以直接修改ansible默认的 hosts 文件: /etc/ansible/hosts
cat > hosts << EOF
[test01]
# 相关主机账号密码请修改为你自己的真实信息,多个主机写多行
192.168.51.140 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass="root"

[test01:vars]
# 主机清单组公共变量写法
myhost=mytesthost.com

[test02]
# 调用多个组的写法
[mytest:children]
test01
test02

EOF

# 4、创建剧本入口文件
cat > test.yaml << EOF
---
- hosts: test01
  name: first palybook
  gather_facts: true
  roles:
  - { role: test }

#- hosts: test02
#  name: secend palybook
#  roles:
#  - { role: test02 }
#  - { role: ext/test03 }

EOF

# 5、创建 roles 相关目录,空的目录,可有可无,但为了指导初学者,我列出了平常使用的目录
mkdir -p roles/test/{defaults,files,handlers,meta,tasks,templates,vars}

# defaults 目录默认变量等信息; meta 可以写依赖相关的信息

# 6、创建 task 文件; 我这里以 main.yaml 和 mytest.yaml 为例

# 6-1、在 tasks 目录,创建 task 文件: main.yaml
cat > roles/test/tasks/main.yaml << EOF
---
  - name: install apps
    yum: name={{ item }} state=present
    with_items:
     - nginx
     - redis
     - httpd

  - name: copy nginx.conf
    copy: src=files/nginx.conf dest=/etc/nginx/nginx.conf
    notify: restart nginx
  
  - name: template for redis.conf
    template: src=templates/redis.conf.j2 dest=/etc/redis.conf
    notify: restart redis

  - name: template for httpd.con
    template: src=templates/httpd.conf.j2 dest=/etc/httpd/conf/httpd.conf
    notify: restart httpd

  - name: start apps
    service: name={{ item }}  state=started
    with_items:
     - nginx
     - redis
     - httpd

  # 应用自定义变量
  - name: "引用定义在主机清单的变量"
    debug: msg={{ myhost }}
  - name: "引用定义在vars目录文件的变量"
    debug: msg={{ myhost1 }}

  # 其他的tasks
  - name: test_ext 引用其他的tasks文件
    #include: mytest.yaml
    include_tasks: mytest.yaml
    #import_tasks: mytest.yaml

EOF


# 6-2、在 tasks 目录,创建 task 文件: mytest.yaml ; mytest.yaml 的作用是用来举例说明 task 文件引用更多的task的方法
cat > roles/test/tasks/mytest.yaml << EOF
---
- name: ping server for ext tasks
  ping:
  register: out
- name: ping stdout ext task
  debug: var=out

- name: cat hosts info for ext tasks
  shell: cat /etc/hosts
  register: out
- name: "hosts info ext task"
  debug: var=out.stdout_lines

EOF

# 7、在 handler 目录,创建处理文件: main.yaml; handler目录下的文件需要 notify 触发器触发才会执行
cat > roles/test/handlers/main.yaml << EOF
---
- name: restart nginx
  systemd: name=nginx state=restarted

- name: restart redis
  systemd: name=redis state=restarted

- name: restart httpd
  systemd: name=httpd state=restarted

EOF

# 8、在 vars 目录,创建自定义的变量文件: main.yaml
cat > roles/test/vars/main.yaml << EOF
myhost1: myhost1.com.cn
httpd_host: httpd.com.cn
redis_port: 6379
# redis_port: 6380

EOF

# 9、在files 目录,创建 nginx.conf配置文件
cat > roles/test/files/nginx.conf << EOF
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '\$remote_addr - \$remote_user [\$time_local] "\$request" '
                      '\$status \$body_bytes_sent "\$http_referer" '
                      '"\$http_user_agent" "\$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;

    server {
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }
}

EOF

# 10、在 templastes 目录,创建模版文件
# 10-1、在 templastes 目录,创建模版文件:redis.conf.j2
cat > roles/test/templates/redis.conf.j2 << EOF
# 绑定主机IP,多网卡多IP可能会失败
bind {{ ansible_default_ipv4.address }}

#port 6379

{% if redis_port is  defined %}
port {{ redis_port }}
{% endif %}

daemonize no

EOF

# 10-2、在 templastes 目录,创建模版文件:httpd.conf.j2
cat > roles/test/templates/httpd.conf.j2 << EOF
ServerRoot "/etc/httpd"
Listen 8080
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost
#ServerName www.example.com:80

#####################################################
# 添加用于 ansible template 部分
{% if httpd_host is defined %}
ServerName {{ httpd_host }}
{% endif %}
# 添加用于 ansible template 部分
#####################################################

<Directory />
    AllowOverride none
    Require all denied
</Directory>
DocumentRoot "/var/www/html"
<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>
<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>
<Files ".ht*">
    Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    <IfModule logio_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>
    CustomLog "logs/access_log" combined
</IfModule>
<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>
<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>
<IfModule mime_module>
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset UTF-8
<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
IncludeOptional conf.d/*.conf

EOF


# 11、成功构建 ansible 测试剧本环境

echo "已成功构建 ansible 测试剧本环境..."
echo "=============================================================================================="
echo "请在当前目录执行以下命令测试: "
echo ""
echo "测试命令: ansible-playbook -i hosts test.yaml -C"
echo ""
echo "执行命令: ansible-playbook -i hosts test.yaml"
echo ""
echo "=============================================================================================="

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

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

相关文章

GPT前2代版本简介

承接上文ChatGPT进化的过程简介 2018年&#xff0c;Google的Bert和OpenAI的GPT绝代双骄&#xff0c;两者非常像&#xff0c;都是语言模型&#xff0c;都基本上是无监督的方式去训练的&#xff0c;你给我一个文本&#xff0c;我给你一个语言模型出来。 GPT前两代没有什么特别的…

好看的皮囊千篇一律,有趣的书籍万里挑一,学习Java必读的两款书籍推荐

今天给各位学习Java的小伙伴儿们推荐两本Java路线上必不可少的书籍&#xff0c;核心卷1和卷2&#xff0c;大家可根据自己的情况种草。正所谓&#xff0c;书多不压身。 Java核心技术卷1 Java 诞生 27 年来&#xff0c;这本享誉全球的 Java 经典著作《Core Java》一路伴随着 J…

2023年了,快去给你的博客加上一个主题吧~

最近闲逛github&#xff0c;发现了一个不错的博客主题&#xff0c;分享给大家。 这个主题主要是用于博客园的个人主页美化用的。 主题地址&#xff1a;Silence - 专注于阅读的博客园主题 目录 一、获取文件 &#xff08;1&#xff09;样式文件 &#xff08;2&#xff09;脚本…

【机器学习】第二节:线性回归和线性分类

作者&#x1f575;️‍♂️&#xff1a;让机器理解语言か 专栏&#x1f387;&#xff1a;机器学习sklearn 描述&#x1f3a8;&#xff1a;本专栏主要分享博主学习机器学习的笔记和一些心得体会。 寄语&#x1f493;&#xff1a;&#x1f43e;没有白走的路&#xff0c;每一步都算…

Linux文件描述符和重定向

介绍 文件描述符是与文件输入、输出相关联的整数&#xff0c;在编写脚本时会经常使用标准的文件描述符来将内容重定向输出&#xff0c;0、1、2是文件描述符&#xff08;分别对应stdin、stdout、stderr&#xff09;&#xff0c;< 、>, >>叫做操作符。 概念 stdin(…

《走进对象村7》之内部类基地

文章目录 &#x1f490;专栏导读&#x1f490;文章导读&#x1f341;内部类匿名内部类匿名内部类的定义匿名内部类访问内部类的特点 &#x1f341;实例内部类实例内部类的定义实例内部类的如何实例化对象实例内部类访问情况 &#x1f341;静态内部类&#x1f341;局部内部类内部…

谈谈中台建设

大家好&#xff0c;我是易安&#xff01; 中台是数字化转型中备受关注的话题。今天&#xff0c;我们将重点探讨业务中台和数据中台。同时&#xff0c;作为企业数字化中台转型的整体&#xff0c;我们也会探讨前台和后台的设计思路。 平台与中台 中台这一概念源于阿里巴巴&#…

命题逻辑与推理

推理理论(假设前提条件为真推出的结论) 真值表法 直接证明法 常用推理规则—倒着看&#xff0c;推理整理过程 P规则(前提引入) T规则(结论引入) ** 常用推理公式 ** 名称内容附加率 A ⇒ ( A ∨ B ) A ⇒ A → B B ⇒ A → B A\Rightarrow(A\lor B)\qquad\\\neg A\Rightarro…

软件工程开发文档写作教程(10)—需求分析书的适用范围

本文原创作者&#xff1a;谷哥的小弟作者博客地址&#xff1a;http://blog.csdn.net/lfdfhl本文参考资料&#xff1a;电子工业出版社《软件文档写作教程》 马平&#xff0c;黄冬梅编著 需求分析书的适用范围 软件项目一旦被确定要实施之后&#xff0c;撇开项目的立项投标不谈&a…

Java每日一练(20230515) 阶乘后的零、矩阵置零、两数相除

目录 1. 阶乘后的零 &#x1f31f; 2. 矩阵置零 &#x1f31f;&#x1f31f; 3. 两数相除 &#x1f31f;&#x1f31f; &#x1f31f; 每日一练刷题专栏 &#x1f31f; Golang每日一练 专栏 Python每日一练 专栏 C/C每日一练 专栏 Java每日一练 专栏 1. 阶乘后的零 …

基于PyQt5的图形化界面开发——PyQt示例_计算器

基于PyQt5的图形化界面开发——PyQt示例_计算器 前言1. caculator.py2. MainWindow.py3. 运行你的项目4. 其他 PyQt 文章 前言 本节学习 PyQt5示例 &#xff0c;制作一个图形化界面 计算器 操作系统&#xff1a;Windows10 专业版 开发环境&#xff1a;Pycahrm Comunity 2022…

2023 年 Pycharm 常用插件推荐

1. Key Promoter X 如果让我给新手推荐一个 PyCharm 必装插件&#xff0c;那一定是 Key Promoter X 。 它就相当于一个快捷键管理大师&#xff0c;它时刻地在&#xff1a; 教导你&#xff0c;当下你的这个操作&#xff0c;应该使用哪个快捷操作来提高效率&#xff1f;提醒你…

Nginx之正向代理与反向代理进阶(支持https)

在【Nginx之正向代理与反向代理】一文中我们实现了将Nginx服务器作为正向代理服务器和反向代理服务器&#xff0c;但美中不足的是仅支持http协议&#xff0c;不支持https协议。 我们先看看看http和https的区别&#xff1a; http协议&#xff1a;协议以明文方式发送数据&#…

django ORM框架(操作数据库)【正在更新中...】

一、ORM框架介绍 ORM框架&#xff0c;把类和数据进行映射&#xff0c;通过类和对象操作它对应表格中的数据&#xff0c;进行增删改查&#xff08;CRUD) ORM框架中 数据库&#xff1a;需要提前手动创建数据库 数据表&#xff1a;与OMR框架中的模型类对应 字段&#xff1a;模…

C++基础STL-deque容器

双端数组&#xff0c;可以对头端进行插入删除操作 deque 容器和 vecotr 容器有很多相似之处&#xff0c;比如&#xff1a; deque 容器也擅长在序列尾部添加或删除元素&#xff08;时间复杂度为O(1)&#xff09;&#xff0c;而不擅长在序列中间添加或删除元素。deque 容器也可…

图解LeetCode——240. 搜索二维矩阵 II

一、题目 编写一个高效的算法来搜索 m x n 矩阵 matrix 中的一个目标值 target 。该矩阵具有以下特性&#xff1a; 每行的元素从左到右升序排列。 每列的元素从上到下升序排列。 二、示例 2.1> 示例 1&#xff1a; 【输入】matrix [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,1…

软件工程开发文档写作教程(08)—需求分析书的编制目标

本文原创作者&#xff1a;谷哥的小弟作者博客地址&#xff1a;http://blog.csdn.net/lfdfhl本文参考资料&#xff1a;电子工业出版社《软件文档写作教程》 马平&#xff0c;黄冬梅编著 需求分析定义 需求分析的基本任务是要准确地定义新系统的目标&#xff0c;为了满足用户需求…

seleniumplaywright获取网站Authorization鉴权实现伪装requests请求

文章目录 selenium&playwright获取网站Authorization鉴权实现伪装requests请求需求背景知识点&#xff1a;selenium获取已登录网站的用户鉴权信息知识点&#xff1a;playwright获取cookie知识点&#xff1a;playwright获取storage_state提取cookie秃发状况windows禁止chrom…

OpenCV实现提取水平线和垂直线,提取验证码

1.提取水平线和垂直线 在之前的博客中&#xff0c;我们介绍了很多形态学操作。其中&#xff0c;膨胀与腐蚀操作可以使用任意的结构元素&#xff0c;例如矩形、圆、直线等各种自定义形状。 提取水平线和垂直线的具体步骤见下&#xff1a; 1.1.步骤一&#xff1a;读入原始图像…

提速YOLOv7:用MobileNetV3更换骨干网络加速目标检测

目录 前言一、MobileNetV3的介绍1、MobileNetV3的原理和特点2、MobileNetV3的结构 二、YOLOv7的介绍1、YOLOv7的结构和流程2、YOLOv7的性能指标 三、MobileNetV3替换YOLOv7的骨干网络1、替换骨干网络2、修改neck部分3、微调模型 四、实验结果与分析1、数据集和实验设置2、实验结…