#:sonarqube下载地址,我们安装6.7 高版本已经不支持MySQL和Mariadb(最小3G内存)
https://www.sonarqube.org/downloads/
#:安装文档
https://docs.sonarqube.org/6.7/Requirements.html
#;根据文档,先修改内核参数 [email protected]:/usr/local/src# vim /etc/sysctl.conf vm.max_map_count=262144 fs.file-max=65536 [email protected]:/usr/local/src# sysctl -p #:修改文件数 [email protected]:/usr/local/src# ulimit -n 65536 [email protected]:/usr/local/src# ulimit -u 2048 [email protected]:/usr/local/src# vim /etc/security/limits.conf sonarqube - nofile 65536 sonarqube - nproc 2048 #:创建用户 [email protected]:/usr/local/src# useradd -m -s /bin/bash sonarqube #:安装数据库(5.6或5.7) [email protected]:/usr/local/src# apt install mysql-server mysql-client #:修改监听地址 [email protected]:/usr/local/src# vim /etc/mysql/mysql.conf.d/mysqld.cnf bind-address = 0.0.0.0 #:准备数据库 mysql> create database sonar default character set utf8 collate utf8_general_ci; Query OK, 1 row affected (0.00 sec) mysql> GRANT ALL PRIVILEGES ON sonar.* TO ‘sonar‘@‘%‘ IDENTIFIED BY ‘123456‘; Query OK, 0 rows affected, 1 warning (0.00 sec) #:测试一下 [email protected]:/usr/local/src/jdk1.8.0_191# mysql -usonar -h192.168.6.105 -p123456 #:下载sonarqube,并解压 [email protected]:/usr/local/src# unzip sonarqube-6.7.7.zip [email protected]:/usr/local/src# ln -sv /usr/local/src/sonarqube-6.7.7 /usr/local/sonarqube #:修改目录的属主属组 [email protected]:/usr/local/src# chown -R sonarqube.sonarqube /usr/local/sonarqube /usr/local/src/sonarqube-6.7.7 #:切换到普通用户配置 [email protected]:/usr/local/src# su - sonarqube #:修改配置文件 [email protected]:~$ cd /usr/local/sonarqube [email protected]:/usr/local/sonarqube$ vim conf/sonar.properties sonar.jdbc.username=sonar sonar.jdbc.password=123456 sonar.jdbc.url=jdbc:mysql://192.168.6.105:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false sonar.jdbc.maxActive=60 sonar.jdbc.maxIdle=5 #:最大空闲 sonar.jdbc.minIdle=2 #:最小空闲 sonar.jdbc.maxWait=5000 sonar.web.host=0.0.0.0 sonar.web.port=9000 #:如果和PHP装一起,记得改端口 #:启动服务 [email protected]:/usr/local/sonarqube$ ./bin/linux-x86-64/sonar.sh start #:看日志 [email protected]:/usr/local/sonarqube$ tail -f logs/*.log 2019.10.04 13:02:25 INFO app[][o.s.a.SchedulerImpl] Process[ce] is up 2019.10.04 13:02:25 INFO app[][o.s.a.SchedulerImpl] SonarQube is up #:必须能看到这个才算启动成功
#:登录(账号密码都是admin)选跳过torken
#:修改中文
#:如果安装很慢
#:将插件放到此目录,并修改权限
#:重启服务
[email protected]:/usr/local/sonarqube# ./bin/linux-x86-64/sonar.sh restart
#:在jenkins服务器配置扫描器
#:解压并做链接 [email protected]:/usr/local/src# unzip sonar-scanner-cli-4.0.0.1744-linux.zip [email protected]:/usr/local/src# ln -sv /usr/local/src/sonar-scanner-4.0.0.1744-linux /usr/local/sonar-scanner #:修改配置文件,指向sonar server 的地址 [email protected]:/usr/local/src# cd /usr/local/sonar-scanner [email protected]:/usr/local/sonar-scanner# vim conf/sonar-scanner.properties sonar.host.url=http://192.168.6.105:9000 #:下载官方给的案例,测试一下 #:解压 [email protected]:/opt# unzip sonar-examples-master.zip #:进到此目录 [email protected]:/opt/sonar-examples-master/projects/languages# cd /opt/sonar-examples-master/projects/languages
#:想测试那个就进到哪个目录
#:都明白以后再此目录下执行sonar-scanner命令
#:扫描java以来很多,根据提示解决
#:我后来扫描的是python的,扫描完,在web端就可以看到了
#:sonarqube结合jenkins(第一种办法)
#:创建一个Python文件(故意写错) [email protected]:/opt/web3# vim app/index.py #!/usr/bin/env python print "Hello,word" #:在创建检测时需要的那个文件 [email protected]:/opt/web3# vim sonar-project.properties # Required metadatasonar.projectKey=linux37-test:v1sonar.projectName=linux37-test:v1sonar.projectVersion=1.0:v1 # Comma-separated paths to directories with sources (required)sonar.sources=./ # Languagesonar.language=py # Encoding of the source filessonar.sourceEncoding=UTF-8 #;提交到仓库 [email protected]:/opt/web3/app# git add ./* [email protected]:/opt/web3/app# git commit -m "v8" [master 596a068] v8 2 files changed, 16 insertions(+) create mode 100644 app/index.py create mode 100644 app/sonar-project.propertie [email protected]:/opt/web3/app# git push
#:在web端结合job配置
jenkins结合sonarqube (第二种办法)
#:先在jenkins安装sonarqube Scanner插件
#:配置sonarqube
#:配置扫描器
#:在jenkins的项目中配置那个文件
#:点击构建测试一下
原文地址:https://www.cnblogs.com/maxuebin/p/11622405.html
时间: 2024-10-08 11:27:22