CentOS安装Sonarqube9

CentOS安装Sonarqube9

 

文章目录

    • 1. 下载软件
    • 2. 修改配置
      • 2.1 修改系统配置
      • 2.2 修改Sonarqube配置
    • 3. 启动软件
      • 3.1 创建用户、授权
      • 3.2 启动
      • 3.3 停止
    • 4. 安装中文插件
      • 4.1 下载插件
      • 4.2 安装插件
    • 5. 安装完成

 

1. 下载软件

进入Sonarqube官网下载页面:https://www.sonarqube.org/downloads,选择免费且开源的社区版本进行下载;如下:

download1

因为Sonarqube是Java语言写的,所以不根据操作系统而区分版本,Linux、Mac、Windows使用的是同一个程序包;

官方提供的是一个zip压缩包,内置了Linux、Mac、Windows的启动脚本,可解压后直接使用;

Sonarqube9版本需要JDK11版本的支持,所以请先自行安装JDK11;


2. 修改配置

2.1 修改系统配置

因Sonarqube内嵌了ElasticSearch来提高查询速度,而ElasticSearch的启动需要修改一些系统参数;

  1. 修改系统最大打开的文件数和进程的最大数目

    vim /etc/security/limits.conf
    
    ......
    #*               soft    core            0
    #*               hard    rss             10000
    #@student        hard    nproc           20
    #@faculty        soft    nproc           20
    #@faculty        hard    nproc           50
    #ftp             hard    nproc           0
    #@student        -       maxlogins       4# 新增配置
    * soft nofile 65536
    * hard nofile 65536
    * soft nproc 4096
    * hard nproc 4096# End of file
    
  2. 修改Linux内核配置

    vim /etc/sysctl.conf
    
    # sysctl settings are defined through files in
    # /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
    #
    # Vendors settings live in /usr/lib/sysctl.d/.
    # To override a whole file, create a new file with the same in
    # /etc/sysctl.d/ and put new settings there. To override
    # only specific settings, add a file with a lexically later
    # name in /etc/sysctl.d/ and put new settings there.
    #
    # For more information, see sysctl.conf(5) and sysctl.d(5).# 新增配置
    vm.max_map_count=655360
    
    # 使其生效
    sysctl -p
    

2.2 修改Sonarqube配置

因Sonarqube需要外部数据库才能启动(当然Sonarqube9版本也有内嵌的数据库,但是个人不推荐使用),而数据库的连接信息在$SONARQUBE_HOME/conf/sonar.properties配置文件中;

Sonarqube9版本支持的数据库有:Oracle 12c/18c/19c、PostgreSQL 9.6+、Microsoft SQLServer 2014/2016/2017/2019、SQL Azure,

注意:Sonarqube从之前的某个版本开始就不再支持MySQL数据库了

Sonarqube会在程序第一次启动时导入数据库表,所以无需提前导入;

