I can believe fly.

Wednesday, February 15, 2017

搭建Sonar平台(MySQL + Tomcat6)

1. Install server

wget http://dist.sonar.codehaus.org/sonar-2.14.zip
unzip sonar-2.14.zip

2. Create database

如果要迁移到Mysql上,需首先创建一个sonar/sonar的UTF-8的mysql数据库,并授权访问sonar库
mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> grant all privileges on sonar.* to 'sonar'@'localhost' identified by 'sonar';
mysql> flush privileges;

3. Configure database

修改conf/sonar.properties中的数据库配置

禁用默认数据库derby
#sonar.jdbc.url: jdbc:derby://localhost:1527/sonar;create=true
#sonar.jdbc.driver: org.apache.derby.jdbc.ClientDriver
#sonar.jdbc.defaultTransactionIsolation: 1
#sonar.jdbc.validationQuery: values(1)
启用mysql数据库
sonar.jdbc.url: jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
sonar.jdbc.driver: com.mysql.jdbc.Driver
sonar.jdbc.validationQuery: select 1
sonar.jdbc.user: sonar
sonar.jdbc.password: sonar

4.tomcat部署

1. 部署到Tomcat   执行war目录里的build-war脚本生成war文件,将war文件部署到应用服务器中
  注意:Sonar对内存要求比较高,一般的默认配置满足不了需求,所以需要定制一下Tomcat里的相应参数:
-Xmx512m -Xmx1024m -Dorg.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER=true -XX:MaxPermSize=256m
-Xmx512m -Xmx1024m -Dorg.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER=true -XX:MaxPermSize=256m

2. 启动服务器后,访问http://localhost/sonar 就能看到界面了,default login/password is admin/admin.
额外说明:
如果想用自带的服务器 启动,即选择bin目录下相应的系统脚本就可以启动了,然后访问http://localhost
注意,如果采用此方式,则修改conf/sonar.properties时,也要配置自己对应的ip及端口号。
Create the file /etc/init.d/sonar with this content :
#! /bin/sh
/usr/bin/sonar $*
Register Sonar at boot time :

sudo ln -s $SONAR_HOME/bin/linux-x86-32/sonar.sh /usr/bin/sonar
sudo chmod 755 /etc/init.d/sonar
sudo update-rc.d sonar defaults

4.FAQ

【问题】Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.0:sonar (default-cli) on project update-server-core: Can not execute Sonar: PicoLifecycleException: method 'public void org.sonar.batch.ProjectTree.start() throws java.io.IOException', instance 'org.sonar.batch.ProjectTree@1747f59, javax.persistence.NonUniqueResultException: Expected single result, but got : [Snapshot[resourceId=1260,buildDate=2012-04-27 18:52:19.0,createdAt=2012-04-27
【解决】更新mysql:
use sonar;
update snapshots old_snap, snapshots new_snap set old_snap.islast=0 where old_snap.islast=1 and new_snap.created_at > old_snap.created_at and new_snap.project_id = old_snap.project_id and new_snap.islast=1;
据说是个BUG,详情参阅http://jira.codehaus.org/browse/SONAR-2329

【问题】如何修改管理密码?I lost the admin password
【解决】
In case you lost the admin password of your Sonar instance, you can reset it by running the following update statement :

update users set crypted_password = '88c991e39bb88b94178123a849606905ebf440f5', salt='6522f3c5007ae910ad690bb1bdbf264a34884c6d' where login = 'admin'
This will reset the password to admin.
参考资料:http://docs.codehaus.org/display/SONAR/Authentication

落款2014.03.07

No comments: