sonarqube + gitlab + jenkins + maven integrated structures (a)

 

 

 

A SonarQube introduce
SonarQube is an open source code analysis platform for ongoing analysis and evaluation of the quality of the code, supports the detection Java, JavaScript, C #, C , C ++ and other two dozen programming languages. SonarQube the project can be detected by potential Bug, vulnerabilities, code specification, code duplication, lack of unit test code and other issues, and provides a UI interface for viewing and management.
Architecture
SonarQube consists of four parts:
(1) SonarQube Server
SonarQube Server will start the three main processes: Web Server: UI management interface, Search Server: based Elasticsearch search service, Compute Engine Server: Calculation Engine service, code analysis and save to sonarQube Database.
(2) SonarQube Database
configuration information stored sonarqube instance, project, view the snapshot information and the like
(3) SonarQube Scanners
analysis item code can be constructed in / on the continuous integration server running one or more of
(. 4) sonarqube Plugins
sonarqube Plugin Manager

Two structures

2.1 environmental requirements
are mainly two requirements
(1) the JDK. 8
(2) the MySQL (> = 5.6 && <8.0) (also supports other data)
mounting java.jdk
presence server typically openjdk yum mostly installed jdk openjdk
RPM - qa | grep java
if openjdk, information will appear XXXX_openjdk_XXX

rpm -e --nodeps `rpm -qa | grep java`
disposable deleted successfully

Jdk package will be uploaded to the server
via yum install a tool.
#yum install lrzsz -y

Check the yum installation package is installed successfully.
#rpm -qa | grep lrzsz

The figure illustrates a successful installation.
Run the file upload:
#rz
will open the local file selection dialog box, select the file, can be uploaded to determine the current directory.
If you overwrite the original file, execute:
#rz -y

Copy the current directory to

decompress jdk-8u181-linux-x64.tar.gz file:
the tar -zxvf jdk-8u181-linux-x64.tar.gz

 

Return to the previous and create / usr / local / jdk directory:
cd ..
mkdir -p the JDK

After entering the directory tools jdk-8u181-linux-x64 jdk directory moved to:
[the root Tools @ localhost] # Music Videos jdk1.8.0_181 / usr / local / jdk /
[the root @ localhost Tools] CD # / usr / local / jdk /

 

Open / etc in the profile file / directory:
Vim / etc / profile
The following code is appended to the end of the profile file:
the JAVA_HOME = / usr / local / JDK / jdk1.8.0_181
the JRE_HOME the JAVA_HOME = $ / JRE
the PATH the PATH = $: $ the JAVA_HOME / bin: $ the JRE_HOME / bin
the CLASSPATH =: $ the JAVA_HOME / lib / Dt.jar: $ the JAVA_HOME / lib / the tools.jar: $ the JRE_HOME / lib / Dt.jar
Export the JAVA_HOME the JRE_HOME the PATH the CLASSPATH

source / etc / profile
Enter java -version to see the version of the JDK:
[root @ localhost the JDK] # source / etc / profile
[root @ localhost the JDK] # java -version

系统环境准备
系统参数需要满足下述要求
sonarqube一定不能在root帐户下运行
vm.max_map_count 大于或等于 262144
fs.file-max 大于或等于 65536
运行SonarQube的用户至少可以打开 65536个 文件描述符
运行SonarQube的用户可以打开至少2048个线程
seccomp已被编译 进内核

根据需要执行下述命令以使内核参数符合sonar安装需求
#可以使用以下命令查看这些值:
sysctl vm.max_map_count
sysctl fs.file-max
ulimit -n

可以通过以root身份运行以下命令来为当前会话动态设置它们:
sysctl -w vm.max_map_count=262144
sysctl -w fs.file-max=65536
ulimit -n 65536

 

为了更永久设置这些值,则必须修改/etc/sysctl.d/99-sonarqube.conf(或/etc/sysctl.conf文件)#文件末尾添加下述两行
vi /etc/sysctl.conf

 

vm.max_map_count=262144
fs.file-max=65536

 

在/etc/profile文件末尾添加ulimit -n 65536
vi /etc/profile
ulimit -n 65536
#保存后运行#source /etc/profile 使其生效
source /etc/profile

2.2 开始安装

1、安装wget工具
[root@localhost ~]#yum -y install wget
wget 时提示 -bash:wget command not found,很明显没有安装wget软件包。一般linux最小化安装时,wget不会默认被安装。

下载
[root@localhost ~]#cd /opt
[root@localhost opt]#wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-6.7.7.zip
这里选择xshell rz将本地文件上传到服务器opt目录中

链接:https://pan.baidu.com/s/1GKjECv9QjGNZ8aAJYdlXNw 密码:ojfg

3、解压
[root@localhost opt]#unzip sonarqube-6.7.7
[root@localhost opt]#cd sonarqube-6.7.7

4、增加用户sonar
//创建sonar用户
//目录组和用户都是sonar
//sonarqube文件设置777
//编写配置文件
[root@localhost ~]# useradd sonar
[root@localhost ~]# chown -R sonar.sonar /opt/sonarqube-6.7.7/

5、编辑sonarqube配置文件
[root@localhost sonarqube-6.7.7]# vi conf/sonar.properties
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:mysql://192.168.1.220:3305/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false

sonar.web.host=192.168.1.x
sonar.web.port=x

 

保存退出。

 

6查看状态
[root@localhost ~]# cd /usr/local/src/sonarqube-6.7.7
[root@localhost sonarqube-6.7.7]# su sonar ./bin/linux-x86-64/sonar.sh status

 

说明:一直无法运行的时候删除sonarqube-6.7.7 下的temp文件
rm -f /opt/sonarqube-6.7.7/temp

 7运行脚本启动服务

[root@localhost sonarqube-6.7.7]# su sonar ./bin/linux-x86-64/sonar.sh start
//以普通用户起服务,不然es启动会报错,用法:console、start、status、stop...

 在启动彻底完成前不可信!什么叫启动"彻底完成"? 见下面:

 

至此,SonarQube启动成功!

排错说明:sonar.log  es.log  web.log

8、登录web端
在浏览器输入:http:// 192.168.1.217:9090
初始用户:admin
初始密码:admin
登录后,可以点击自己账户修改密码。

 

Guess you like

Origin www.cnblogs.com/duxingren/p/11356101.html