首页 > 系统相关 >Linux下SonarQube+Runner+Scanner离线安装

Linux下SonarQube+Runner+Scanner离线安装

时间:2023-01-18 18:45:02浏览次数:46  
标签:Scanner Runner sonarqube qsh 离线 local runner sonar root

 Linux下SonarQube+Runner+Scanner离线安装

(一)、创建sonar数据库

#创建sonar数据库

mysql> create user 'sonar'@'%' identified by 'yzt12345';

Query OK, 0 rows affected (0.00 sec)

mysql>create database sonarqube;

Query OK, 1 row affected (0.00 sec)

mysql>grant all privileges on sonarqube.* TO 'sonar'@'%' identified by 'yzt12345';

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql>flush privileges;

Query OK, 0 rows affected (0.00 sec)

(二)、安装SonarQube

第一步:下载

sonarqube下载地址: http://www.sonarqube.org/downloads/

sonar-runner下载地址:   http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip

sonar-scanner下载扫描器地址: https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner

wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-6.7.6.zip

wget http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip

wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.3.0.1492-linux.zip

unzip sonarqube-6.7.6.zip

unzip sonar-runner-dist-2.4.zip

unzip sonar-scanner-cli-3.3.0.1492-linux.zip

mv sonarqube-6.7.6 /usr/local/sonarqube

mv sonar-runner-2.4 /usr/local/sonar-runner

mv sonar-scanner-3.3.0.1492-linux /usr/local/sonar-scanner

第二步:配置环境变量

[root@qsh local]# vim /etc/profile

#--------------------------------------------------------------------

export SONAR_HOME=/usr/local/sonarqube

export SONAR_RUNNER_HOME=/usr/local/sonar-runner

export SONAR_SCANNER_HOME=/usr/local/sonar-scanner

PATH=$PATH:$SONAR_HOME/bin:$SONAR_RUNNER_HOME/bin:$SONAR_SCANNER_HOME/bin

[root@qsh local]# source /etc/profile

第三步:配置sonar.properties

[root@Nginx-Jenkins-Server sonarqube]# cd /usr/local/sonarqube/conf/

[root@Nginx-Jenkins-Server conf]# vim sonar.properties

#修改连接数据库用户密码

sonar.jdbc.username=sonar

sonar.jdbc.password=yzt12345

#取消注释,修改数据库地址

sonar.jdbc.url=jdbc:mysql://127.0.0.1:3306/sonarqube?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false

#取消下面两行注释

sonar.web.host=192.168.65.132

sonar.web.port=9000

sonarqube启动参数,修改配置: /usr/local/sonarqube/conf/wrapper.conf

ES启动参数,修改配置:/usr/local/sonarqube/elasticsearch/config/jvm.options

第四步:配置SonarQube Runner

[root@qsh conf]# cd /usr/local/sonar-runner/conf/

[root@qsh conf]# vim sonar-runner.properties

#----- Default SonarQube server

sonar.host.url=http://192.168.65.132:9000

#----- PostgreSQL

#sonar.jdbc.url=jdbc:postgresql://localhost/sonar

#----- MySQL

sonar.jdbc.url=jdbc:mysql://127.0.0.1:3306/sonarqube?useUnicode=true&characterEncoding=utf8

#----- Oracle

#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE

#----- Microsoft SQLServer

#sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor

#----- Global database settings

sonar.jdbc.username=sonar

sonar.jdbc.password=yzt12345

#----- Default source code encoding

sonar.sourceEncoding=UTF-8

#----- Security (when 'sonar.forceAuthentication' is set to 'true')

sonar.login=admin

sonar.password=admin

[root@qsh sonar-runner]# cd /usr/local/sonar-runner

[root@qsh sonar-runner]# mkdir /data

[root@qsh sonar-runner]# mkdir /data/sonar-runner

[root@qsh sonar-runner]# vim sonar-project.properties

#-------------------------------------------------

#Required metadata

#对于较大的工程项目,经常出现内存不够的问题,需要利用环境变量设置虚拟机的内存