vim $SONARQUBE_HOME/conf/sonar.properties
# ......### 数据库配置
# DATABASE
#
# IMPORTANT:
# - The embedded H2 database is used by default. It is recommended for tests but not for
#   production use. Supported databases are 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=postgres
# 数据库密码
sonar.jdbc.password=123456# ......## Oracle数据库连接信息
#----- Oracle 12c/18c/19c
# The Oracle JDBC driver must be copied into the directory extensions/jdbc-driver/oracle/.
# Only the thin client is supported, and we recommend using the latest Oracle JDBC driver. 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数据库连接信息,默认使用"public"的schema,可以通过currentSchema参数指定自定义的schema
#----- PostgreSQL 9.6 or greater
# By default the schema named "public" is used. It can be overridden with the parameter "currentSchema".
sonar.jdbc.url=jdbc:postgresql://127.0.0.1:5432/sonarqube## Microsoft SQLServer数据库连接信息
#----- Microsoft SQLServer 2014/2016/2017/2019 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 9.2.0 package from
# https://docs.microsoft.com/en-us/sql/connect/jdbc/release-notes-for-the-jdbc-driver?view=sql-server-ver15#92
# and copy mssql-jdbc_auth-9.2.0.x64.dll to your path.
#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## 数据库连接池配置设置
#----- Connection pool settings
# The maximum number of active connections that can be allocated
# at the same time, or negative for no limit.
# The recommended value is 1.2 * max sizes of HTTP pools. For example if HTTP ports are
# enabled with default sizes (50, see property sonar.web.http.maxThreads)
# then sonar.jdbc.maxActive should be 1.2 * 50 = 60.
# 连接池最大连接数,推荐为sonar.web.http.maxThreads(HTTP连接最大线程数)的1.2倍
#sonar.jdbc.maxActive=60# The maximum number of connections that can remain idle in the
# pool, without extra ones being released, or negative for no limit.
# 连接池保持激活状态的最大连接数
#sonar.jdbc.maxIdle=5# The minimum number of connections that can remain idle in the pool,
# without extra ones being created, or zero to create none.
# 连接池保持激活状态的最小连接数
#sonar.jdbc.minIdle=2# The maximum number of milliseconds that the pool will wait (when there
# are no available connections) for a connection to be returned before
# throwing an exception, or <= 0 to wait indefinitely.
# 从连接池获取数据库连接的超时时长, 小于等于0表示永不超时
#sonar.jdbc.maxWait=5000#sonar.jdbc.minEvictableIdleTimeMillis=600000
#sonar.jdbc.timeBetweenEvictionRunsMillis=30000### 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
#
# WEB服务JVM配置
#sonar.web.javaOpts=-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError# Same as previous property, but allows to not repeat all other settings like -Xmx
# WEB服务JVM附加配置
#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.
# WEB服务绑定地址
#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).
# WEB服务ContextPath
#sonar.web.context=
# TCP port for incoming HTTP connections. Default value is 9000.
# WEB服务端口
#sonar.web.port=9000# The maximum number of connections that the server will accept and process at any given time.
# When this number has been reached, the server will not accept any more connections until
# the number of connections falls below this value. The operating system may still accept connections
# based on the sonar.web.connections.acceptCount property. The default value is 50.
# HTTP连接最大线程数
#sonar.web.http.maxThreads=50# The minimum number of threads always kept running. The default value is 5.
# HTTP连接最小线程数
#sonar.web.http.minThreads=5# The maximum queue length for incoming connection requests when all possible request processing
# threads are in use. Any requests received when the queue is full will be refused.
# The default value is 25.
# HTTP连接队列最大数
#sonar.web.http.acceptCount=25# ......### SSO认证登录
# ......### LDAP认证登录
# ......### ELASTICSEARCH配置
# ......### 等等其他配置

3. 启动软件

3.1 创建用户、授权

Sonarqube9不支持root用户直接启用(实际上应该是内嵌的elasticsearch不支持),可以为其创建一个sonarqube用户来启用该程序

# 创建组
groupadd sonarqube
# 创建用户
useradd sonarqube -g sonarqube
# 授权
chown -R sonarqube:sonarqube $SONARQUBE_HOME

3.2 启动

# 使用sonarqube用户!!!
# Linux系统启动命令
$SONARQUBE_HOME/bin/linux-x86-64/sonar.sh start

启动后,可在$SONARQUBE_HOME/logs目录查看运行日志;

在启动过程中,开始可能会出现一大片org.elasticsearch.ElasticsearchException: java.util.concurrent.ExecutionException: java.net.ConnectException: 拒绝连接异常抛出,这是因为Sonarqube依赖于Elasticsearch,而刚开始启动时Elasticsearch还未启动完成,Sonarqube就去连接Elasticsearch,自然就会抛出该异常,待Elasticsearch启动成功,Sonarqube连接上Elasticsearch后就不会再抛出该异常了;

3.3 停止

# 使用sonarqube用户!!!
# Linux系统停止命令
$SONARQUBE_HOME/bin/linux-x86-64/sonar.sh stop

4. 安装中文插件

4.1 下载插件

下载地址:https://github.com/xuhuisheng/sonar-l10n-zh

根据其版本兼容列表进行下载对应版本插件,如:Sonarqube-9.2 下载 sonar-l10n-zh-9.2版本

4.2 安装插件

插件下载下来为一个jar包,如:sonar-l10n-zh-plugin-9.2.jar;

将该插件拷贝至$SONARQUBE_HOME/extensions/plugins目录,然后重启Sonarqube即可


5. 安装完成

注意:

  1. 开通服务器防火墙sonarqube的web端口(默认:9000)或者关闭防火墙(不推荐)
  2. 默认登录用户密码:admin/admin
  3. 第一次登录需要重置默认密码

success1

success2

 
原文地址:https://blog.csdn.net/gu19930914/article/details/122603423
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.taodudu.cc/news/show-3704712.html 
posted @ 2023-08-25 16:16  ianCloud  阅读(250)  评论(0编辑  收藏  举报