美文网首页
sonarqube安装&设置服务service

sonarqube安装&设置服务service

作者: 与狼共舞666 | 来源:发表于2020-06-17 19:40 被阅读0次

Install the Server

Installing the Database

支持多个数据库引擎。确保遵循为数据库列出的要求,它们是真实的要求,而不是建议。

创建一个空schema和一个sonarqube用户。向该sonarqube用户授予创建,更新和删除此schema对象的权限。

PostgreSQL

If you want to use a custom schema and not the default "public" one, the PostgreSQL search_path property must be set:

如果你想用一个自定义的schema,不是默认的"public",PostgreSQL数据库 search_path属性必须被设置。


ALTER USER mySonarUser SET search_path to mySonarQubeSchema

Installing the Server from the ZIP file

首先,检查requirements,然后下载并解压缩发行版(不要解压缩到以数字开头的目录中)。

SonarQube无法在基于Unix的系统上以root用户身份运行,因此如有必要,创建一个专用用户帐户以用于SonarQube。

$SONARQUBE-HOME (below) 指的是SonarQube发行版已解压缩的目录的路径。

Setting the Access to the Database

编辑$SONARQUBE-HOME/conf/sonar.properties以配置数据库设置。模板可用于每个受支持的数据库。只需取消注释并配置所需的模板,然后注释掉专用于H2的行:


Example for PostgreSQL

sonar.jdbc.username=sonarqube

sonar.jdbc.password=mypassword

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

Adding the JDBC Driver

已经提供了支持的数据库(Oracle除外)的驱动程序。不要更换提供的驱动程序;他们是唯一受支持的。对于Oracle,将JDBC驱动程序复制到$SONARQUBE-HOME/extensions/jdbc-driver/oracle。

Configuring the Elasticsearch storage path

默认情况下,Elasticsearch数据存储在$SONARQUBE-HOME/data中,但不建议将其用于生产实例。 相反,您应该将此数据存储在其他位置,最好是在具有快速I/O的专用卷中。除了保持可接受的性能外,这样做还可以简化SonarQube的升级。

编辑$SONARQUBE-HOME/conf/sonar.properties以配置以下设置:


sonar.path.data=/var/sonarqube/data

sonar.path.temp=/var/sonarqube/temp

用于启动SonarQube的用户必须具有对这些目录的读写权限。

Starting the Web Server

默认端口为“ 9000”,上下文路径为“ /”。这些值可以在$SONARQUBE-HOME/conf/sonar.properties中进行更改:


sonar.web.host=192.0.0.1

sonar.web.port=80

sonar.web.context=/sonarqube

Execute the following script to start the server:

  • On Linux/Mac OS: bin/sonar.sh start

  • On Windows: bin/windows-x86-64/StartSonar.bat

您现在可以在http://localhost:9000浏览SonarQube(默认的系统管理员凭据为admin / admin)。

启动过程中一般会报如下的错误:


23 [2] bootstrap checks failed

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

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

1.对于第一个错误

vi /etc/security/limits.conf 该文件为通过PAM登录的用户设置资源限制。它不影响系统服务的资源限制。后面设置服务单元的过程遇到这个坑 修改配置文件,在文件最后加入下面两个行。用户退出重新登录生效。我这里是重启后生效的。


* soft nofile 65536

* hard nofile 65536

# /etc/security/limits.conf

#

#This file sets the resource limits for the users logged in via PAM.

#It does not affect resource limits of the system services.

#

#Also note that configuration files in /etc/security/limits.d directory,

#which are read in alphabetical order, override the settings in this

#file in case the domain is the same or more specific.

#That means for example that setting a limit for wildcard domain here

#can be overriden with a wildcard setting in a config file in the

#subdirectory, but a user specific setting here can be overriden only

#with a user specific setting in the subdirectory.

#

#Each line describes a limit for a user in the form:

#

#<domain>        <type>  <item>  <value>

#

#Where:

# /etc/security/limits.conf

#

#This file sets the resource limits for the users logged in via PAM.

#It does not affect resource limits of the system services.

#

#Also note that configuration files in /etc/security/limits.d directory,

#which are read in alphabetical order, override the settings in this

#file in case the domain is the same or more specific.

#That means for example that setting a limit for wildcard domain here

#can be overriden with a wildcard setting in a config file in the

#subdirectory, but a user specific setting here can be overriden only

#with a user specific setting in the subdirectory.

#

#Each line describes a limit for a user in the form:

#

#<domain>        <type>  <item>  <value>

#

#Where:

#<domain> can be:

#        - a user name

#        - a group name, with @group syntax

#        - the wildcard *, for default entry

#        - the wildcard %, can be also used with %group syntax,

#                for maxlogin limit

#

#<type> can have the two values:

#        - "soft" for enforcing the soft limits

#        - "hard" for enforcing hard limits

#

#<item> can be one of the following:

#        - core - limits the core file size (KB)

#        - data - max data size (KB)

#        - fsize - maximum filesize (KB)

#        - memlock - max locked-in-memory address space (KB)

#        - nofile - max number of open file descriptors

#        - rss - max resident set size (KB)

#        - stack - max stack size (KB)

#        - cpu - max CPU time (MIN)

#        - nproc - max number of processes

#        - as - address space limit (KB)

#        - maxlogins - max number of logins for this user

#        - maxsyslogins - max number of logins on the system

#        - priority - the priority to run user process with

#        - locks - max number of file locks the user can hold

#        - sigpending - max number of pending signals