SONAR_RUNNER_OPTS=-Xmx512m-XX:MaxPermSize=128m

sonar.projectKey=my:project

sonar.projectName=yaok

sonar.projectVersion=1.0

#Paths to source directories.

#Paths are relative to the sonar-project.properties file. Replace "\" by "/" on Windows.

#Do not put the "sonar-project.properties" file in the same directory with the source code.

#(i.e. never set the "sonar.sources" property to ".")

sonar.sources=/data/sonar-runner

#The value of the property must be the key of the language.

sonar.language=java

#Encoding of the source code

sonar.sourceEncoding=UTF-8

#Additional parameters

sonar.my.property=value

第五步:安装后启动SonarQube

用root无法启动lSonarQube,需要另外新建普通用户来启动

[root@qsh ~]# useradd esadmin

[root@qsh ~]# chown -R esadmin.esadmin /usr/local/sonarqube

[root@qsh ~]# vim /usr/local/sonarqube/elasticsearch/config/elasticsearch.yml

//开启以下两行

 

 

 

//切换用户,启动

[root@qsh ~]# su - esadmin

[esadmin@qsh ~]$ cd /usr/local/sonarqube/

[esadmin@qsh sonarqube]$ ./bin/linux-x86-64/sonar.sh start

Starting SonarQube...

Started SonarQube.

//检查是否正常启动

[esadmin@qsh sonarqube]$ ps -aux |grep sonar

//启动日志查看

#sonarqube

tail -f /usr/local/sonarqube/logs/sonar.log

#Es

tail -f /usr/local/sonarqube/logs/es.log

附:启动的时候报错

1,错误:max file descriptors [4096] for elasticsearch process is too low, increase to at least

解决方法:

[root@qsh ]#vim /etc/security/limits.conf

#在文件最后添加下面四行

*               soft     nofile          65536

*               hard     nofile         65536

*               soft     nproc          4096

*               hard     npro          4096

#查看文件限制命令

[esadmin@qsh sonarqube]$ ulimit -Hn

655350

2,错误,max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

解决方法:

切换到root用户修改配置sysctl.conf

[root@qsh]#vim /etc/sysctl.conf

#添加下面配置:

vm.max_map_count=655360

并执行命令:

[root@qsh]# sysctl -p

第六步:安装后启动Sonar-Runner

[root@qsh sonar-runner]$ cd /usr/local/sonar-runner

[root@qsh sonar-runner]$ ./bin/sonar-runner -e -X

如果能够看到下面的输出信息,证明你的SonarQube Runner安装并配置正确啦。

问题:sonarQube环境搭建过程中报错:ERROR web[][o.a.c.h.Http11NioProtocol] Failed to initialize end point associated with ProtocolHandler [“http-nio-192.168.X.X-9000”]

java.net.BindException: Cannot assign requested address

解决:使用127.0.0.1,启动没问题,说明IP不对,使用命令ip addr 查询实际IP,即可成功启动

如果是报已经被绑定,说明是进程没有被真正关掉

使用netstat -ano|findstr 9000命令查看,查到PID后,再kill

第七步:使用浏览器就可以直接登陆

 http://192.168.65.132:9000/about

 

 

 

登录:admin/admin

//安装中文语言包

选择语言包,点击安装,安装好后重启,重新进入就是汉化版了

 

 

 

 

 

 

 

插件安装位置: /usr/local/sonarqube/extensions/plugins/

第八步:配置SonarQube Scanner代码扫描工具

[root@qsh sonar-scanner]# cd /usr/local/sonar-scanner/conf/

[root@Nginx-Jenkins-Server conf]# vim 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:9000

sonar.host.url=http://192.168.65.132:9000

 

#----- Default source code encoding

#sonar.sourceEncoding=UTF-8

sonar.sourceEncoding=UTF-8

# 拉取sonar示例代码

[root@qsh ]# mkdir /data/sonar-examples

[root@qsh ]# cd /data/sonar-examples

