首页
视频
资源
登录
原
SonarQube代码审查(1) - 安装SonarQube
4490
人阅读
2021/6/6 17:37
总访问:
2536753
评论:
0
收藏:
0
手机
分类:
云产品
![](https://img.tnblog.net/arcimg/hb/534b7ffcf52345759dd857b7f114741d.png) >#SonarQube代码审查(1) - 安装SonarQube [TOC] SonarQube简介 ------------ tn> SonarQube 是一种自动代码审查工具,用于检测代码中的错误、漏洞和代码异味。它可以与您现有的工作流程集成,以支持跨项目分支和拉取请求的持续代码检查。 安装SonarQube ------------ ### 安装mysql并创建SonarQube数据库(仅仅支持SonarQube 7.9的以下的) tn>安装mysql请参考:https://www.tnblog.net/hb/article/details/4888 然后在mysql中创建sonar数据库 ```bash create database sonar; show databases; ``` ![](https://img.tnblog.net/arcimg/hb/bfd53fc46baa443c84b79394ebece9c6.png) ### 安装postgres ```bash docker pull postgres:11.4 docker run --name postgres1 -e POSTGRES_PASSWORD=pwd123456 -e POSTGRES_USER=root -e POSTGRES_DB=sonardb -p 5432:5432 -d postgres:11.4 docker exec -it postgres1 /bin/bash psql template1 # 创建数据库 create database sonarqubedb; # 创建用户 create user sonarqube with encrypted password 'pwd123456'; # 把所有权限都给它 grant all privileges on database sonarqubedb to sonarqube # 退出 \q exit ``` ### 官网下载 >通过访问官网到下载地址下载相对应的包:https://www.sonarqube.org/success-download-community-edition/ ```bash wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-8.9.0.43852.zip yum install unzip # 安装解压程序 unzip sonarqube-8.9.0.43852.zip # 解压包 mkdir /opt/sonar mv sonarqube-8.9.0.43852/* /opt/sonar #移动文件 useradd sonar # 创建 sonar 用户 chown -R sonar /opt/sonar # 更改目录以及权限 ``` ### 修改sonar配置文件 ```bash # 修改配置文件 vi /opt/sonar/conf/sonar.properties ``` ```bash # 添加数据库密码与账户 sonar.jdbc.username=root sonar.jdbc.password=pwd123456 # mysql sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false # postgres sonar.jdbc.username=sonarqube sonar.jdbc.password=pwd123456 sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonardb ``` >使用`sonar`账号启动 ```bash cd /opt su sonar /opt/sonar/bin/linux-x86-64/sonar.sh start tail -f sonar/logs/sonar.20210606.log # 查看日志 ``` ![](https://img.tnblog.net/arcimg/hb/0897f9a2f120444287921e378ba7bfd0.png) >接着我们来启动日志追踪,发现报错了 ![](https://img.tnblog.net/arcimg/hb/cde25eba524849f18757b3e50563c3a1.png) tn>原来是SonarQube 7.9以上版本已不再支持mysql ![](https://img.tnblog.net/arcimg/hb/b84a946a087d4d3c9507da12e1b79be6.png) tn>解决数据库后,它很妖艳又要Java11才能支持 ### 解决问题(安装java11) ```bash yum search java-11 yum install java-11-openjdk -y # 然后我们通过下面的命令选择java-11 JDK(我们选择2) alternatives --config java java -version ``` ![](https://img.tnblog.net/arcimg/hb/36e760e5886c4f58be2677ae75a81707.png) >然后再次运行,elasticsearch报错 ![](https://img.tnblog.net/arcimg/hb/e065442988914a8c9f0f195fcb027502.png) ```bash # 解决第一个问题 vi /etc/security/limits.conf # 添加下面内容 * soft nofile 65536 * hard nofile 65536 ``` ```bash # 解决第二个问题 vi /etc/sysctl.conf # 最后添加一行 vm.max_map_count=262144 # 保存后执行,立马生效然后再次尝试启动SonarQube /sbin/sysctl -p ``` ![](https://img.tnblog.net/arcimg/hb/c492158fd8c0496f88adc7d9a6190413.png) >貌似成功了,访问一下`9000`端口看看(默认端口是9000,可以在刚刚的配置文件里面设置其他端口) ```bash # 关闭防火墙 systemctl stop firewalld # 查看内网ip ifconfig ``` tn>由于坑可能比较多大家尽量通过 `/opt/sonar/logs` 日志去查,排查顺序`sonar.log`-->`es.log`-->`web.log`,如有问题可以直接在群里或qq上@我。 ```bash # 重启SonarQube rm -rf sonar/data/es7/ # 查看网站端口 netstat -tlunp # 杀掉elasticsearch的pid kill {pid} # 停掉sonarQube su sonar /opt/sonar/bin/linux-x86-64/sonar.sh stop /opt/sonar/bin/linux-x86-64/sonar.sh stop # 在ps中找到sonar并杀掉 ps -ef | grep sonar kill {pid} # 启动 su sonar /opt/sonar/bin/linux-x86-64/sonar.sh start ``` >最后通过`127.0.0.1:9000`访问到该页面,默认账号和密码为`admin:admin` ![](https://img.tnblog.net/arcimg/hb/8e03782033e04a949444f081899a6160.png) >更改了密码之后就进来了 ![](https://img.tnblog.net/arcimg/hb/b9b9eeee63cd45a8a66f6b1a676488ad.png) >然后去生成我们Jenkins所需要的Token密钥 ![](https://img.tnblog.net/arcimg/hb/70299a85d12943d2ba7772b90f8a785e.png)
欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739
👈{{preArticle.title}}
👉{{nextArticle.title}}
评价
{{titleitem}}
{{titleitem}}
{{item.content}}
{{titleitem}}
{{titleitem}}
{{item.content}}
尘叶心繁
这一世以无限游戏为使命!
博主信息
排名
6
文章
6
粉丝
16
评论
8
文章类别
.net后台框架
166篇
linux
17篇
linux中cve
1篇
windows中cve
0篇
资源分享
10篇
Win32
3篇
前端
28篇
传说中的c
4篇
Xamarin
9篇
docker
15篇
容器编排
101篇
grpc
4篇
Go
15篇
yaml模板
1篇
理论
2篇
更多
Sqlserver
4篇
云产品
39篇
git
3篇
Unity
1篇
考证
2篇
RabbitMq
23篇
Harbor
1篇
Ansible
8篇
Jenkins
17篇
Vue
1篇
Ids4
18篇
istio
1篇
架构
2篇
网络
7篇
windbg
4篇
AI
18篇
threejs
2篇
人物
1篇
嵌入式
2篇
python
13篇
HuggingFace
8篇
pytorch
9篇
opencv
6篇
最新文章
最新评价
{{item.articleTitle}}
{{item.blogName}}
:
{{item.content}}
关于我们
ICP备案 :
渝ICP备18016597号-1
网站信息:
2018-2024
TNBLOG.NET
技术交流:
群号656732739
联系我们:
contact@tnblog.net
欢迎加群
欢迎加群交流技术