日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

SonarQube代码质量管理工具的安装(Linux)

發(fā)布時間:2025/3/17 linux 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SonarQube代码质量管理工具的安装(Linux) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

一、安裝配置sonar

1、Sonar介紹

Sonar是一個用于代碼質(zhì)量管理的開源平臺,用于管理Java源代碼的質(zhì)量。通過插件機制,Sonar 可以集成不同的測試工具,代碼分析工具,以及持續(xù)集成工具,比如pmd-cpd、checkstyle、findbugs、Jenkins。通過不同的插件對這些結(jié)果進行再加工處理,通過量化的方式度量代碼質(zhì)量的變化,從而可以方便地對不同規(guī)模和種類的工程進行代碼質(zhì)量管理。

同時 Sonar 還對大量的持續(xù)集成工具提供了接口支持,可以很方便地在持續(xù)集成中使用 Sonar。

此外,Sonar 的插件還可以對 Java 以外的其他編程語言提供支持,對國際化以及報告文檔化也有良好的支持。

注意:安裝sonar前, 請確保安裝好了jdk和MySQL,jdk版本為7.0+,mysql為5.6+,sonar為5.6.6

2、配置數(shù)據(jù)庫

Apache Derby 是Sonar自帶并且默認安裝使用的數(shù)據(jù)庫,此外Sonar對如下數(shù)據(jù)庫提供支持:MySQL 5.x, Oracle 10g XE, Postgresql, MS SqlServer等,本文以mysql為例介紹如何配置數(shù)據(jù)庫:

1) 配置mysql

結(jié)合 SonarQube, MySQL 數(shù)據(jù)庫最好使用 InnoDB 引擎, 可提高性能。 看你的 mysql 現(xiàn)在已提供什么存儲引擎:?
mysql> show engines;

看你的 mysql 當前默認的存儲引擎:?
mysql> show variables like ‘%storage_engine%’;

修改 MySQL 存儲引擎為 InnoDB, 在配置文件/etc/my.cnf 中加入 default-storage-engine=INNODB,?
重啟 mysql 服務(wù)器 # service mysqld restart, 再次登錄 MySQL 查看默認引擎設(shè)置是否生效?
mysql> show variables like ‘%storage_engine%’;

innodb_buffer_pool_size 參數(shù)值設(shè)置得盡可能大一點,這個參數(shù)主要作用是緩存 innodb 表的索引,數(shù)據(jù),插入數(shù)據(jù)時的緩沖默認值: 128M, 專用 mysql 服務(wù)器設(shè)置的大小:操作系統(tǒng)內(nèi)存的 70%-80%最佳。

設(shè)置方法: my.cnf 文件[mysqld] 下面加入innodb_buffer_pool_size 參數(shù) innodb_buffer_pool_size = 256M( 我們這里設(shè)置為 256M, 因為我們的不是專用的 MySQL 數(shù)據(jù)庫服務(wù)器,還有很多其他的服務(wù)需要占用系統(tǒng)內(nèi)存)?
設(shè)置 MySQL 的查詢緩存 query_cache_size ,最少設(shè)置 15M, query_cache_type=1?
query_cache_size=32M?
重啟 mysql 服務(wù)器 service mysqld restart?
驗證緩存設(shè)置是否生效:?
mysql> show variables like ‘%query_cache%’;

2)創(chuàng)建數(shù)據(jù)庫

在mysql中執(zhí)行如下腳本創(chuàng)建數(shù)據(jù)庫及mysql用戶

CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;

CREATE USER ‘sonar’ IDENTIFIED BY ‘sonar’;?
GRANT ALL ON sonar.* TO ‘sonar’@’%’ IDENTIFIED BY ‘sonar’;?
GRANT ALL ON sonar.* TO ‘sonar’@’localhost’ IDENTIFIED BY ‘sonar’;

3)配置數(shù)據(jù)庫

編輯${SONAR_HOME}/conf/sonar.properties:

sonar.jdbc.username: sonar?
sonar.jdbc.password: sonar?
sonar.jdbc.url: jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true # Optional properties sonar.jdbc.driverClassName: com.mysql.jdbc.Driver

3、安裝Sonar

解壓安裝:?
unzip sonarqube-4.5.4.zip?
mv sonarqube-4.5.4 sonarqube

編輯 sonar 配置:?
cd sonarqube/conf/?
vi sonar.properties

