CHAPTER 5 Jenkins SonarQube

news2024/9/22 1:32:34

Jenkins & SonarQube

    • 5.1 安装SonarQube
      • 1. 下载镜像
      • 2. 导出到其他服务器
      • 3. 准备工作
      • 4. docker-compose文件
      • 5. 启动容器
    • 5.2 登录SonarQube
      • 1.登录
      • 2. 安装中文语言插件
      • 3. 安装其他插件
    • 5.3 部署扫描器sonar-scanner
      • 1. 部署sonar-scanner
      • 2. 新建项目
      • 3. 扫描代码
      • 4. 查看报告
    • 5.4 Jenkins集成SonarQube
      • 1. jenkins安装插件
      • 2. 配置SonarQube
      • 3. 配置jenkins
      • 4. 修改jenkins任务
      • 5. 运行任务
      • 6. 查看报告
    • 5.5 pipeline配置sonarqube
      • 1. 创建pipeline项目
      • 2. 配置jenkins
      • 3. 修改任务
      • 4. 运行
      • 5. 查看报告
    • 5.6 jenkins结语

SonarQube 代码质量测试
官方网站:http://www.sonarqube.org/SonarQube

SonarQube是一个用于代码质量管理的开放平台,通过插件机制,SonarQube可以集成不同的测试工具,代码分析工具,以及持续集成工具,例如Hudson/Jenkins等。
下载地址:https://www.sonarqube.org/downloads/

七个维度检测代码质量

  • 复杂度分布:代码复杂度过高将难以理解
  • 重复代码:程序中包含大量复制、粘贴的代码而导致代码臃肿,sonar可以展示源码中重复严重的地方
  • 单元测试统计:统计并展示单元测试覆盖率,开发或测试可以清楚测试代码的覆盖情况代码
  • 规则检查:检查代码是否符合规范
  • 注释率:若代码注释过少,特别是人员变动后,其他人接手比较难接手;若过多,又不利于阅读
  • 潜在的Bug:检测潜在的bug
  • 结构与设计:找出循环,展示包与包、类与类之间的依赖、检查程序之间耦合度

在这里插入图片描述

5.1 安装SonarQube

本次使用docker-compose安装

1. 下载镜像

由于SonarQube 7.9.XLTS版本不再使用MySQL,所以我们使用postgres数据库

[root@swarm-worker sonarqube]# docker pull postgres
[root@swarm-worker sonarqube]# docker pull sonarqube
[root@swarm-worker sonarqube]# docker images
REPOSITORY                               TAG       IMAGE ID       CREATED         SIZE
postgres                                 latest    ccd94e8b5fd9   27 hours ago    379MB
sonarqube                                latest    27d02b3b63c0   6 days ago      614MB

2. 导出到其他服务器

如果在本机安装,则可以省略此步骤
导出

[root@swarm-worker sonarqube]# docker save sonarqube:latest -o sonar
[root@swarm-worker sonarqube]# docker save postgres:latest -o postgres

拷贝

[root@dbc-server-554 ~]# scp root@192.168.70.183:/root/sonarqube/sonar .
root@192.168.70.183's password:
sonar                                                                                                   100%  591MB  61.9MB/s   00:09
[root@dbc-server-554 ~]# scp root@192.168.70.183:/root/sonarqube/postgres .
root@192.168.70.183's password:
postgres          

导入

