sonarqube 安裝使用

Prerequisite

# download jre11 rpm package
# install jre11 rpm
rpm -i jdk-11.0.5_linux-x64_bin.rpm
  • Linux installation prerequisite
# If you're running on Linux, you must ensure that:

* vm.max_map_count is greater or equals to 262144
* fs.file-max is greater or equals to 65536
* the user running SonarQube can open at least 65536 file descriptors
* the user running SonarQube can open at least 4096 threads

# You can see the values with the following commands:
sysctl vm.max_map_count
sysctl fs.file-max
ulimit -n
ulimit -u

# You can set them dynamically for the current session by running the following commands as root:
sysctl -w vm.max_map_count=262144
sysctl -w fs.file-max=65536
ulimit -n 65536
ulimit -u 4096

# To set these values more permanently, you must update either /etc/sysctl.d/99-sonarqube.conf (or /etc/sysctl.conf as you wish) to reflect these values.
# Install the repository RPM
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# Install the client packages:
yum install postgresql11

# Optionally install the server packages:
yum install postgresql11-server

# Optionally initialize the database and enable automatic start:

/usr/pgsql-11/bin/postgresql-11-setup initdb
systemctl enable postgresql-11\
systemctl start postgresql-11

# PostgreSQL會自動創(chuàng)建postgres用戶, 創(chuàng)建數(shù)據(jù)庫之前, 要用postgres用戶或root用戶登錄并重置postgres用戶密碼.
su -l postgres

# 連接數(shù)據(jù)庫, psql命令會激活PostgreSQL數(shù)據(jù)庫終端:
psql

# 會輸出下列說明連接進入了PostgreSQL數(shù)據(jù)庫:
-bash-4.2$ psql
psql (11.5)
Type "help" for help.
postgres=# help
You are using psql, the command-line interface to PostgreSQL.
Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

# 重置postgres用戶密碼:
postgres=# \password

# 開啟遠程訪問
    vim /var/lib/pgsql/11/data/postgresql.conf
    修改#listen_addresses = 'localhost'  為  listen_addresses=‘*'

# 信任遠程連接
    vim /var/lib/pgsql/11/data/pg_hba.conf
    修改如下內(nèi)容,信任指定服務(wù)器連接

    # IPv4 local connections:
    host    all            all      127.0.0.1/32      trust
    host    all            all      10.xx.xx.6/32(需要連接的服務(wù)器IP)  trust

# 重啟數(shù)據(jù)庫生效
systemctl restart postgresql-11

# 創(chuàng)建新用戶
CREATE USER sonarqube  WITH PASSWORD 'Wood!nHo13';

# 創(chuàng)建數(shù)據(jù)庫
CREATE SCHEMA sonar_schema;
ALTER USER sonarqube SET search_path to sonarqube;
CREATE DATABASE sonarqube OWNER sonarqube;
GRANT ALL PRIVILEGES ON DATABASE sonarqube to sonarqube;
DROP DATABASE sonarqube;

PostgreSQL 設(shè)置
if you want to use a custom schema and not the default "public" one, the PostgreSQL search_path property must be set:

ALTER USER sonarqube SET search_path to sonarqube;

Installing the Web Server

  • download from here

SonarQube cannot be run as root on Unix-based systems, so create a dedicated user account to use for SonarQube if necessary.

useradd sonar
  • Setting the Access to the Database

$SONARQUBE-HOME (below) refers to the path to the directory where the SonarQube distribution has been unzipped.

Edit $SONARQUBE-HOME/conf/sonar.properties to configure the database settings.

Templates are available for every supported database. Just uncomment and configure the template you need and comment out the lines dedicated to H2:

Example for PostgreSQL

sonar.jdbc.username=sonarqube
sonar.jdbc.password=mypassword
sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube
  • Adding the JDBC Driver

Drivers for the supported databases (except Oracle) are already provided. Do not replace the provided drivers; they are the only ones supported.

  • Configuring the Elasticsearch storage path

By default, Elasticsearch data is stored in $SONARQUBE-HOME/data, but this is not recommended for production instances. Instead, you should store this data elsewhere, ideally in a dedicated volume with fast I/O. Beyond maintaining acceptable performance, doing so will also ease the upgrade of SonarQube.

Edit$SONARQUBE-HOME/conf/sonar.properties to configure the following settings:

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

The user used to launch SonarQube must have read and write access to those directories.

chown sonarqube:sonarqube /var/sonarqube/data
chown sonarqube:sonarqube /var/sonarqube/temp
  • SonarQube中文界面

下載中文語言包 sonar-l10n-zh-plugin.jar
然后,將其放入sonar安裝目錄的 extensions/plugins 目錄下
https://search.maven.org/search?q=sonar-l10n-zh-plugin

Starting the Web Server

The default port is "9000" and the context path is "/". These values can be changed in $SONARQUBE-HOME/conf/sonar.properties:

sonar.web.host=xxx.xxx.xxx.xxx
sonar.web.port=80
sonar.web.context=/sonarqube

Execute the following script to start the server:

bin//sonar.sh start

You can now browse SonarQube at http://localhost:9000 (the default System administrator credentials are admin/admin).

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容