首页 > 系统相关 >ubuntu20.04部署sonarqube 9.9

ubuntu20.04部署sonarqube 9.9

时间:2023-03-01 16:45:32浏览次数:58  
标签:ubuntu20.04 java -- sonarqube add 9.9 sonar data

要求

前提条件

sysctl.conf

# echo "vm.max_map_count=524288" >> /etc/sysctl.conf
# echo "fs.file-max=131072" >> /etc/sysctl.conf
# sysctl -p

limits.conf

# echo "sonarqube   -   nofile   131072" >> /etc/security/limits.conf
# echo "sonarqube   -   nproc    8192" >> /etc/security/limits.conf

硬件要求

  • 8 个核心
  • 16GB RAM 

软件版本

OpenJDK:17

PostgreSQL:15

创建sonarqube用户

# groupadd -g 2023 -o -r sonarqube
# useradd -M -N -g sonarqube -o -r -d /data/apps/sonarqube -s /bin/false -c "sonarqube server" -u 2023  sonarqube

设置数据库

创建数据库sonar

postgres=# create database sonar;     # 创建数据库
CREATE DATABASE
postgres=# create user sonar with encrypted password 'sonar';  # 创建用户并设置密码
CREATE ROLE
postgres=# grant all privileges on database sonar to sonar;  # 授权用户
GRANT
postgres=# alter database sonar owner to sonar;   # 执行变更
ALTER DATABASE

查看数据库sonar

postgres=# \l sonar;
                                            List of databases
 Name  | Owner | Encoding |   Collate   |    Ctype    | ICU Locale | Locale Provider | Access privileges 
-------+-------+----------+-------------+-------------+------------+-----------------+-------------------
 sonar | sonar | UTF8     | en_US.UTF-8 | en_US.UTF-8 |            | libc            | =Tc/sonar        +
       |       |          |             |             |            |                 | sonar=CTc/sonar
(1 row)

连接数据库sonar