[root@dbc-server-554 ~]# docker load -i sonar
c5ff2d88f679: Loading layer [==================================================>]  80.33MB/80.33MB
2b1193862943: Loading layer [==================================================>]  50.63MB/50.63MB
b21a8131f99a: Loading layer [==================================================>]  140.4MB/140.4MB
8937a408fb83: Loading layer [==================================================>]   2.56kB/2.56kB
f83c5c49a366: Loading layer [==================================================>]  348.2MB/348.2MB
0b3270b4db9d: Loading layer [==================================================>]  4.096kB/4.096kB
Loaded image: sonarqube:latest
[root@dbc-server-554 ~]# docker load -i postgres
4695cdfb426a: Loading layer [==================================================>]     84MB/84MB
b6ed5f2e01f9: Loading layer [==================================================>]  10.19MB/10.19MB
7cccddc6f072: Loading layer [==================================================>]    340kB/340kB
dac682fc7088: Loading layer [==================================================>]  4.259MB/4.259MB
b33ae74a6a4d: Loading layer [==================================================>]   25.7MB/25.7MB
273c5438a1fe: Loading layer [==================================================>]  3.554MB/3.554MB
ac1e4166d7d5: Loading layer [==================================================>]  2.048kB/2.048kB
b8d11d799bc0: Loading layer [==================================================>]  8.704kB/8.704kB
b4a792488c9f: Loading layer [==================================================>]  258.5MB/258.5MB
191f89fba0f7: Loading layer [==================================================>]  67.58kB/67.58kB
f54e2e550587: Loading layer [==================================================>]  2.048kB/2.048kB
1865a5f167a1: Loading layer [==================================================>]  3.584kB/3.584kB
69457d72c597: Loading layer [==================================================>]  15.87kB/15.87kB
Loaded image: postgres:latest
[root@dbc-server-554 ~]# docker images
REPOSITORY                                          TAG              IMAGE ID       CREATED         SIZE
postgres                                            latest           ccd94e8b5fd9   27 hours ago    379MB
sonarqube                                           latest           27d02b3b63c0   6 days ago      614MB

3. 准备工作

mkdir -p /data/sonar/postgres/postgresql
mkdir -p /data/sonar/postgres/data

mkdir -p /data/sonar/sonarqube
chmod 777 -R /data/sonar/sonarqube
echo "vm.max_map_count=262144" > /etc/sysctl.conf
sysctl -p

4. docker-compose文件

[root@dbc-server-554 sonar]# cat sonar-compose.yml
version: '3'
services:
  postgres:
    image: postgres:latest
    container_name: postgres
    restart: always
    privileged: true
    networks:
      - sonar
    volumes:
      - /data/sonar/postgres/postgresql:/var/lib/postgresql
      - /data/sonar/postgres/data:/var/lib/postgresql/data
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "5432:5432"
    environment:
      POSTGRES_USER: sonar
      POSTGRES_PASSWORD: sonar
      POSTGRES_DB: sonar
      TZ: Asia/Shanghai

  sonar:
    image: sonarqube:latest
    container_name: sonar
    restart: always
    privileged: true
    networks:
      - sonar
    volumes:
      - /data/sonar/sonarqube/logs:/opt/sonarqube/logs
      - /data/sonar/sonarqube/conf:/opt/sonarqube/conf
      - /data/sonar/sonarqube/data:/opt/sonarqube/data
      - /data/sonar/sonarqube/extensions:/opt/sonarqube/extensions
    ports:
      - "9090:9000"
    links:
      - "postgres:postgres"
    environment:
      ALLOW_EMPTY_PASSWORD: "yes"
      SONARQUBE_JDBC_USERNAME: sonar
      SONARQUBE_JDBC_PASSWORD: sonar
      SONARQUBE_JDBC_URL: "jdbc:postgresql://postgres:5432/sonar"

networks:
  sonar:
    driver: bridge

5. 启动容器

[root@dbc-server-554 sonar]# docker-compose -f sonar-compose.yml up -d
[+] Running 2/2
 ⠿ Container postgres  Started                                                                                               4.1s
 ⠿ Container sonar     Started                                                                                                       8.5s