sonar.jdbc.username=root?
sonar.jdbc.password=root?
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonarqube?useUnicode=true&characterE?
ncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance?
sonar.web.host=0.0.0.0?
sonar.web.context=/sonarqube?
sonar.web.port=9000

保存以上配置(注意,要看看默認的 9000 端口是否已被占用)?
防火墻中打開 9000 端口:?
vi /etc/sysconfig/iptables?
-A INPUT -m state –state NEW -m tcp -p tcp –dport 9000 -j ACCEPT?
重啟防火墻, 使端口配置生效?
service iptables restart?
啟動 SonarQube Web Server?
/root/sonarqube/bin/Linux-x86-64/sonar.sh start( 初次啟動會自動建表和做相應(yīng)的初始化)

瀏覽器中輸入:?http://10.21.0.187:9000/sonarqube/

ps:當啟動sonar服務(wù)時,elasticsearch不能通過root啟動時,解決如下:

解決方法1:

  • 如果是用root賬號啟動,會報以下錯誤

    Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root. at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:93) at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:144) at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:285) at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35) Refer to the log for complete error details.
  • 這是出于系統(tǒng)安全考慮設(shè)置的條件。由于ElasticSearch可以接收用戶輸入的腳本并且執(zhí)行,為了系統(tǒng)安全考慮,?
    建議創(chuàng)建一個單獨的用戶用來運行ElasticSearch

  • 創(chuàng)建elsearch用戶組及elsearch用戶

    groupadd elsearch useradd elsearch -g elsearch -p elasticsearch
  • 更改elasticsearch文件夾及內(nèi)部文件的所屬用戶及組為elsearch:elsearch

    cd /opt chown -R elsearch:elsearch elasticsearch
  • 切換到elsearch用戶再啟動

    su elsearch cd elasticsearch/bin ./elasticsearch
  • 啟動后打印信息如下

    [2015-12-30 10:15:44,876][WARN ][bootstrap ] unable to install syscall filter: prctl(PR_GET_NO_NEW_PRIVS): Invalid argument [2015-12-30 10:15:45,175][INFO ][node ] [Grim Hunter] version[2.1.1], pid[26383], build[40e2c53/2015-12-15T13:05:55Z] [2015-12-30 10:15:45,176][INFO ][node ] [Grim Hunter] initializing ... [2015-12-30 10:15:45,243][INFO ][plugins ] [Grim Hunter] loaded [], sites [] [2015-12-30 10:15:45,272][INFO ][env ] [Grim Hunter] using [1] data paths, mounts [[/ (/dev/mapper/vg_yong-lv_root)]], net usable_space [33.3gb], net total_space [49gb], spins? [no], types [ext4] [2015-12-30 10:15:47,318][INFO ][node ] [Grim Hunter] initialized [2015-12-30 10:15:47,318][INFO ][node ] [Grim Hunter] starting ... [2015-12-30 10:15:47,388][INFO ][discovery ] [Grim Hunter] elasticsearch/fnXUCLOQQBiC1aR7hhB82Q [2015-12-30 10:15:50,442][INFO ][cluster.service ] [Grim Hunter] new_master {Grim Hunter}{fnXUCLOQQBiC1aR7hhB82Q}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-join(elected_as_master, [0] joins received) [2015-12-30 10:15:50,491][INFO ][node ] [Grim Hunter] started [2015-12-30 10:15:50,526][INFO ][gateway ] [Grim Hunter] recovered [0] indices into cluster_state
ElasticSearch后端啟動命令
./elasticsearch -d

解決方法2:

在執(zhí)行elasticSearch時加上參數(shù)-Des.insecure.allow.root=true,完整命令如下?

  • ./elasticsearch?-Des.insecure.allow.root=true??
  • 解決辦法3:

    用vi打開elasicsearch執(zhí)行文件,在變量ES_JAVA_OPTS使用前添加以下命令?

  • ES_JAVA_OPTS="-Des.insecure.allow.root=true"??
  • 如下圖所示,這個方法的好處是以后不用添加參數(shù)就能以root身份執(zhí)行了
    ps:方法二、三只對elesticSearch2.x有效

    轉(zhuǎn)載于:https://www.cnblogs.com/dengshihuang/p/8032371.html

    總結(jié)

    以上是生活随笔為你收集整理的SonarQube代码质量管理工具的安装(Linux)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。