su - postgres -c " psql -U sonar -d sonar  -h 192.168.1.23 -p 5432 "
Password for user sonar: 
psql (15.2 (Ubuntu 15.2-1.pgdg20.04+1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
Type "help" for help.

sonar=> 

下载sonarqube

# wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-9.9.0.65466.zip

设置sonarqube

解压sonarqube

# unzip sonarqube-9.9.0.65466.zip
# ln -sv /data/apps/sonarqube/sonarqube-9.9.0.65466.zip/ /usr/local/sonarqube

修改sonarqube目录权限

# chown -R sonarqube.sonarqube /data/apps/sonarqube && chown -R sonarqube.sonarqube /usr/local/sonarqube

sonar.properties

egrep -v "^$|^#" /usr/local/sonarqube/conf/sonar.properties
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:postgresql://192.168.1.23/sonar
sonar.path.data=/data/apps/sonarqube/data
sonar.path.temp=/data/apps/sonarqube/temp

创建数据目录

mkdir /data/apps/sonarqube/{data,temp}

修改数据目录属组

chown -R sonarqube.sonarqube /data/apps/sonarqube/

开机启动

查看nohup路径

which nohup
/usr/bin/nohup

sonarqube.service

[Unit]
Description=SonarQube service
After=syslog.target network.target

[Service]
Type=simple
User=sonarqube
Group=sonarqube
PermissionsStartOnly=true
ExecStart=/usr/bin/nohup /usr/local/jdk/bin/java -Xms512m -Xmx512m -Djava.net.preferIPv4Stack=true -jar /usr/local/sonarqube/lib/sonar-application-9.9.0.65466.jar
StandardOutput=syslog
LimitNOFILE=131072
LimitNPROC=8192
TimeoutStartSec=5
Restart=always
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target

开机启动

systemctl enable sonarqube.service && systemctl start sonarqube.service
Created symlink /etc/systemd/system/multi-user.target.wants/sonarqube.service → /lib/systemd/system/sonarqube.service.

查看服务状态

systemctl status sonarqube.service
● sonarqube.service - SonarQube service
     Loaded: loaded (/lib/systemd/system/sonarqube.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2023-03-01 15:53:07 CST; 3min 12s ago
   Main PID: 2264047 (java)
      Tasks: 216 (limit: 18883)
     Memory: 1.9G
     CGroup: /system.slice/sonarqube.service
             ├─2264047 /usr/local/jdk/bin/java -Xms512m -Xmx512m -Djava.net.preferIPv4Stack=true -jar /usr/local/sonarqube/lib/sonar-application-9.9.0.65466.jar
             ├─2264077 /usr/local/jdk-17.0.6/bin/java -XX:+UseG1GC -Djava.io.tmpdir=/data/apps/sonarqube/temp -XX:ErrorFile=/data/apps/sonarqube/sonarqube-9.9.0.65466/logs/es_hs_err_pid%p.log -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch ->
             ├─2264227 /usr/local/jdk-17.0.6/bin/java -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/data/apps/sonarqube/temp -XX:-OmitStackTraceInFastThrow --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/jav>
             └─2264555 /usr/local/jdk-17.0.6/bin/java -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/data/apps/sonarqube/temp -XX:-OmitStackTraceInFastThrow --add-opens=java.base/java.util=ALL-UNNAMED --add-exports=java.base/jdk.internal.ref=ALL-UNNAMED --add-opens=java>

查看sonarqube日志

tail -f /usr/local/sonarqube/logs/sonar.log 
2023.03.01 16:03:58 INFO  app[][o.s.a.AppFileSystem] Cleaning or creating temp directory /data/apps/sonarqube/temp
2023.03.01 16:03:58 INFO  app[][o.s.a.es.EsSettings] Elasticsearch listening on [HTTP: 127.0.0.1:9001, TCP: 127.0.0.1:11121]
2023.03.01 16:03:58 INFO  app[][o.s.a.ProcessLauncherImpl] Launch process[ELASTICSEARCH] from [/data/apps/sonarqube/sonarqube-9.9.0.65466/elasticsearch]: /data/apps/sonarqube/sonarqube-9.9.0.65466/elasticsearch/bin/elasticsearch
2023.03.01 16:03:58 INFO  app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
2023.03.01 16:04:05 INFO  app[][o.s.a.SchedulerImpl] Process[es] is up
2023.03.01 16:04:05 INFO  app[][o.s.a.ProcessLauncherImpl] Launch process[WEB_SERVER] from [/data/apps/sonarqube/sonarqube-9.9.0.65466]: /usr/local/jdk-17.0.6/bin/java -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/data/apps/sonarqube/temp -XX:-OmitStackTraceInFastThrow --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED --add-exports=java.base/jdk.internal.ref=ALL-UNNAMED --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.management/sun.management=ALL-UNNAMED --add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED -Dcom.redhat.fips=false -Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -Dhttp.nonProxyHosts=localhost|127.*|[::1] -cp ./lib/sonar-application-9.9.0.65466.jar:/data/apps/sonarqube/sonarqube-9.9.0.65466/lib/jdbc/postgresql/postgresql-42.5.1.jar org.sonar.server.app.WebServer /data/apps/sonarqube/temp/sq-process13303001845063311473properties
2023.03.01 16:04:12 INFO  app[][o.s.a.SchedulerImpl] Process[web] is up
2023.03.01 16:04:12 INFO  app[][o.s.a.ProcessLauncherImpl] Launch process[COMPUTE_ENGINE] from [/data/apps/sonarqube/sonarqube-9.9.0.65466]: /usr/local/jdk-17.0.6/bin/java -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/data/apps/sonarqube/temp -XX:-OmitStackTraceInFastThrow --add-opens=java.base/java.util=ALL-UNNAMED --add-exports=java.base/jdk.internal.ref=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.management/sun.management=ALL-UNNAMED --add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED -Dcom.redhat.fips=false -Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -Dhttp.nonProxyHosts=localhost|127.*|[::1] -cp ./lib/sonar-application-9.9.0.65466.jar:/data/apps/sonarqube/sonarqube-9.9.0.65466/lib/jdbc/postgresql/postgresql-42.5.1.jar org.sonar.ce.app.CeServer /data/apps/sonarqube/temp/sq-process17095243054073289148properties
2023.03.01 16:04:15 INFO  app[][o.s.a.SchedulerImpl] Process[ce] is up
2023.03.01 16:04:15 INFO  app[][o.s.a.SchedulerImpl] SonarQube is operational

访问sonarqube

默认用户名:admin

默认密码:admin

插件安装路径

ls -l /usr/local/sonarqube/extensions/plugins/
total 76
-rw-r--r-- 1 sonarqube sonarqube   737 Feb  3 11:19 README.txt
-rw-r--r-- 1 sonarqube sonarqube 70457 Mar  1 16:22 sonar-l10n-zh-plugin-9.9.jar

参考文档

https://docs.sonarqube.org/latest/

标签:ubuntu20.04,java,--,sonarqube,add,9.9,sonar,data
From: https://www.cnblogs.com/wangguishe/p/17165195.html

相关文章