[root@dbc-server-554 sonar]# docker ps
CONTAINER ID   IMAGE                      COMMAND                  CREATED          STATUS                  PORTS                                                                                    NAMES
58ca473cd0d6   sonarqube:latest           "/opt/sonarqube/dock…"   18 minutes ago   Up 12 minutes           0.0.0.0:9090->9000/tcp, :::9090->9000/tcp                                                sonar
09ced20ce5d8   postgres:latest            "docker-entrypoint.s…"   18 minutes ago   Up 12 minutes           0.0.0.0:5432->5432/tcp, :::5432->5432/tcp                                                postgres
89a093a64d8c   beginor/gitlab-ce:latest   "/assets/wrapper"        31 hours ago     Up 31 hours (healthy)   22/tcp, 0.0.0.0:8080->80/tcp, :::8080->80/tcp, 0.0.0.0:8443->443/tcp, :::8443->443/tcp   gitlab1

5.2 登录SonarQube

1.登录

访问http://服务器IP:9090
点击login登录,默认用户名密码都是admin
在这里插入图片描述

2. 安装中文语言插件

对于不喜欢英文界面的读者,可以选择安装中文插件

方法1:administration->Marketplace,在后面的搜索框搜索插件Chinese,然后点install安装:
方法2:插件目录/data/sonar/sonarqube/extensions/plugins/ 执行以下命令

[root@dbc-server-554 extensions]# mkdir plugins;cd plugins;
[root@dbc-server-554 plugins]# wget https://github.com/SonarQubeCommunity/sonar-l10n-zh/releases/download/sonar-l10n-zh-plugin-1.11/sonar-l10n-zh-plugin-1.11.jar
[root@dbc-server-554 plugins]# cd /root/docker/sonar
[root@dbc-server-554 sonar]# docker-compose -f sonar-compose.yml restart
[+] Running 2/2
 ⠿ Container postgres  Started                                                                                                       2.0s
 ⠿ Container sonar     Started             

在这里插入图片描述

3. 安装其他插件

Sonarquebe对代码的扫描都基于插件实现,因此要安装要扫描的开发语言插件:
Php
Java
Python
内存不足的截图:
在这里插入图片描述

5.3 部署扫描器sonar-scanner

下载扫描器:https://docs.sonarqube.org/latest/analyzing-source-code/scanners/sonarscanner/
官方文档:https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/

1. 部署sonar-scanner

unzip sonar-scanner-cli-4.7.0.2747-linux.zip
cd sonar-scanner-4.7.0.2747-linux/
vim conf/sonar-scanner.properties
[root@dbc-server-554 sonar-scanner-4.7.0.2747-linux]# cat conf/sonar-scanner.properties
#Configure here general information about the environment, such as SonarQube server connection details for example
#No information about specific project should appear here

#----- Default SonarQube server
sonar.host.url=http://localhost:9090

#----- Default source code encoding
sonar.sourceEncoding=UTF-8
ln -sv /root/docker/sonar/sonar-scanner-4.7.0.2747-linux /usr/local/sonar-scanner
export PATH=/usr/local/sonar-scanner/bin:$PATH
source .bashrc
[root@dbc-server-554 sonar-scanner-4.7.0.2747-linux]# sonar-scanner -h
INFO:
INFO: usage: sonar-scanner [options]
INFO:
INFO: Options:
INFO:  -D,--define <arg>     Define property
INFO:  -h,--help             Display help information
INFO:  -v,--version          Display version information
INFO:  -X,--debug            Produce execution debug output

当看到sonar-scanner的帮助信息,说明已经部署成功

2. 新建项目

在这里插入图片描述

在sonarqube管理界面,Projects->create project
在这里插入图片描述
Set Up -> Locally
在这里插入图片描述
Generate
在这里插入图片描述
复制命令
在这里插入图片描述

3. 扫描代码

[root@dbc-server-554 sonar-scanner-4.7.0.2747-linux]# mkdir src;cd src;

拷贝代码到src,并非必须src,此处只是配置一个存放代码的路径
把代码文件拷到src,然后执行拷贝的指令

