sonar安装

 

 

##jdk不要用yum下载的

一、下载sonar源码

cd /usr/local/src
wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-6.7.4.zip

unzip sonarqube-6.7.4.zip

mv
sonarqube-6.7.4 /usr/local/sonarqube


 

二、创建数据库及账号密码

CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
grant all privileges on sonar.* to 'sonar'@'%' identified by 'sonar';
GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
flush privileges;

 

三、修改sonar配置文件

[root@izm5ecjazswrig6et6loj1z ~]# egrep   "^[a-z]"  /usr/local/sonarqube/conf/sonar.properties 

sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false

sonar.web.host
=0.0.0.0 sonar.web.context=/ sonar.web.port=9000

 

 

 

四、创建sonar用户并以sonar用户启动

useradd sonar
su -c   '/usr/local/sonarqube/bin/linux-x86-64/sonar.sh start'  sonar

 

五、错误解决(logs/sonar.log日志内容)

WrapperSimpleApp: Encountered an error running main: java.nio.file.AccessDeniedException: /opt/sonarqube-6.7.4/temp/conf/es/elasticsearch.yml
java.nio.file.AccessDeniedException: /opt/sonarqube-6.7.4/temp/conf/es/elasticsearch.yml
    at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
    at sun.nio.fs.UnixFileSystemProvider.implDelete(UnixFileSystemProvider.java:244)
    at sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:103)
    at java.nio.file.Files.delete(Files.java:1126)
    at org.sonar.process.FileUtils2$DeleteRecursivelyFileVisitor.visitFile(FileUtils2.java:170)
    at org.sonar.process.FileUtils2$DeleteRecursivelyFileVisitor.visitFile(FileUtils2.java:165)
    at java.nio.file.Files.walkFileTree(Files.java:2670)
    at java.nio.file.Files.walkFileTree(Files.java:2742)
    at org.sonar.process.FileUtils2.deleteDirectoryImpl(FileUtils2.java:127)
    at org.sonar.process.FileUtils2.deleteDirectory(FileUtils2.java:112)
    at org.sonar.application.AppFileSystem$CleanTempDirFileVisitor.visitFile(AppFileSystem.java:117)
    at org.sonar.application.AppFileSystem$CleanTempDirFileVisitor.visitFile(AppFileSystem.java:101)
    at java.nio.file.Files.walkFileTree(Files.java:2670)
    at org.sonar.application.AppFileSystem.createOrCleanTempDirectory(AppFileSystem.java:96)
    at org.sonar.application.AppFileSystem.reset(AppFileSystem.java:62)
    at org.sonar.application.App.start(App.java:55)
    at org.sonar.application.App.main(App.java:78)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.tanukisoftware.wrapper.WrapperSimpleApp.run(WrapperSimpleApp.java:240)
    at java.lang.Thread.run(Thread.java:748)
<-- Wrapper Stopped

 

###解决

删除/usr/local/sonarqube/temp目录

删除temp目录

rm -rf /usr/local/sonarqube/temp

###然后再启动

  

六、查看9000端口并在浏览器访问

 

[root@izm5ecjazswrig6et6loj1z ~]# ss -luntp|grep 9000
tcp    LISTEN     0      25        *:9000                  *:*                   users:(("java",pid=16863,fd=116))

  

 

七、中文插件安装

sonar版本对应的中文插件版本

###github地址 https://github.com/SonarQubeCommunity/sonar-l10n-zh/tags

wget https://github.com/SonarQubeCommunity/sonar-l10n-zh/releases/download/sonar-l10n-zh-plugin-1.19/sonar-l10n-zh-plugin-.19.jar

mv sonar-l10n-zh-plugin-1.19.jar  /usr/local/sonarqube/extensions/plugins/

  

##重启sonar

 

8、下载sonar-sonarner(我下载了一个wordpress进行测试)

wget https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.2.0.1227.zip
unzip sonar-scanner-cli-3.2.0.1227.zip 
mv sonar-scanner-3.2.0.1227 /usr/local/sonar-scanner
 cd /usr/local/sonar-scanner
 cd conf/

[root@localhostPython]egrep -v "^#|^$" m /usr/local/sonar-scanner/conf/sonar-scanner.properties


sonar.host.url=http://localhost:9000

sonar.sourceEncoding=UTF-8      
sonar.projectKey=csgias-key    ##自定义的key
sonar.projectName=csgias       ##自定义项目名字
sonar.projectVersion=1.0        #版本
sonar.sources=/root/wordpress/php   ###代码目录

sonar.java.binaries=/root/wordpress/php  ####java需要制定这个

 

9.##执行命令

/usr/local/sonar-scanner/bin/sonar-scanner

  

查看sonar的web页面

###修改了代码后测试

 

####命令行形式扫描代码

 

/usr/local/sonar-scanner/bin/sonar-scanner -Dsonar.projectKey=test-key -D sonar.projectName=test -Dsonar.projectVersio=1.0 -Dsonar.sources=/root/ruby-2.4.4

 

 

posted @ 2018-07-09 15:34  巽逸  阅读(537)  评论(0编辑  收藏  举报