[root@qsh sonar-examples]# git clone https://github.com/SonarSource/sonar-scanning-examples.git

#在项目的根目录中创建配置文件: sonar-project.properties

[root@qsh sonar-examples]# cd sonar-scanning-examples/sonarqube-scanner-maven/

[root@qsh sonarqube-scanner-maven]# vim sonar-project.properties

#------------------------------------------------------------------

# must be unique in a given SonarQube instance

sonar.projectKey=devops-demo

# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.

sonar.projectName=devops-demo

sonar.projectVersion=1.0

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.

# This property is optional if sonar.modules is set.

sonar.sources=.

sonar.java.binaries=.

# Encoding of the source code. Default is default system encoding

sonar.sourceEncoding=UTF-8

#代码扫描测试

[root@qsh sonarqube-scanner-maven]# sonar-scanner

//使用浏览器打开 http://192.168.65.132:9000/projects ,查看扫描结果

 

 

 

 

注释:手工测试时,可以直接把自己的程序包源码文件夹直接拷贝到sonar-scanning-examples/sonarqube-scanner-maven/下,然后,直接执行

[root@qsh sonarqube-scanner-maven]# sonar-scanner

标签:Scanner,Runner,sonarqube,qsh,离线,local,runner,sonar,root
From: https://www.cnblogs.com/dabao150114/p/17060390.html

相关文章

  • Scanner对象
    Scanner对象Scanner是Java5的新特性,导入包的路径为"java.util.Scanner"我们可以通过Scanner类来获取用户的输入Scanner基本语法创建一个Scanner对象Scanners=newS......
  • pyenv离线安装Python
    ​​welcometomyblog​​使用pyenv安装python3.7.4,下载了很久没有下载成功,于是尝试离线安装一.手动下载python3.7.4pyenv安装python时会给出下载地址,去这个地址下......
  • Centos 7 离线升级内核
    1.查看现在的内核版本uname-r 2.下载内核RPM包https://elrepo.org/linux/kernel/el7/x86_64/RPMS/3.选择rpm包,lt长期维护版ml最新稳定版,下载下图红框选中的文件......
  • Linux CentOS 8系统离线升级内核版本
    LinuxCentOS8系统离线升级内核版本 搬运如下文章,十分感谢https://blog.csdn.net/WQwinter/article/details/127231086  二、升级步骤    1、查看当......
  • Windows离线安装MeterSphere
    1安装操作步骤​安装 WSL​设置 WSL2 为默认​安装 Ubuntu​检测 UbuntuWSL 版本​安装docker​docker设置​下载安装包(​​点击下载​​)​启动 Ubuntu​检查 D......
  • 【服务器数据恢复】infortrend存储raid6故障离线,强制上线成功后分区数据无法访问的数
    服务器数据恢复环境:某影音制作公司一台infortrend某型号存储设备;12块硬盘组建raid6磁盘阵列,共一个lun映射到WINDOWS系统;在WINDOWS系统上,划分了一个GPT分区。服务器故障&......
  • Scanner对象
    Scanner对象java.util.Scanner是java5的新特征,使我们可以通过Scanner类来获取用户的输入基本语法:Scanners=newScanner(System.in)通过Scanner类的next()与nextLine()......
  • docker中离线安装nginx
    注:默认已经安装好docker。 为什么要离线安装?其实离线安装是建立在在线安装的基础上的;因为有可能我们的服务器由于安全问题无法访问外网,自此我们需要将镜像手动上传至服......
  • 深入理解ClassPathBeanDefinitionScanner
    1介绍ClassPathBeanDefinitionScanner可以扫描指定路径下的@Component类,将这些类解析成BeanDefinition,注册到Spring容器中。此外,ClassPathBeanDefinitionScanner通过注......
  • Loadrunner11创建脚本、打开vugen、controller、analysis超级慢的解决方法
    问题现象启动的时候很慢,即打开LR11的启动程序很慢;点击创建脚本的时候也很慢:打开脚本很慢:创建controller场景很慢:分析结果的时候很慢:解决方法:如果你......