[root@dbc-server-554 sonar-scanner-4.7.0.2747-linux]# sonar-scanner   -Dsonar.projectKey=python_test   -Dsonar.sources=.   -Dsonar.host.url=http://192.168.5.54:9090   -Dsonar.login=sqp_88b6fe0977f60b2989560d57aec12060e9988df7
INFO: Scanner configuration file: /root/docker/sonar/sonar-scanner-4.7.0.2747-linux/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.7.0.2747
INFO: Java 11.0.14.1 Eclipse Adoptium (64-bit)
INFO: Linux 3.10.0-1160.83.1.el7.x86_64 amd64
INFO: User cache: /root/.sonar/cache
INFO: Scanner configuration file: /root/docker/sonar/sonar-scanner-4.7.0.2747-linux/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: Analyzing on SonarQube server 9.9.0.65466
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Load global settings
INFO: Load global settings (done) | time=124ms
INFO: Server id: 147B411E-AYY6RuGWR--Ley_TBS9I
INFO: User cache: /root/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=33ms
INFO: Plugin [l10nzh] defines 'l10nen' as base plugin. This metadata can be removed from manifest of l10n plugins since version 5.2.
INFO: Load/download plugins (done) | time=704ms
INFO: Process project properties
INFO: Process project properties (done) | time=8ms
INFO: Execute project builders
INFO: Execute project builders (done) | time=2ms
INFO: Project key: python_test
INFO: Base dir: /root/docker/sonar/sonar-scanner-4.7.0.2747-linux
INFO: Working dir: /root/docker/sonar/sonar-scanner-4.7.0.2747-linux/.scannerwork
INFO: Load project settings for component key: 'python_test'
INFO: Load project settings for component key: 'python_test' (done) | time=267ms
WARN: SCM provider autodetection failed. Please use "sonar.scm.provider" to define SCM of your project, or disable the SCM Sensor in the project settings.
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=377ms
INFO: Load active rules
INFO: Load active rules (done) | time=1253ms
INFO: Load analysis cache
INFO: Load analysis cache | time=37ms
INFO: Load project repositories
INFO: Load project repositories (done) | time=25ms
INFO: Indexing files...
INFO: Project configuration:
WARN: File '/root/docker/sonar/sonar-scanner-4.7.0.2747-linux/jre/lib/server/libjvm.so' is bigger than 20MB and as consequence is removed from the analysis scope.
WARN: File '/root/docker/sonar/sonar-scanner-4.7.0.2747-linux/jre/lib/modules' is bigger than 20MB and as consequence is removed from the analysis scope.
INFO: 266 files indexed
INFO: Quality profile for py: Sonar way
INFO: ------------- Run sensors on module python_test
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=80ms
INFO: Sensor Python Sensor [python]
WARN: Your code is analyzed as compatible with python 2 and 3 by default. This will prevent the detection of issues specific to python 2 or python 3. You can get a more precise analysis by setting a python version in your configuration via the parameter "sonar.python.version"
INFO: Starting global symbols computation
INFO: 2 source files to be analyzed
INFO: 2/2 source files have been analyzed
INFO: Starting rules execution
INFO: 2 source files to be analyzed
INFO: 2/2 source files have been analyzed
INFO: The Python analyzer was able to leverage cached data from previous analyses for 0 out of 2 files. These files were not parsed.
INFO: Sensor Python Sensor [python] (done) | time=1788ms
INFO: Sensor Cobertura Sensor for Python coverage [python]
INFO: Sensor Cobertura Sensor for Python coverage [python] (done) | time=6ms
INFO: Sensor PythonXUnitSensor [python]
INFO: Sensor PythonXUnitSensor [python] (done) | time=4ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=1ms
INFO: Sensor CSS Rules [javascript]
INFO: No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
INFO: Sensor CSS Rules [javascript] (done) | time=1ms
INFO: Sensor C# Project Type Information [csharp]
INFO: Sensor C# Project Type Information [csharp] (done) | time=5ms
INFO: Sensor C# Analysis Log [csharp]
INFO: Sensor C# Analysis Log [csharp] (done) | time=315ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=0ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=17ms
INFO: Sensor TextAndSecretsSensor [text]
INFO: 226 source files to be analyzed
WARN: Invalid character encountered in file /root/docker/sonar/sonar-scanner-4.7.0.2747-linux/jre/lib/jspawnhelper at line 1 for encoding UTF-8. Please fix file content or configure the encoding to be used using property 'sonar.sourceEncoding'.
WARN: Invalid character encountered in file /root/docker/sonar/sonar-scanner-4.7.0.2747-linux/jre/bin/java at line 1 for encoding UTF-8. Please fix file content or configure the encoding to be used using property 'sonar.sourceEncoding'.
WARN: Invalid character encountered in file /root/docker/sonar/sonar-scanner-4.7.0.2747-linux/jre/lib/jexec at line 1 for encoding UTF-8. Please fix file content or configure the encoding to be used using property 'sonar.sourceEncoding'.
INFO: 226/226 source files have been analyzed
INFO: Sensor TextAndSecretsSensor [text] (done) | time=994ms
INFO: Sensor VB.NET Project Type Information [vbnet]
INFO: Sensor VB.NET Project Type Information [vbnet] (done) | time=19ms
INFO: Sensor VB.NET Analysis Log [vbnet]
INFO: Sensor VB.NET Analysis Log [vbnet] (done) | time=29ms
INFO: Sensor VB.NET Properties [vbnet]
INFO: Sensor VB.NET Properties [vbnet] (done) | time=0ms
INFO: Sensor IaC Docker Sensor [iac]
INFO: 0 source files to be analyzed
INFO: 0/0 source files have been analyzed
INFO: Sensor IaC Docker Sensor [iac] (done) | time=55ms
INFO: ------------- Run sensors on project
INFO: Sensor Analysis Warnings import [csharp]
INFO: Sensor Analysis Warnings import [csharp] (done) | time=1ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=30ms
INFO: SCM Publisher No SCM system was detected. You can use the 'sonar.scm.provider' property to explicitly specify it.
INFO: CPD Executor 1 file had no CPD blocks
INFO: CPD Executor Calculating CPD for 1 file
INFO: CPD Executor CPD calculation finished (done) | time=49ms
INFO: Analysis report generated in 373ms, dir size=196.8 kB
INFO: Analysis report compressed in 151ms, zip size=57.5 kB
INFO: Analysis report uploaded in 805ms
INFO: ANALYSIS SUCCESSFUL, you can find the results at: http://192.168.5.54:9090/dashboard?id=python_test
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://192.168.5.54:9090/api/ce/task?id=AYY-Th4HRjtTwsXO-RLp
INFO: Analysis total time: 12.573 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 15.156s
INFO: Final Memory: 26M/90M
INFO: ------------------------------------------------------------------------

