2

我正在尝试第一次针对我们的 repo 运行 sonar-runner ...

我有:

  1. 安装 Sonar 3.2 并安装在 /opt/sonar
  2. 在 /opt/sonar-runner-2.0/ 中安装并配置了 sonar-runner
  3. 安装PHP扩展插件并放入/opt/sonar/extensions/plugins/sonar-php-plugin-1.1.jar

我的 sonar.properties 文件具有以下属性:

   sonar.jdbc.username:                       sonar
   sonar.jdbc.password:                       sonar
   sonar.jdbc.url:                            jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true
   sonar.jdbc.driverClassName:                com.mysql.jdbc.Driver

尽管用户/密码设置为 sonar/sonar,但 sonar-runner 仍在尝试以 root@localhost 身份连接...请参见下面的跟踪:

Caused by: java.lang.IllegalStateException: Fail to connect to database
    at org.sonar.core.persistence.DefaultDatabase.start(DefaultDatabase.java:66)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.invokeMethod(ReflectionLifecycleStrategy.java:110)
    ... 20 more
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password: YES))
    at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
    at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
    at org.apache.commons.dbcp.BasicDataSource.getLogWriter(BasicDataSource.java:1098)
    at org.apache.commons.dbcp.BasicDataSourceFactory.createDataSource(BasicDataSourceFactory.java:350)
    at org.sonar.core.persistence.DefaultDatabase.initDatasource(DefaultDatabase.java:117)
    at org.sonar.core.persistence.DefaultDatabase.start(DefaultDatabase.java:62)
    ... 25 more
Caused by: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:943)
    at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4113)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1308)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2336)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2369)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
    at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
    at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
    at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
    at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
    ... 30 more

更改配置后,我重新启动了声纳服务器...

是否可以使用空/空白密码?如果我注释掉sonar.jdbc.password,声纳 GUI 将抛出 500 状态码。如果我sonar.jdbc.password留空/空白,那么它仍然会尝试使用密码进行连接:'root'@'localhost' (using password: YES)!!

非常感谢

4

1 回答 1

3

堆栈跟踪详细说明了错误:

Caused by: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

看起来配置与您的错误不匹配。您是否尝试将 Sonar 配置为使用 root 用户?

我怀疑您的问题与 mySQL 用户访问有关。您是否尝试以“声纳”用户身份连接到数据库?

更新

Sonar runner不使用与 Sonar 服务器相同的配置文件。在以下位置查找文件:

$SONAR_RUNNER_HOME/conf/sonar-runner.properties
于 2012-09-24T22:02:27.397 回答