#        - msgqueue - max memory used by POSIX message queues (bytes)

#        - nice - max nice priority allowed to raise to values: [-20, 19]

#        - rtprio - max realtime priority

重启后查看效果:open files (-n) 65535


[root@VM_2_11_centos system]# ulimit -a

core file size          (blocks, -c) 0

data seg size          (kbytes, -d) unlimited

scheduling priority            (-e) 0

file size              (blocks, -f) unlimited

pending signals                (-i) 15071

max locked memory      (kbytes, -l) 64

max memory size        (kbytes, -m) unlimited

open files                      (-n) 65535

pipe size            (512 bytes, -p) 8

POSIX message queues    (bytes, -q) 819200

real-time priority              (-r) 0

stack size              (kbytes, -s) 8192

cpu time              (seconds, -t) unlimited

max user processes              (-u) 15071

virtual memory          (kbytes, -v) unlimited

file locks                      (-x) unlimited

对于设置systemd service的资源限制,可以在全局配置文件/etc/systemd/system.conf中的DefaultLimitNOFILE/DefaultLimitNPROC设置,系统默认没有配置,也可在对应的service单元中指定。这里以单个服务单元中添加配置参数限制说明:


[root@VM_2_11_centos system]# systemctl status sonarqube

● sonarqube.service - sonarqube

  Loaded: loaded (/usr/lib/systemd/system/sonarqube.service; enabled; vendor preset: disabled)

  Active: active (running) since Wed 2020-06-17 10:09:08 CST; 8h ago

  Process: 31938 ExecStop=/lvmdata/sonarqube/bin/linux-x86-64/sonar.sh stop (code=exited, status=0/SUCCESS)

  Process: 32119 ExecStart=/lvmdata/sonarqube/bin/linux-x86-64/sonar.sh start (code=exited, status=0/SUCCESS)

Main PID: 32169 (wrapper)

  CGroup: /system.slice/sonarqube.service

          ├─32169 /lvmdata/sonarqube/bin/linux-x86-64/./wrapper /lvmdata/sonarqube/bin/linux-x86-64/../../conf/wrapper.conf wrapper.syslog.ident=SonarQube wrapper.pidfile=/lvmdata/sonarqube/bin/linux-x86-64/....

          ├─32171 /usr/local/jdk/bin/java -Dsonar.wrapped=true -Djava.awt.headless=true -Xms8m -Xmx32m -Djava.library.path=./lib -classpath ../../lib/jsw/wrapper-3.2.3.jar:../../lib/common/woodstox-core-lgpl-...

          ├─32200 /usr/local/jdk/bin/java -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.t...

          ├─32326 /usr/local/jdk/bin/java -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/lvmdata/sonarqube/temp -XX:-OmitStackTraceInFastThrow --add-opens=java.base/java.util=ALL-UNNAMED --a...

          └─32426 /usr/local/jdk/bin/java -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/lvmdata/sonarqube/temp -XX:-OmitStackTraceInFastThrow --add-opens=java.base/java.util=ALL-UNNAMED -Xm...

Jun 17 10:09:07 VM_2_11_centos systemd[1]: Starting sonarqube...

Jun 17 10:09:07 VM_2_11_centos sonar.sh[32119]: Starting SonarQube...

Jun 17 10:09:08 VM_2_11_centos systemd[1]: Started sonarqube.

[root@VM_2_11_centos system]# cat /proc/32169/limits

Limit                    Soft Limit          Hard Limit          Units   

Max cpu time              unlimited            unlimited            seconds 

Max file size            unlimited            unlimited            bytes   

Max data size            unlimited            unlimited            bytes   

Max stack size            8388608              unlimited            bytes   

Max core file size        unlimited            unlimited            bytes   

Max resident set          unlimited            unlimited            bytes   

Max processes            100000              100000              processes

Max open files            100000              100000              files   

Max locked memory        65536                65536                bytes   

Max address space        unlimited            unlimited            bytes   

Max file locks            unlimited            unlimited            locks   

Max pending signals      15071                15071                signals 

Max msgqueue size        819200              819200              bytes   

Max nice priority        0                    0                   

Max realtime priority    0                    0                   

Max realtime timeout      unlimited            unlimited            us     

note 非root用户的最大进程数为4096,可在/etc/security/limits.d/20-nproc.conf中查看

2.对于第二个错误,通过修改内核参数即可解决


# root用户

vi /etc/sysctl.conf

# 添加以下配置

vm.max_map_count=655360

# 生效

sysctl -p

Adjusting the Java Installation

如果服务器上安装了多个Java版本,则可能需要明确定义使用哪个Java版本。

要更改SonarQube使用的Java JVM,请编辑$ SONARQUBE-HOME/conf/wrapper.conf并更新以下行:


wrapper.java.command=/path/to/my/jdk/bin/java

设置systemd-unit服务


[Unit]

Description=sonarqube

After=network.target

[Service]

LimitCORE=infinity

LimitNOFILE=100000

LimitNPROC=100000

Type=forking

ExecStart=/lvmdata/sonarqube/bin/linux-x86-64/sonar.sh start

ExecReload=/lvmdata/sonarqube/bin/linux-x86-64/sonar.sh restart

ExecStop=/lvmdata/sonarqube/bin/linux-x86-64/sonar.sh stop

User=sonarqube

Group=sonarqube

[Install]

WantedBy=multi-user.target

相关文章

网友评论

      本文标题:sonarqube安装&设置服务service

      本文链接:https://www.haomeiwen.com/subject/khqexktx.html