提示SUCCESS,则执行成功

4. 查看报告

回到sonarqube的项目管理页面,查看报告
在这里插入图片描述

5.4 Jenkins集成SonarQube

1. jenkins安装插件

查找SonarQube Scanner并安装,安装完成后重启
在这里插入图片描述

2. 配置SonarQube

开启SonarQube权限验证
在这里插入图片描述
获取Sonar Qube的令牌
我的账号->安全,新建令牌或者复用创建好的令牌
在这里插入图片描述

3. 配置jenkins

添加sonarqube凭据
系统管理->凭据->系统->全局凭据
把上一节的令牌,复制在secret中,create凭据
在这里插入图片描述
配置SonarQube servers
系统管理->系统配置->SonarQube servers
配置Name,URL及使用前面配置的凭据
在这里插入图片描述
配置Sonar-scanner
在这里插入图片描述

4. 修改jenkins任务

在任务中新增构建步骤Excute SonarQube Scanner
在这里插入图片描述
配置如下信息:

sonar.projectname=${JOB_NAME}
sonar.projectKey=${JOB_NAME}
sources=./
sonar.java.binaries=target/

此处需要注意:如果jenkins任务名称和SonarQube项目名称不一致,则需要修改
sonar.projectKey=SonarQube项目名称
否则会报错,如ERROR: You're not authorized to run analysis. Please contact the project administrator.

