`
sillycat
  • 浏览: 2489780 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Code SonarQube 2019(1)Installation with default H2

 
阅读更多
Code SonarQube 2019(1)Installation with default H2

We can find the downloads from here https://www.sonarqube.org/downloads/
And we can find scanner https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/

Source Codes
https://github.com/SonarSource/sonarqube
https://github.com/SonarSource/sonar-scanner-cli

Download the file from these versions
> wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-7.9.1.zip
> wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.0.0.1744.zip

Unzip and file and place to the working directories
> unzip sonarqube-7.9.1.zip
> mv sonarqube-7.9.1 ~/tool/

> unzip sonar-scanner-cli-4.0.0.1744.zip
> mv sonar-scanner-4.0.0.1744 ~/tool/

> sudo ln -s /home/carl/tool/sonarqube-7.9.1 /opt/sonarqube-7.9.1
> sudo ln -s /opt/sonarqube-7.9.1 /opt/sonarqube

> sudo ln -s /home/carl/tool/sonar-scanner-4.0.0.1744 /opt/sonar-scanner-4.0.0
> sudo ln -s /opt/sonar-scanner-4.0.0 /opt/sonar-scanner


Check Java version
> java -version
java version "1.8.0_171"

According to https://blog.51cto.com/dadapeng/1934568
Need Database MySQL
> sudo apt update
> sudo apt install mysql-server
> sudo apt install mysql-client

Default root User
https://stackoverflow.com/questions/33991228/what-is-the-default-root-pasword-for-mysql-5-7

Check the root password
> sudo cat /etc/mysql/debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH!
[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 -u debian-sys-maint -pddHulNSEFzhUFvS1

Prepare Database Information
> 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';

> FLUSH PRIVILEGES;

Then I can use this command to connect to that
> mysql -h localhost -u sonar -psonar

Configure sonarque configuration
> cd /opt/sonarqube

> vi conf/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


Add this to the ClassPath
export SONAR_HOME=/opt/sonarqube
export SONAR_RUNNER_HOME=/opt/sonar-scanner
export PATH="$PATH:$SONAR_HOME/bin:$SONAR_RUNNER_HOME/bin"

Start the Service
> bin/linux-x86-64/sonar.sh start

Check the logging and I get this error
WrapperSimpleApp: Encountered an error running main: java.lang.IllegalStateException: SonarQube requires Java 11+ to run
java.lang.IllegalStateException: SonarQube requires Java 11+ to run
        at org.sonar.application.App.checkJavaVersion(App.java:93)
        at org.sonar.application.App.start(App.java:56)
        at org.sonar.application.App.main(App.java:98)


Solutions:
http://www.jenv.be/

Install jENV on Ubuntu
> git clone https://github.com/gcuisinier/jenv.git ~/.jenv
> echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
> echo 'eval "$(jenv init -)"' >> ~/.bash_profile

> . ~/.bash_profile

Check installation
> jenv versions
* system (set by /home/carl/.jenv/version)

> jenv --version
jenv 0.5.2-4-gd8ffd5b

I manually install JDK8 so
>  jenv add /opt/jdk-1.8.0-171
oracle64-1.8.0.171 added
1.8.0.171 added
1.8 added

Download JDK 11 and JDK 12
https://www.oracle.com/technetwork/java/javase/downloads/jdk12-downloads-5295953.html

Then I get file
jdk-11.0.4_linux-x64_bin.tar.gz
jdk-12.0.2_linux-x64_bin.tar.gz

Put all these in the working directory
> sudo ln -s /home/carl/tool/jdk-11.0.4 /opt/jdk-11.0.4
> sudo ln -s /home/carl/tool/jdk-12.0.2 /opt/jdk-12.0.2

> jenv add /opt/jdk-11.0.4
> jenv add /opt/jdk-12.0.2

> jenv versions
* system (set by /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

> jenv global 11.0

Check java version
> java -version
java version "11.0.4" 2019-07-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.4+10-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.4+10-LTS, mixed mode)


Start Sonar again
> bin/linux-x86-64/sonar.sh start

Exception:
2019.07.22 13:08:01 WARN  app[][o.s.a.p.AbstractManagedProcess] Process exited with exit value [es]: 143

Solution:
https://stackoverflow.com/questions/49128166/sonarqube-exits-with-143
Move out all the plugins
> cd /opt/sonarqube
> mv plugins/* ~/install/plugins/

Then it is working fine now
>  bin/linux-x86-64/sonar.sh status
SonarQube is running (30432)

After few seconds, it stoped again…..
https://community.sonarsource.com/t/installing-sq-7-9-on-ubuntu-14-04-exit-value-es-143/11478

Cleaned the data and logs directories, still not working.
Does this matters in es.log
2019.07.22 14:53:42 DEBUG es[][i.n.u.i.CleanerJava9] java.nio.ByteBuffer.cleaner(): unavailable
java.lang.UnsupportedOperationException: sun.misc.Unsafe unavailable
        at io.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

> sudo sysctl -p
vm.max_map_count = 262144
net.ipv4.ip_nonlocal_bind = 1

Try one older version
> wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-7.6.zip
> sudo ln -s /home/carl/tool/sonarqube-7.6 /opt/sonarqube-7.6
> sudo ln -s /opt/sonarqube-7.6 /opt/sonarqube

> vi conf/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

It seems that it has something to do with the MySQL drivers. If I use default database setting H2 I guess, it will work.
Check document from here
https://docs.sonarqube.org/7.9/requirements/requirements/
https://docs.sonarqube.org/6.7/Requirements.html

It seems old version support MySQL, new version does not.
After all these, we can visit the page here
http://ubuntu-master:9000/about

We can login with default username and password admin/admin

After I create a sample JAVA project there, it asked me to run the maven command
> mvn sonar:sonar -Dsonar.projectKey=sillycat-websocket -Dsonar.host.url=http://ubuntu-master:9000 -Dsonar.login=adf305363a2cec4fa4311ea89317229ddd691991

It will scan and get a feeling about my JAVA codes.

Try the sample project
https://github.com/luohuazju/sillycat-jwtphp

For PHP project, we can have something similar
> sonar-scanner -Dsonar.projectKey=sillycat-jwtphp -Dsonar.sources=.   -Dsonar.host.url=http://ubuntu-master:9000 -Dsonar.login=8118a943f3eb997399ecd9ad0891c3c7f46f8e21


On Mac OS, we can install the scanner as well.
> wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.0.0.1744.zip

Unzip and place that in the working directory
> mv sonar-scanner-4.0.0.1744 ~/tool/

> sudo ln -s /Users/hluo/tool/sonar-scanner-4.0.0.1744 /opt/sonar-scanner-4.0.0
> sudo ln -s /opt/sonar-scanner-4.0.0 /opt/sonar-scanner

Add to the path
export PATH=/opt/sonar-scanner/bin:$PATH

Check installation
> sonar-scanner --version
INFO: Scanner configuration file: /Users/hluo/tool/sonar-scanner-4.0.0.1744/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarQube Scanner 4.0.0.1744
INFO: Java 1.8.0_161 Oracle Corporation (64-bit)
INFO: Mac OS X 10.14.5 x86_64

Same command, works pretty well.

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




分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics