zl程序教程

您现在的位置是:首页 >  其他

当前栏目

SonarQube - 安装与运行SonarQube

安装 运行 SonarQube
2023-09-14 09:00:40 时间

1 - 下载SonarQube

SonarQube有多个版本,其中CE(Community Edition)版本免费开源,其余的开发者版本、企业版本和数据中心版本都是收费版本。

特别说明:

2 - 准备

官网安装要求:https://docs.sonarqube.org/latest/requirements/requirements/
对硬件、操作系统参数设置、Java版本等都有对应的要求。

确认系统和Java版本信息

[root@node201 ~]# cat /etc/system-release
CentOS Linux release 7.5.1804 (Core) 
[root@node201 ~]# 
[root@node201 ~]# uname -a
Linux node201 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@node201 ~]# java -version
openjdk version "1.8.0_161"
OpenJDK Runtime Environment (build 1.8.0_161-b14)
OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)

临时修改Linux系统级别的参数

[root@node201 ~]# 
[root@node201 ~]# sysctl vm.max_map_count
vm.max_map_count = 65530
[root@node201 ~]# sysctl fs.file-max
fs.file-max = 790172
[root@node201 ~]# ulimit -n
1024
[root@node201 ~]# ulimit -u
31155
[root@node201 ~]# 
[root@node201 ~]# sysctl -w vm.max_map_count=262144
vm.max_map_count = 262144
[root@node201 ~]# sysctl -w fs.file-max=65536
fs.file-max = 65536
[root@node201 ~]# ulimit -n 65536
[root@node201 ~]# ulimit -u 4096
[root@node201 ~]# 
[root@node201 ~]# sysctl vm.max_map_count
vm.max_map_count = 262144
[root@node201 ~]# sysctl fs.file-max
fs.file-max = 65536
[root@node201 ~]# ulimit -n
65536
[root@node201 ~]# ulimit -u
4096
[root@node201 ~]# 

永久修改Linux系统级别的参数

[root@node201 ~]# vim /etc/sysctl.conf 
[root@node201 ~]# cat /etc/sysctl.conf |grep -v "#"
vm.max_map_count = 262144
fs.file-max = 65536
[root@node201 ~]# 
[root@node201 ~]# vim /etc/security/limits.conf
[root@node201 ~]# cat /etc/security/limits.conf |grep -v "#"
*    soft    nofile    65536
*    hard    nofile    65536
[root@node201 ~]# 
[root@node201 ~]# reboot
......
......
......
[root@node201 ~]# sysctl vm.max_map_count
vm.max_map_count = 262144
[root@node201 ~]# sysctl fs.file-max
fs.file-max = 65536
[root@node201 ~]# ulimit -n
65536
[root@node201 ~]# ulimit -u
31155
[root@node201 ~]# 

数据库(非必须)

SonarQube服务器默认使用自带的H2数据库,但建议只在测试阶段使用。
在实际项目使用时,更改为更加稳定强大的外置数据库,例如开源免费的PostgreSQL等。

3 - 安装

ElasticSearch组件不允许使用root启动,因此需要创建sonar用户,用于启动SonarQube服务器进程。

[root@node201 ~]# adduser sonar
[root@node201 ~]# passwd sonar
Changing password for user sonar.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@node201 ~]#
[root@node201 ~]# visudo
[root@node201 ~]# cat /etc/sudoers |grep "sonar"
sonar    ALL=(ALL)   ALL
[root@node201 ~]# 
[root@node201 ~]# su - sonar
Last login: Thu Nov 28 14:55:07 CST 2019 on pts/0
[sonar@node201 ~]$ 

下载并解压缩

[root@node201 ~]# wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-6.7.7.zip
......
......
......
[root@node201 ~]# ll sonarqube-6.7.7.zip 
-rw-r--r-- 1 root root 159921852 Nov 28 14:52 sonarqube-6.7.7.zip
[root@node201 ~]# 
[root@node201 ~]# ll /usr/share/sonar*
ls: cannot access /usr/share/sonar*: No such file or directory
[root@node201 ~]# 
[root@node201 ~]# unzip sonarqube-6.7.7.zip -d /usr/share/
......
......
......
[root@node201 ~]# ll /usr/share/sonarqube-6.7.7
total 12
drwxr-xr-x 8 root root  136 Apr 16  2019 bin
drwxr-xr-x 2 root root   50 Apr 16  2019 conf
-rw-r--r-- 1 root root 7651 Apr 16  2019 COPYING
drwxr-xr-x 2 root root   24 Apr 16  2019 data
drwxr-xr-x 7 root root  150 Apr 16  2019 elasticsearch
drwxr-xr-x 4 root root   40 Apr 16  2019 extensions
drwxr-xr-x 9 root root  140 Apr 16  2019 lib
drwxr-xr-x 2 root root    6 Apr 16  2019 logs
drwxr-xr-x 2 root root   24 Apr 16  2019 temp
drwxr-xr-x 9 root root 4096 Apr 16  2019 web
[root@node201 ~]# 

设置权限并启动sonar服务

[root@node201 ~]# chown -R sonar:sonar /usr/share/sonarqube-6.7.7
[sonar@node201 ~]$ sh /usr/share/sonarqube-6.7.7/bin/linux-x86-64/sonar.sh start
Starting SonarQube...
Started SonarQube.
[sonar@node201 ~]$ 

开放端口

[sonar@node201 ~]$ sudo firewall-cmd --add-port=9000/tcp --permanent
success
[sonar@node201 ~]$ sudo firewall-cmd --reload
success
[sonar@node201 ~]$ 

打开SonarQube界面,默认web端口为9000,
http://192.168.16.201:9000/

管理员默认账号和密码为admin/admin

4 - 参考消息