5. 运行任务

在这里插入图片描述
看到任务已变成带有SonarQube标识的任务了
在这里插入图片描述

6. 查看报告

登录到sonarqube网页,查看报告
在这里插入图片描述

5.5 pipeline配置sonarqube

1. 创建pipeline项目

在sonarqube网页创建pipeline项目,和普通创建并没有什么不同,复制指令信息
在这里插入图片描述

2. 配置jenkins

创建凭据
这一点我也没太搞清楚,为什么相同的sonarqube,只因为项目不同,需要配置多次凭据去绑定项目
在这里插入图片描述
如下修改配置
在这里插入图片描述

3. 修改任务

通过流水线语法,生成sonarqube命令
在这里插入图片描述
把这部分和前面复制的指令整合到一起

node('Node-2-554'){
    stage("clone代码"){
        echo "代码clone"
        git credentialsId: '46d932dc-47f6-4dcd-b9f4-0d7848ab5ef8', url: 'http://192.168.5.54:8080/root/hello-world2.git'
        
    }
    stage("代码构建"){
        echo "代码构建"
        
    }
    stage("代码测试"){
        withSonarQubeEnv(credentialsId: '3423756c-d848-49f6-a068-8df64a1e62b1') {
        sh "/usr/local/sonar-scanner/bin/sonar-scanner \
        -Dsonar.projectKey=New-world-pipeline \
        -Dsonar.sources=. \
        -Dsonar.host.url=http://192.168.5.54:9090 \
        -Dsonar.login=sqp_58e96ab3279cf65bb0faaed354ced57f63199831"
}
        
    }
    stage("代码部署"){
        echo "代码部署"
        
    }
}

sh "/usr/local/sonar-scanner/bin/sonar-scanner \ 我这里写的绝对路径,也可以提前定义好环境变量,调度使用,例如

stage('代码质量分析'){
            steps {
                dir("code"){
                    script {
                        def scannerHome = tool name: 'sonarscanner'
                    }
                    withSonarQubeEnv(installationName: 'Sonar',credentialsId: 'sonar'){
                        sh "${scannerHome}/bin/sonar-scanner " +
                           "-Dsonar.branch.name=uat " +
                           "-Dsonar.projectKey=test_java " +
                           "-Dsonar.projectName=test_java " +
                           "-Dsonar.sourceEncoding=UTF-8 " +
                           "-Dsonar.language=java " +
                           "-Dsonar.projectVersion=1.0 " +
                           "-Dsonar.sources=. " +
                           "-Dsonar.java.binaries=."
                    }
                }
            }
        }

4. 运行

在这里插入图片描述

5. 查看报告

在这里插入图片描述

5.6 jenkins结语

关于jenkins,本专栏大体介绍了搭建,配置到结合svn,git等scm的使用,以及pipeline简单介绍及使用,到后来的SonarQube的配置使用。
整体介绍的内容可能进占jenkins功能的百分之一,还有些更强大的功能及插件,需要在以后的实践及生产环境中不断的学习夯实。

由于时间有限,像一些配置类的未能详细阐述,像MultiJob等很多使用功能都没有介绍,读者可以自行了解。笔者如果在后续工作中遇到有意思的设置或者功能,还会不断更新该专栏,敬请期待吧。

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

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

相关文章

Prometheus 的介绍和安装

介绍 Prometheus 是一个开源的监控和报警系统,最初由SoundCloud于2012年创建,随着越来越多的公司采用Prometheus以及非常活跃的社区,Prometheus于2016年加入云原生基金会,成为Kubernetes之后的第二个托管项目,并于2018年毕业。 特点 通过PromQL来对基于指标名称和键值对…

独立产品灵感周刊 DecoHack #047 - 安卓手机上最有用的APP

