sonar的配置安裝
一 Sonar 概述
Sonar 是一個用於程式碼質量管理的開放平臺。通過外掛機制,Sonar 可以整合不同的測試工具,程式碼分析工具,以及持續整合工具。
與持續整合工具(例如 Hudson/Jenkins 等)不同,Sonar 並不是簡單地把不同的程式碼檢查工具結果(例如 FindBugs,PMD 等)直接顯示在 Web 頁面上,而是通過不同的外掛對這些結果進行再加工處理,通過量化的方式度量程式碼質量的變化,從而可以方便地對不同規模和種類的工程進行程式碼質量管理。
在對其他工具的支援方面,Sonar 不僅提供了對 IDE 的支援,可以在 Eclipse 和 IntelliJ IDEA 這些工具裡聯機檢視結果;同時 Sonar 還對大量的持續整合工具提供了介面支援,可以很方便地在持續整合中使用 Sonar。
此外,Sonar 的外掛還可以對 Java 以外的其他程式語言提供支援,對國際化以及報告文件化也有良好的支援。
二 Sonar 的安裝
Sonar的相關下載和文件可以在下面的連結中找到:http://www.sonarqube.org/downloads/。需要注意最新版的Sonar需要至少JDK 1.8
及以上版本。
上篇文章我們已經可以成功的使用Git進行拉去,Sonar的功能就是來檢查程式碼是否有BUG。除了檢查程式碼是否有bug還有其他的功能,比如說:你的程式碼註釋率是多少,程式碼有一些建議,編寫語法的建議。所以我們叫質量管理
Sonar還可以給程式碼打分,並且引用了技術宅的功能(告訴你有很多地方沒改)
Sonar 是 Codehaus 上面的一個開源專案,使用的是 LGPL V3 軟體許可。我們可以在其官方網站上下載其原始碼及安裝包。
其原始碼需要使用分散式版本控制軟體 Git 進行檢出(Check Out),命令列方式如下:
git clone git://github.com/SonarSource/sonar.git
基礎環境安裝
1
2
3
4
5
6
7
8
|
[root@linux-node1 ~] # yum install -y java-1.8.0
[root@linux-node1 ~] # cd /usr/local/src
軟體包我們通過wget或者下載,rz上傳到伺服器 #軟體包下載:https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-5.6.zip [root@linux-node1 src] # unzip sonarqube-5.6.zip
[root@linux-node1 src] # mv sonarqube-5.6 /usr/local/
[root@linux-node1 src] # ln -s /usr/local/sonarqube-5.6/ /usr/local/sonarqube
|
資料庫安裝配置
Sonar 預設使用的是 Derby 資料庫,但這個資料庫一般用於評估版本或者測試用途。商用及對資料庫要求較高時,建議使用其他資料庫。Sonar 可以支援大多數主流關係型資料庫(例如 Microsoft SQL Server, MySQL, Oracle, PostgreSQL 等)
本文以 mariadb 為例說明如何更改 Sonar 的資料庫設定:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
yum install -y mariadb mariadb-server
[root@salt-node2 ~] # systemctl enable mariadb
[root@salt-node2 ~] # systemctl start mariadb
[root@salt-node2 ~] # mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we`ll need the current password for the root user. If you`ve just installed MariaDB, and
you haven`t set the root password yet, the password will be blank,
so you should just press enter here. Enter current password for root (enter for none):
ERROR 1045 (28000): Access denied for user `root` @ `localhost` (using password: YES)
Enter current password for root (enter for none):
OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y /n ] y
New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users ? [Y /n ] y
... Success!
Normally, root should only be allowed to connect from `localhost` . This
ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y /n ] y
... Success!
By default, MariaDB comes with a database named `test` that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment. Remove test database and access to it? [Y /n ] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y /n ] y
... Success!
Cleaning up... All done ! If you`ve completed all of the above steps, your MariaDB
installation should now be secure. Thanks for using MariaDB!
[root@salt-node2 ~] # mysql -uroot -p
Enter password: Welcome to the MariaDB monitor. Commands end with ; or g. Your MariaDB connection id is 18
Server version: 5.5.52-MariaDB MariaDB Server Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type `help;` or `h` for help. Type `c` to clear the current input statement.
MariaDB [(none)]> |
配置資料庫
1
2
3
4
5
6
7
8
9
10
11
|
MariaDB [(none)]> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci; Query OK, 1 row affected (0.02 sec) MariaDB [(none)]> GRANT ALL ON sonar.* TO `sonar` @ `localhost` IDENTIFIED BY `sonar@pw` ;
Query OK, 0 rows affected (0.01 sec) MariaDB [(none)]> GRANT ALL ON sonar.* TO `sonar` @ `%` IDENTIFIED BY `sonar@pw` ;
Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) |
配置Sonar配置檔案連結資料庫
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
[root@salt-node2 ~] # cd /usr/local/sonarqube/conf/
[root@salt-node2 /usr/local/sonarqube/conf ] # ls
sonar.properties wrapper.conf [root@salt-node2 /usr/local/sonarqube/conf ] # vim sonar.properties
# Property values can: # - reference an environment variable, for example sonar.jdbc.url= ${env:SONAR_JDBC_URL} # - be encrypted. See http://redirect.sonarsource.com/doc/settings-encryption.html #-------------------------------------------------------------------------------------------------- # 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. # 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@pw #----- 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 sonar.jdbc.url=jdbc:mysql: //localhost :3306 /sonar ?useUnicode= true &characterEncoding=utf8&rewriteBatchedStatements= true &useConfigs=maxPerformance
99 #sonar.web.host=0.0.0.0 配置監聽地址
106 #sonar.web.port=9000 配置監聽埠
|
配置Java訪問資料庫驅動(可選)
預設情況Sonar有自帶的嵌入的資料庫,那麼你如果使用類是Oracle資料庫,必須手動複製驅動類到${SONAR_HOME}/extensions/jdbc-driver/oracle/
目錄下,其它支援的資料庫預設提供了驅動。其它資料庫的配置可以參考官方文件:
http://docs.sonarqube.org/display/HOME/SonarQube+Platform
啟動sonar
1
|
<br>
|
相關文章
- sonar安裝c/c++外掛C++
- Mac下Sonar Swift的配置使用MacSwift
- sonar(二)掃描配置
- zabbix的安裝配置
- rsync的安裝配置
- HIVE的安裝配置Hive
- haproxy的配置安裝
- ASM的安裝配置ASM
- statspack的安裝配置
- JDK的安裝配置JDK
- 本地windows搭建spark環境,安裝與詳細配置(jdk安裝與配置,scala安裝與配置,hadoop安裝與配置,spark安裝與配置)WindowsSparkJDKHadoop
- centos7 (阿里雲、linux) 單機spark的安裝與配置詳解(jdk安裝與配置,scala安裝與配置,hadoop安裝與配置,spark安裝與配置)CentOS阿里LinuxSparkJDKHadoop
- Flutter的安裝和配置Flutter
- VNC的安裝配置使用VNC
- JDK的安裝和配置JDK
- Hive的安裝與配置Hive
- mongodb的安裝配置,使用MongoDB
- PG的安裝與配置
- yum的安裝與配置
- rsync的安裝 和 配置
- Barrier 的安裝和配置
- Redis的安裝與配置Redis
- Nginx的安裝配置使用Nginx
- Vue的安裝與配置Vue
- zabbix安裝—–nginx安裝和配置Nginx
- Zookeeper 安裝配置
- 【mongodb安裝配置】MongoDB
- ceph安裝配置
- ELK 安裝配置
- Prometheus安裝配置Prometheus
- MySQL安裝配置MySql
- SwitchOmega 安裝配置
- Hive安裝配置Hive
- JWT安裝配置JWT
- oracle安裝配置Oracle
- VNC安裝配置VNC
- rlwrap 安裝配置
- otrs安裝配置