BORISHOU 2019-07-23
CodeSonarQube2019(1)InstallationwithdefaultH2
Wecanfindthedownloadsfromherehttps://www.sonarqube.org/downloads/
Andwecanfindscannerhttps://docs.sonarqube.org/latest/analysis/scan/sonarscanner/
SourceCodes
https://github.com/SonarSource/sonarqube
https://github.com/SonarSource/sonar-scanner-cli
Downloadthefilefromtheseversions
>wgethttps://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-7.9.1.zip
>wgethttps://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.0.0.1744.zip
Unzipandfileandplacetotheworkingdirectories
>unzipsonarqube-7.9.1.zip
>mvsonarqube-7.9.1~/tool/
>unzipsonar-scanner-cli-4.0.0.1744.zip
>mvsonar-scanner-4.0.0.1744~/tool/
>sudoln-s/home/carl/tool/sonarqube-7.9.1/opt/sonarqube-7.9.1
>sudoln-s/opt/sonarqube-7.9.1/opt/sonarqube
>sudoln-s/home/carl/tool/sonar-scanner-4.0.0.1744/opt/sonar-scanner-4.0.0
>sudoln-s/opt/sonar-scanner-4.0.0/opt/sonar-scanner
CheckJavaversion
>java-version
javaversion"1.8.0_171"
Accordingtohttps://blog.51cto.com/dadapeng/1934568
NeedDatabaseMySQL
>sudoaptupdate
>sudoaptinstallmysql-server
>sudoaptinstallmysql-client
DefaultrootUser
https://stackoverflow.com/questions/33991228/what-is-the-default-root-pasword-for-mysql-5-7
Checktherootpassword
>sudocat/etc/mysql/debian.cnf
#AutomaticallygeneratedforDebianscripts.DONOTTOUCH!
[client]
host=localhost
user=debian-sys-maint
password=ddHulNSEFzhUFvS1
socket=/var/run/mysqld/mysqld.sock
[mysql_upgrade]
host=localhost
user=debian-sys-maint
password=ddHulNSEFzhUFvS1
socket=/var/run/mysqld/mysqld.sock
>mysql-udebian-sys-maint-pddHulNSEFzhUFvS1
PrepareDatabaseInformation
>CREATEDATABASEsonarCHARACTERSETutf8COLLATEutf8_general_ci;
>CREATEUSER'sonar'IDENTIFIEDBY'sonar';
>GRANTALLONsonar.*TO'sonar'@'%'IDENTIFIEDBY'sonar';
>GRANTALLONsonar.*TO'sonar'@'localhost'IDENTIFIEDBY'sonar';
>FLUSHPRIVILEGES;
ThenIcanusethiscommandtoconnecttothat
>mysql-hlocalhost-usonar-psonar
Configuresonarqueconfiguration
>cd/opt/sonarqube
>viconf/sonar.properties
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.sorceEncoding=UTF-8
sonar.login=admin
sonar.password=admin
AddthistotheClassPath
exportSONAR_HOME=/opt/sonarqube
exportSONAR_RUNNER_HOME=/opt/sonar-scanner
exportPATH="$PATH:$SONAR_HOME/bin:$SONAR_RUNNER_HOME/bin"
StarttheService
>bin/linux-x86-64/sonar.shstart
ChecktheloggingandIgetthiserror
WrapperSimpleApp:Encounteredanerrorrunningmain:java.lang.IllegalStateException:SonarQuberequiresJava11+torun
java.lang.IllegalStateException:SonarQuberequiresJava11+torun
atorg.sonar.application.App.checkJavaVersion(App.java:93)
atorg.sonar.application.App.start(App.java:56)
atorg.sonar.application.App.main(App.java:98)
Solutions:
http://www.jenv.be/
InstalljENVonUbuntu
>gitclonehttps://github.com/gcuisinier/jenv.git~/.jenv
>echo'exportPATH="$HOME/.jenv/bin:$PATH"'>>~/.bash_profile
>echo'eval"$(jenvinit-)"'>>~/.bash_profile
>.~/.bash_profile
Checkinstallation
>jenvversions
*system(setby/home/carl/.jenv/version)
>jenv--version
jenv0.5.2-4-gd8ffd5b
ImanuallyinstallJDK8so
>jenvadd/opt/jdk-1.8.0-171
oracle64-1.8.0.171added
1.8.0.171added
1.8added
DownloadJDK11andJDK12
https://www.oracle.com/technetwork/java/javase/downloads/jdk12-downloads-5295953.html
ThenIgetfile
jdk-11.0.4_linux-x64_bin.tar.gz
jdk-12.0.2_linux-x64_bin.tar.gz
Putalltheseintheworkingdirectory
>sudoln-s/home/carl/tool/jdk-11.0.4/opt/jdk-11.0.4
>sudoln-s/home/carl/tool/jdk-12.0.2/opt/jdk-12.0.2
>jenvadd/opt/jdk-11.0.4
>jenvadd/opt/jdk-12.0.2
>jenvversions
*system(setby/home/carl/.jenv/version)
11.0
11.0.4
12.0
12.0.2
1.8
1.8.0.171
oracle64-11.0.4
oracle64-12.0.2
oracle64-1.8.0.171
>jenvglobal11.0
Checkjavaversion
>java-version
javaversion"11.0.4"2019-07-16LTS
Java(TM)SERuntimeEnvironment18.9(build11.0.4+10-LTS)
JavaHotSpot(TM)64-BitServerVM18.9(build11.0.4+10-LTS,mixedmode)
StartSonaragain
>bin/linux-x86-64/sonar.shstart
Exception:
2019.07.2213:08:01WARNapp[][o.s.a.p.AbstractManagedProcess]Processexitedwithexitvalue[es]:143
Solution:
https://stackoverflow.com/questions/49128166/sonarqube-exits-with-143
Moveoutalltheplugins
>cd/opt/sonarqube
>mvplugins/*~/install/plugins/
Thenitisworkingfinenow
>bin/linux-x86-64/sonar.shstatus
SonarQubeisrunning(30432)
Afterfewseconds,itstopedagain…..
https://community.sonarsource.com/t/installing-sq-7-9-on-ubuntu-14-04-exit-value-es-143/11478
Cleanedthedataandlogsdirectories,stillnotworking.
Doesthismattersines.log
2019.07.2214:53:42DEBUGes[][i.n.u.i.CleanerJava9]java.nio.ByteBuffer.cleaner():unavailable
java.lang.UnsupportedOperationException:sun.misc.Unsafeunavailable
atio.netty.util.internal.CleanerJava9.<clinit>(CleanerJava9.java:68)[netty-common-4.1.32.Final.jar:4.1
.32.Final]
https://blog.csdn.net/qq_35981283/article/details/81072852
>ulimit-Hn
65536
>sudosysctl-p
vm.max_map_count=262144
net.ipv4.ip_nonlocal_bind=1
Tryoneolderversion
>wgethttps://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-7.6.zip
>sudoln-s/home/carl/tool/sonarqube-7.6/opt/sonarqube-7.6
>sudoln-s/opt/sonarqube-7.6/opt/sonarqube
>viconf/sonar.properties
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.sorceEncoding=UTF-8
sonar.login=admin
sonar.password=admin
ItseemsthatithassomethingtodowiththeMySQLdrivers.IfIusedefaultdatabasesettingH2Iguess,itwillwork.
Checkdocumentfromhere
https://docs.sonarqube.org/7.9/requirements/requirements/
https://docs.sonarqube.org/6.7/Requirements.html
ItseemsoldversionsupportMySQL,newversiondoesnot.
Afterallthese,wecanvisitthepagehere
http://ubuntu-master:9000/about
Wecanloginwithdefaultusernameandpasswordadmin/admin
AfterIcreateasampleJAVAprojectthere,itaskedmetorunthemavencommand
>mvnsonar:sonar-Dsonar.projectKey=sillycat-websocket-Dsonar.host.url=http://ubuntu-master:9000-Dsonar.login=adf305363a2cec4fa4311ea89317229ddd691991
ItwillscanandgetafeelingaboutmyJAVAcodes.
Trythesampleproject
https://github.com/luohuazju/sillycat-jwtphp
ForPHPproject,wecanhavesomethingsimilar
>sonar-scanner-Dsonar.projectKey=sillycat-jwtphp-Dsonar.sources=.-Dsonar.host.url=http://ubuntu-master:9000-Dsonar.login=8118a943f3eb997399ecd9ad0891c3c7f46f8e21
OnMacOS,wecaninstallthescanneraswell.
>wgethttps://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.0.0.1744.zip
Unzipandplacethatintheworkingdirectory
>mvsonar-scanner-4.0.0.1744~/tool/
>sudoln-s/Users/hluo/tool/sonar-scanner-4.0.0.1744/opt/sonar-scanner-4.0.0
>sudoln-s/opt/sonar-scanner-4.0.0/opt/sonar-scanner
Addtothepath
exportPATH=/opt/sonar-scanner/bin:$PATH
Checkinstallation
>sonar-scanner--version
INFO:Scannerconfigurationfile:/Users/hluo/tool/sonar-scanner-4.0.0.1744/conf/sonar-scanner.properties
INFO:Projectrootconfigurationfile:NONE
INFO:SonarQubeScanner4.0.0.1744
INFO:Java1.8.0_161OracleCorporation(64-bit)
INFO:MacOSX10.14.5x86_64
Samecommand,worksprettywell.
References:
https://www.jianshu.com/p/50496b75a7b0
https://www.jianshu.com/p/9766f0129581
https://blog.csdn.net/zdyueguanyun/article/details/79447701
https://blog.51cto.com/dadapeng/1934568