本周刊记录有趣好玩的独立产品设计开发相关内容&#xff0c;每周发布&#xff0c;往期内容同样精彩&#xff0c;感兴趣的伙伴可以点击订阅我的周刊。为保证每期都能收到&#xff0c;建议邮件订阅。欢迎通过 Twitter 私信推荐或投稿。&#x1f4bb; 产品推荐 1. Bouncer Tempor…

算法训练营 day45 动态规划 0-1背包理论 分割等和子集

算法训练营 day45 动态规划 0-1背包理论 分割等和子集 0-1背包理论 有n件物品和一个最多能背重量为w 的背包。第i件物品的重量是weight[i]&#xff0c;得到的价值是value[i] 。每件物品只能用一次&#xff0c;求解将哪些物品装入背包里物品价值总和最大。 在下面的讲解中&…

python 使用 thrift 教程

一、前言&#xff1a;   Thrift 是一种接口描述语言和二进制通信协议。以前也没接触过&#xff0c;最近有个项目需要建立自动化测试&#xff0c;这个项目之间的微服务都是通过 Thrift 进行通信的&#xff0c;然后写自动化脚本之前研究了一下。 需要定义一个xxx.thrift的文件&…

【C++】十分钟带你入门C++

目录零 内容概括一 C关键字二 命名空间2.1 命名空间定义2.2 命名空间的使用三 C输入和输出四 缺省参数4.1 缺省参数的概念4.2 缺省参数分类五 函数重载5.1 函数重载的概念六 引用6.1 引用概念6.2 引用特性6.3 常引用6.4 使用场景6.5 效率比较6.6 引用和指针的区别七 内联函数7.…

最简易的教程 -一篇文章教会你 用Python打包文件

前言 嗨嗨&#xff0c;好久不见&#xff0c;我是 我叫 … emmm你们好 我是一堆英文字母&#xff08;名字乱打的不好yi shi ~&#xff09; 看到文章的人多不多&#xff0c;我不知道 &#xff0c;招呼我还是要打一个的 &#x1f44d; 今天文章很简单&#xff0c;打包改图标 用…

C++关键字之const、inline、static

C 关键字总结 1.const const是 constant 的缩写&#xff0c;本意是不变的、不易改变的意思。在C中用来修饰内置类型变量&#xff0c;自定义对象&#xff0c;成员函数&#xff0c;返回值&#xff0c;函数参数使用如下&#xff1a; //修饰普通类型变量 const int a 7; int ba;…

人工智能对教育的冲击有多大?

人工智能对教育有巨大冲击 高考改革也会发生重大变化 教育系统其实是一个坚固的堡垒 再坚固也要适应未来 趣讲大白话&#xff1a;让我未来更有竞争力 *********** 创造和创新的意识和能力 复杂性和不确定性的适应能力 应该是改革的方向 【安志强趣讲信息科技】74期 掌握信息科…

【人工智能】对贝叶斯网络进行吉布斯采样

问题 现要求通过吉布斯采样方法&#xff0c;利用该网络进行概率推理&#xff08;计算 P(RT|SF, WT)、P2(CF|WT)的概率值&#xff09;。 原理 吉布斯采样的核心思想为一维一维地进行采样&#xff0c;采某一个维度的时候固定其他的维度&#xff0c;在本次实验中&#xff0c;假…

分享开放通达信l2接口的过程,开发之后怎么使用?

随着互联网的不断进步&#xff0c;信息技术的不断发展&#xff0c;通达信l2接口技术逐步成熟。那么&#xff0c;这些开放通达信l2接口开发的过程是怎么样的呢?期间又会遇到什么问题&#xff0c;开放之后又会怎么使用呢&#xff1f;这篇文章带你深入了解。 通达信l2接口不像一…

高通8155 GPS HAL层代码移植

1.添加gps hal层代码包 将ublox gps芯片的hal层代码拷贝至apps/LINUX/android/hardware/ublox/路径下&#xff0c;树状图如下&#xff1a; 2.修改编译选项 将新增的ublox gps hal层代码编译进入image&#xff0c;需要修改apps/LINUX/android/device/qcom/msmnile_gvmgh/路径下的…

