1.安装mysql数据库 5.6以上版本(本人数据库版本5.7)
2.安装jdk1.8(本人jdk版本1.8)
https://www.sonarqube.org/downloads/
最新版本6.7稳定版
选择 Show all version 查看更多版本,我选择版本为:sonarqube-7.6,下载解压以mac环境为例:将解压后的文件夹拷贝到/usr/local 下。
cd sonarqube-6.5/conf/
vi 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&useSSL=false
vi wrapper.conf(java安装路径)
wrapper.java.command=/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/bin/java
cd /usr/local/sonarqube-6.5/bin
看到不同环境下不同的目录:根据自己的环境 (本人环境mac 所有 cd macosx-universal-64)
执行命令:
./sonar.sh start 启动
./sonar.sh status 状态
./sonar.sh stop 停止
./sonar.sh restart 重新启动
此处sonar7.6出现的错误:
在安装完sonar7.6启动的时候,报了这种错
org.sonar.server.platform.db.migration.step.MigrationStepExecutionException: Execution of migration step #2128 'Purge duplicate rules_parameters and their orphans' failed
at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:79)
at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:67)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.ReferencePipeline$Head.forEachOrdered(ReferencePipeline.java:590)
at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:52)
at org.sonar.server.platform.db.migration.engine.MigrationEngineImpl.execute(MigrationEngineImpl.java:50)
at org.sonar.server.platform.db.migration.DatabaseMigrationImpl.doUpgradeDb(DatabaseMigrationImpl.java:105)
at org.sonar.server.platform.db.migration.DatabaseMigrationImpl.doDatabaseMigration(DatabaseMigrationImpl.java:80)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLException: You can't specify target table 'p1' for update in FROM clause
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3976)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3912)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2486)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1197)
at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)
at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)
at org.sonar.server.platform.db.migration.step.UpsertImpl.execute(UpsertImpl.java:66)
at org.sonar.server.platform.db.migration.version.v72.PurgeDuplicateRulesParameters.execute(PurgeDuplicateRulesParameters.java:64)
at org.sonar.server.platform.db.migration.step.DataChange.execute(DataChange.java:44)
at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:75)
... 11 common frames omitted
这个问题是数据迁移失败,其中有一块数据有问题,因为是刚出来的版本,没有在论坛找到解决办法,最后在sonarqube社区论坛找到了这个错误的解决办法:
在数据库中手动插入不起作用的迁移。
insert into schema_migrations values (2128);
好了,重启一下sonar访问一下http://localhost:9000/sonar
账户密码默认的为admin,admin
查看日志:
cd /usr/local/sonarqube-6.5/logs 下查看相关启动日志。
打开浏览器访问 localhost:9000
1.官网下载扫描仪:https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner
下载成功后 : 解压 拷贝到 /usr/local 目录下
2.修改配置文件sonar-scanner.properties
#Configure here general information about the environment, such as SonarQube server connection details for example
#No information about specific project should appear here
#----- Default SonarQube server
sonar.host.url=http://localhost:9000
#----- Default source code encoding
sonar.sourceEncoding=UTF-8
sonar.login=admin
sonar.password=admin
sonar.scm.forceReloadAll=true
3.配置环境变量
export SONAR_HOME=/usr/local/sonarqube-7.6
export SONAR_RUNNER_HOME=/usr/local/sonar-scanner
export PATH=$PATH:$SONAR_RUNNER_HOME/bin
4.执行 sonar-scanner -v 查看版本
5.在待扫描项目根目录下创建sonar-project.properties
sonar.projectKey=test 项目key 一个项目一个key
sonar.projectName=pyxis_web 项目名称
sonar.projectVersion=0 版本
sonar.sources=js 要扫描待文件夹 ,可设置 . 都扫描
sonar.sourceEncoding=UTF-8 编码
6.执行名称 sonar-scanner 扫描完成 到web页面查看。。。