SonarQubeをインストール

  • 久しぶりにSonarQubeをインストールしようと思ったらいろいろ忘れていてハマりました。
    • 特に公式ドキュメントにDBのつくりかたちゃんと書いてないし・・・

Installing the Server - SonarQube Documentation - SonarQube

DB作成

postgres=# CREATE USER sonarqube WITH PASSWORD 'sonarqube';
CREATE ROLE

postgres=# ALTER ROLE sonarqube CREATEDB;
ALTER ROLE

postgres=# CREATE DATABASE sonar WITH ENCODING 'UTF-8' OWNER=sonarqube;
CREATE DATABASE

postgres=# grant all privileges on database sonar to sonarqube;
GRANT

postgres=# \du
                             List of roles
 Role name |                   Attributes                   | Member of
-----------+------------------------------------------------+-----------
 postgres  | Superuser, Create role, Create DB, Replication | {}
 sonarqube | Create DB                                      | {}

postgres=# \l
                                   List of databases
   Name    |   Owner   | Encoding |   Collate   |    Ctype    |    Access privileges
-----------+-----------+----------+-------------+-------------+-------------------------
 postgres  | postgres  | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 |
 sonar     | sonarqube | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =Tc/sonarqube          +
           |           |          |             |             | sonarqube=CTc/sonarqube
 template0 | postgres  | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres            +
           |           |          |             |             | postgres=CTc/postgres
 template1 | postgres  | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres            +
           |           |          |             |             | postgres=CTc/postgres
(4 rows)
  • このままだとサーチパスが想定と違うので以下のようなエラーになります。
org.jruby.rack.RackInitializationException: ActiveRecord::JDBCError: ERROR: no schema has been selected to create in: CREATE TABLE "schema_migrations" ("version" varchar(10485760) NOT NULL) 
  • なのでサーチパスの設定をします。

kashi.way-nifty.com

postgres=# ALTER USER sonarqube SET search_path to public;
ALTER ROLE

モジュールのインストール

  • いつの間にかLTSができていたのでちょっと古いけどLTSにしました。
$ cd /usr/local/src
$ wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-4.5.6.zip
$ cd ..
$ unzip src/sonarqube-4.5.6.zip
$ ln -s sonarqube-4.5.6 sonar

設定

  • DBの設定
$ cd sonar/conf
$ vi sonar.properties

#sonar.jdbc.username=sonar
#sonar.jdbc.password=sonarsonar.jdbc.username=sonarqube
sonar.jdbc.password=sonarqube

#----- PostgreSQL 8.x/9.x
#sonar.jdbc.url=jdbc:postgresql://localhost/sonarsonar.jdbc.url=jdbc:postgresql://localhost/sonar
$ vi conf/sonar.properties

#---------------------------------------------------------
# LDAP Plugin
#---------------------------------------------------------

# his property must be defined to ask the Sonar server to use first the LDAP plugin when trying to authenticate a user.
sonar.security.realm=LDAP
# URL of the LDAP server. Note that if you are using ldaps, then you should install server certificate into java truststore.
ldap.url=ldap://ldap.example.com:389
# Bind DN is the username of an LDAP user to connect (or bind) with. Leave blank for anonymous access to the LDAP directory.
ldap.bindDn=cn=user,dc=ldap,dc=example,dc=com
# Bind Password is the password of the user to connect with. Leave blank for anonymous access to the LDAP directory.
ldap.bindPassword=xxxxxxxxxxx

# Distinguished Name (DN) of the root node in LDAP from which to search for users.
ldap.user.baseDn=ou=Users,dc=ldap,dc=example,dc=com
# Attribute in LDAP holding the user’s real name.
ldap.user.realNameAttribute=displayName
  • Proxyの設定
    • 上のLDAPプラグインを入れようとすると、プラグインのダウンロードに失敗する
    • 普通に設定しようとするとエラーが出るのでstackoverflowを参考に設定する

stackoverflow.com

Fail to download the plugin (csharp, version 5.0) from https://sonarsource.bintray.com/Distribution/sonar-csharp-plugin/sonar-csharp-plugin-5.0.jar (error is : Fail to download: https://sonarsource.bintray.com/Distribution/sonar-csharp-plugin/sonar-csharp-plugin-5.0.jar (no proxy))


↓だめ
https.proxyHost=proxy.example.com
https.proxyPort=8080

OK
sonar.web.javaAdditionalOpts=-Dhttps.proxyHost=proxy.example.com -Dhttps.proxyPort=8080

これで動いた