基于Python来爬取某音动态壁纸,桌面更香了!

至于小伙伴们想要这个封图&#xff0c;我也没有。不过继续带来一波靓丽壁纸&#xff0c;而且是动态的&#xff0c;我的桌面壁纸又换了&#xff1a;每天换着花样欣赏一波波动态壁纸桌面立刻拥有了高颜值&#xff0c;简直跟刷美女短视频一样啊。对的&#xff0c;这些动态壁纸就是…

Linux信号一门搞定

1.信号是什么&#xff1f; 信号其实就是一个软件中断。 例&#xff1a; 输入命令&#xff0c;在Shell下启动一个前台进程。用户按下Ctrl-C&#xff0c;键盘输入产生一个硬件中断。如果CPU当前正在执行这个进程的代码&#xff0c;则该进程的用户空间代码暂停执行&#xff0c;…

Linux | Liunx安装Tomcat(Ubuntu版)

目录 一、下载并上传Tomcat压缩包到Ubuntu 1.1 下载并解压 1.2 执行 startup.sh 文件 二、验证Tomcat启动是否成功 2.1 查看启动日志 2.2 查看启动进程 三、Windows访问 Tomcat 服务 四、停止 Tomcat 服务 Tomcat是一款Web服务器&#xff0c;开发Web项目基本上都会用到…

应用篇|如何精准搜索一个答题考试小程序

应用篇|如何精准搜索一个答题考试小程序在线考试是一种非常节约成本的考试方式&#xff0c;考生通过微信扫码即可参加培训考试&#xff0c;不受时间、空间的限制&#xff0c;近几年越来越受企事业单位的青睐。比如有以下场景&#xff1a;为落实反电信网络诈骗普法宣传教育工作&…

【云原生-Docker】docker镜像制作、上传、dockerfile命令解析

场景 在实际业务场景中&#xff0c;需要制作多个不同版本进行镜像使用&#xff0c;如maven版本、JDK、openJDK不同使用等&#xff0c;所以需要做多个针对不同版本做不同的镜像。这里记录一下之前devops用的openJDK版本、某些部门需要用orcle JDK、特此需要做不同的镜像&#x…

C#学习笔记--泛型函数的==和Equals(看完你一定能学到!)

前言 工作的同事发现了这个问题&#xff0c;觉得实际游戏开发中会有这样的问题&#xff0c;所以在此记录 准备 开一个Unity项目&#xff0c;新建一个Test.cs脚本&#xff0c;并且生成一个Cube&#xff0c;直接把Test.cs挂在Cube上写一个Nulltest.cs脚本 using System.Colle…

【C++从入门到放弃】初识C++(基础知识入门详解)

&#x1f9d1;‍&#x1f4bb;作者&#xff1a; 情话0.0 &#x1f4dd;专栏&#xff1a;《C从入门到放弃》 &#x1f466;个人简介&#xff1a;一名双非编程菜鸟&#xff0c;在这里分享自己的编程学习笔记&#xff0c;欢迎大家的指正与点赞&#xff0c;谢谢&#xff01; C基础…

CentOS搭建博客typecho

Ubuntu搭建博客typecho_Dyansts的博客-CSDN博客 见过这样的文章展示页面吗&#xff1f; 详细视频安装教程&#xff1a; 9分钟快速搭建typecho博客&#xff0c;让你不再烦恼_哔哩哔哩_bilibili 现在就把他搭建出来 展示页面&#xff1a;Hello World 其他的插件&#xff1a;…

真的要用SaaS类产品做企业的移动办公平台吗?

面对越来越多的企业信息移动化解决方案&#xff0c;作为CIO该如何选择移动平台呢&#xff1f;先看看最常见的SaaS产品的情况。真的要用SaaS类产品做企业的移动门户吗&#xff1f;当前&#xff0c;热门SaaS类产品主要是企业微信和钉钉&#xff0c;适合小微初创企业。企业在不同成…