說明:sonar依賴數據庫.html
mysql優化java
一、筆者使用的是mysql數據庫.首先對mysql作簡單的優化配置.mysql
[root@localhost bin]# cat /etc/my.cnf [mysqld] max_allowed_packet=10M datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # 修改默認的編碼爲utf8 default-character-set=utf8 # 修改默認的存儲引擎爲InnoDB default-storage-engine=InnoDB # 這個參數主要做用是緩存innodb表的索引,數據,插入數據時的緩衝 innodb_buffer_pool_size = 256M # 配置查詢緩存的大小 query_cache_size=128M # 啓動mysql高速緩存 query_cache_type=1 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
二、重啓mysql服務
[root@localhost bin]# service mysqld restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
sonar安裝和部署linux
一、sonar部署nginx
[root@localhost local]# pwd
/usr/local [root@localhost local]# unzip sonarqube-4.5.4.zip
修改sonar配置文件
[root@localhost conf]# pwd
/usr/local/sonarqube-4.5.4/conf [root@localhost conf]# vim sonar.properties sonar.jdbc.username=root sonar.jdbc.password=123456 sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
sonar.web.javaOpts=-Xmx768m -XX:MaxPermSize=160m -XX:+HeapDumpOnOutOfMemoryError sonar.web.host=0.0.0.0 sonar.web.port=9000
建立sonar數據庫依賴web
create database sonar default character set utf8;
二、利用nginx反響代理sql
upstream配置數據庫
upstream tomcat_tools.sonar.local { server 127.0.0.1:9000 weight=10 max_fails=2 fail_timeout=300s; } server { listen 80; server_name tools.sonar.local.com; root /usr/local/sonarqube-4.5.4/web/; access_log /usr/local/sonarqube-4.5.4/logs/tools.sonar.local.com_access.log main; error_log /usr/local/sonarqube-4.5.4/logs/tools.sonar.local.com_error.log warn; error_page 403 404 /40x.html; location / { index index.html index.htm; proxy_next_upstream http_500 http_502 http_503 http_504 error timeout invalid_header; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://tomcat_tools.sonar.local;
expires 0d; } }
增減配置完成後,重啓nginx
[root@localhost domains]# service nginx restart
三、修改防火牆開放9000端口vim
-A INPUT -m state --state NEW -m tcp -p tcp --dport 9000 -j ACCEPT
四、啓動sonar緩存
[root@localhost linux-x86-64]# pwd
/usr/local/sonarqube-4.5.4/bin/linux-x86-64 [root@localhost linux-x86-64]# ls lib sonar.sh wrapper [root@localhost linux-x86-64]# ./sonar.sh start Starting SonarQube... Started SonarQube.
五、訪問tools.sonar.local.com
六、登陸sonar[默認帳號admin/admin]安裝漢化包
Settings/SYSTEM/Update Center/Available Plugins
選擇漢化包,漢化完成以後須要從新啓動.
項目代碼提交sonar檢測代碼質量
一、在maven本地倉庫的settings.xml中 <profiles>節點之間增長以下內容
<profiles>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.jdbc.url> jdbc:mysql://192.168.147.129:3306/sonar?useUnicode=true&characterEncoding=utf8
</sonar.jdbc.url>
<sonar.jdbc.driver>com.mysql.jdbc.Driver</sonar.jdbc.driver>
<sonar.jdbc.username>root</sonar.jdbc.username>
<sonar.jdbc.password>123456</sonar.jdbc.password>
<sonar.host.url>http://tools.sonar.local.com</sonar.host.url>
</properties>
</profile>
</profiles>
或者直接在應用項目的總pom中增長如上內容.區別是前者爲全部項目增長,後者只是針對單個項目配置.
二、建立mvn命令

三、執行命令,查看sonar控制面板的項目

如圖,爲剛纔的項目接入到sonar檢測上的狀況.點擊查看該代碼的質量狀況.
轉載請註明出處:[http://www.cnblogs.com/dennisit/p/4546245.html]