话不多说,直接先上分析;
本人实测:运行sonar,需要本地搭建jdk环境+elasticsearch环境+db环境
关于sonar支持db问题,此处需要特别声明:
在sonar7.9将宣布不再支持mysql
主要原因就是:sonar更希望通过json存储数据,而mysql不支持,这里可能mysql也需要与时俱进了。
具体问题暂不细究,了解即可。
https://gitlab.com/gitlab-org/gitlab-foss/-/issues/51173#issues
本人下载最新的sonarqube-8.4.1版本显示已经是不支持mysql了,也下载了其他版本
为此,我还特地装了其他数据库。那么我们来看看最新版本支持哪些数据库吧:
上述已经严格说明了数据库选择以及要求,此文章我就只以mysql数据库为例吧。毕竟此数据库是比较更大众一些。
那么如果最新版本的sonarqube不支持了,那哪些版本支持呢?
由于sonar官方下载地址是真的慢,有些版本都是10+k/s下载速度,那么我就下载了sonarbe7.0、sonarbe7.5、sonarbe7.9
实测,sonarbe7.0、sonarbe7.5是支持mysql的,同学可以直接下载。那么我此处将文件上传至百度网盘。有需要的同学可以直接下载
链接:https://pan.baidu.com/s/1OmBNYSXIhgYgAiQFqI8k9A
提取码:osu4
那么我是用的sonarqube7.0版本为例:
粘出配置信息,配置信息相对路径是 ..\sonarqube-7.0\conf\sonar.properties
在修改sonar配置文件的时候,我们需要在我们的本地数据库中新增一个角色“sonar",然后密码也设置为“sonar”、然后再新增一个数据库“sonar”;编码使用utf-8(能够举一反三的也可自定义)
#--------------------------------------------------------------------------------------------------
# DATABASE
#
# IMPORTANT:
# - The embedded H2 database is used by default. It is recommended for tests but not for
# production use. Supported databases are MySQL, Oracle, PostgreSQL and Microsoft SQLServer.
# - Changes to database connection URL (sonar.jdbc.url) can affect SonarSource licensed products.
# User credentials.
# Permissions to create tables, indices and triggers must be granted to JDBC user.
# The schema must be created first.
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
#----- Embedded Database (default)
# H2 embedded database server listening port, defaults to 9092
#sonar.embeddedDatabase.port=9092
#----- MySQL 5.6 or greater
# Only InnoDB storage engine is supported (not myISAM).
# Only the bundled driver is supported. It can not be changed.
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
#----- Oracle 11g/12c
# The Oracle JDBC driver must be copied into the directory extensions/jdbc-driver/oracle/.
# Only the thin client is supported, and only the versions 11.2.x or 12.2.x must be used. See
# https://jira.sonarsource.com/browse/SONAR-9758 for more details.
# If you need to set the schema, please refer to http://jira.sonarsource.com/browse/SONAR-5000
#sonar.jdbc.url=jdbc:oracle:thin:@localhost:1521/XE
#----- PostgreSQL 8.x or greater
# If you don't use the schema named "public", please refer to http://jira.sonarsource.com/browse/SONAR-5000
#sonar.jdbc.url=jdbc:postgresql://localhost/sonar
#----- Microsoft SQLServer 2014/2016 and SQL Azure
# A database named sonar must exist and its collation must be case-sensitive (CS) and accent-sensitive (AS)
# Use the following connection string if you want to use integrated security with Microsoft Sql Server
# Do not set sonar.jdbc.username or sonar.jdbc.password property if you are using Integrated Security
# For Integrated Security to work, you have to download the Microsoft SQL JDBC driver package from
# https://www.microsoft.com/en-us/download/details.aspx?id=55539
# and copy sqljdbc_auth.dll to your path. You have to copy the 32 bit or 64 bit version of the dll
# depending upon the architecture of your server machine.
#sonar.jdbc.url=jdbc:sqlserver://localhost;databaseName=sonar;integratedSecurity=true
# Use the following connection string if you want to use SQL Auth while connecting to MS Sql Server.
# Set the sonar.jdbc.username and sonar.jdbc.password appropriately.
#sonar.jdbc.url=jdbc:sqlserver://localhost;databaseName=sonar
上述配置中,我已经将三个主要配置注释放开了,同时改了我自己的配置
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
原先我以为配置好了数据库,那么就可以正常启动sonar了,但是我发现启动的时候,他打印日志,显示在扫描Elasticsearch???
于是我把Elasticsearch也启动了一下,然后发现???没扫描到??
于是我在配置文件中找了一下,发现是需要配置Elasticsearch的,因为他的默认端口是9001????然后Elasticsearch的默认端口是9100?
那就改一下,同时把地址也改为本机
#--------------------------------------------------------------------------------------------------
# ELASTICSEARCH
# Elasticsearch is used to facilitate fast and accurate information retrieval.
# It is executed in a dedicated Java process. Default heap size is 512Mb.
#
# --------------------------------------------------
# Word of caution for Linux users on 64bits systems
# --------------------------------------------------
# Please ensure Virtual Memory on your system is correctly configured for Elasticsearch to run properly
# (see https://www.elastic.co/guide/en/elasticsearch/reference/5.5/vm-max-map-count.html for details).
#
# When SonarQube runs standalone, a warning such as the following may appear in logs/es.log:
# "max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]"
# When SonarQube runs as a cluster, however, Elasticsearch will refuse to start.
#
# JVM options of Elasticsearch process
#sonar.search.javaOpts=-Xms512m \
# -Xmx512m \
# -XX:+HeapDumpOnOutOfMemoryError
# Same as previous property, but allows to not repeat all other settings like -Xmx
#sonar.search.javaAdditionalOpts=
# Elasticsearch port. Default is 9001. Use 0 to get a free port.
# As a security precaution, should be blocked by a firewall and not exposed to the Internet.
sonar.search.port=9100
# Elasticsearch host. The search server will bind this address and the search client will connect to it.
# Default is loopback address.
# As a security precaution, should NOT be set to a publicly available address.
sonar.search.host=127.0.0.1
其他的话,我也吧web界面的配置放开了
#--------------------------------------------------------------------------------------------------
# WEB SERVER
# Web server is executed in a dedicated Java process. By default heap size is 512Mb.
# Use the following property to customize JVM options.
# Recommendations:
#
# The HotSpot Server VM is recommended. The property -server should be added if server mode
# is not enabled by default on your environment:
# http://docs.oracle.com/javase/8/docs/technotes/guides/vm/server-class.html
#
# Startup can be long if entropy source is short of entropy. Adding
# -Djava.security.egd=file:/dev/./urandom is an option to resolve the problem.
# See https://wiki.apache.org/tomcat/HowTo/FasterStartUp#Entropy_Source
#
#sonar.web.javaOpts=-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError
# Same as previous property, but allows to not repeat all other settings like -Xmx
#sonar.web.javaAdditionalOpts=
# Binding IP address. For servers with more than one IP address, this property specifies which
# address will be used for listening on the specified ports.
# By default, ports will be used on all IP addresses associated with the server.
sonar.web.host=0.0.0.0
# Web context. When set, it must start with forward slash (for example /sonarqube).
# The default value is root context (empty value).
#sonar.web.context=
# TCP port for incoming HTTP connections. Default value is 9000.
sonar.web.port=9000
然后再启动好Elasticsearch(后续测试的时候,发现不启动Elasticsearch也是可以的)
再启动sonar(执行bat脚本)
相对路径是 ..\sonarqube-7.0\conf\sonar.properties ..\sonarqube-7.0\bin\windows-x86-64\StartSonar.bat
显示SonarQube is up就是启动成功了。
那么我们访问浏览器 http://localhost:9000/about
就成功了,然后我们进行其他配置,例如汉化插件(其实也不建议汉化,汉化很多意义都变了。)
汉化插件下载地址,通过对应sonar版本下载对应的插件版本 https://github.com/SonarQubeCommunity/sonar-l10n-zh/releases
我们是7.0版本的,就下载1.2.0版本的插件 下载jar包版本
然后放入安装目录的 ..\sonarqube-7.0\extensions\plugins\文件夹下,重启应用就可以了 (需先杀java进程,然后再启动)
然后我们点击右上角的Log In
默认账户 admin/admin
登录成功后
然后点击配置->项目->项目管理->创建项目
注意:关键字不能是汉字
这里就不写具体搭建项目信息了,不然文章太长了。