SonarQube 代码质量管理平台的安装

来源:互联网 发布:scrollreveal.js 编辑:程序博客网 时间:2024/05/20 09:21

IP:192.168.4.221
环境:CentOS 6.6、JDK7、MySQL5.1 、SonarQube-4.5.4(LTS)
root 用户操作
准备工作:已安装 JDK7 并配置好了环境变量

一、Mysql安装与配置

1 、安装 MySQL5.1

# rpm -qa | grep mysql ## 查看该操作系统上是否已经安装了 mysql 数据库,有的话,可以通过 rpm -e 命令 或者 rpm -e --nodeps 命令来卸载掉# yum install mysql-server mysql mysql-devel# service mysqld start# chkconfig --list | grep mysqldmysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off用上面的命令查看到 MySQL 并没有设置开机启动,所以需要设置开机启动# chkconfig mysqld on为了方便远程管理,防火墙中打开 3306 端口# vi /etc/sysconfig/iptables-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT重启防火墙,使端口配置生效# service iptables restart设置 MySQL 数据库 root 用户的密码:# mysqladmin -u root password 'wusc.123'登录数据库:# mysql -u root -pMySQL 授权远程访问(先用 root 登录 mysql)mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'wusc.321' WITH GRANT OPTION;mysql> FLUSH PRIVILEGES;

2、配置 MySQL

结合 SonarQube,MySQL 数据库最好使用 InnoDB 引擎,可提高性能。
看你的 mysql 现在已提供什么存储引擎:mysql> show engines;
这里写图片描述
看你的 mysql 当前默认的存储引擎:

mysql> show variables like '%storage_engine%';

这里写图片描述
修改 MySQL 存储引擎为 InnoDB, 在配置文件/etc/my.cnf 中的
[mysqld] 下面加入 default-storage-engine=INNODB

# vi /etc/my.cnf[mysqld]default-storage-engine=INNODB重启 mysql 服务器# service mysqld restart再次登录 MySQL 查看默认引擎设置是否生效mysql> show variables like '%storage_engine%';+----------------+--------+| Variable_name | Value |+----------------+--------+| storage_engine | InnoDB |+----------------+--------+

innodb_buffer_pool_size 参数值设置得尽可能大一点
这个参数主要作用是缓存 innodb 表的索引,数据,插入数据时的缓冲
默认值:128M,专用 mysql 服务器设置的大小:操作系统内存的 70%-80%最佳。
设置方法:my.cnf 文件[mysqld] 下面加入 innodb_buffer_pool_size 参数

# vi /etc/my.cnf[mysqld]innodb_buffer_pool_size = 256M

(我们这里设置为 256M,因为我们的不是专用的 MySQL 数据库服务器,还有很多其他的服
务需要占用系统内存)

设置 MySQL 的查询缓存 query_cache_size ,最少设置 15M

# vi /etc/my.cnf[mysqld]query_cache_type=1query_cache_size=32M重启 mysql 服务器# service mysqld restart验证缓存设置是否生效:mysql> show variables like '%query_cache%';+------------------------------+----------+| Variable_name | Value |+------------------------------+----------+| have_query_cache | YES || query_cache_limit | 1048576 || query_cache_min_res_unit | 4096 || query_cache_size | 33554432 || query_cache_type | ON || query_cache_wlock_invalidate | OFF |+------------------------------+----------+

3、创建 sonarqube 数据库(UTF-8 编码)

这里写图片描述

二、安装 SonarQube 的 Web Server

下载最新 LTS 版的 SonarQube 安装包(当前版本为 sonarqube-4.5.4.zip):
下载地址:http://www.sonarqube.org/downloads/
这里写图片描述
http://dist.sonar.codehaus.org/sonarqube-4.5.4.zip

下载:

# wget http://dist.sonar.codehaus.org/sonarqube-4.5.4.zip

解压安装:

# unzip sonarqube-4.5.4.zip# mv sonarqube-4.5.4 sonarqube

编辑 sonar 配置:

# cd sonarqube/conf/# vi sonar.propertiessonar.jdbc.username=rootsonar.jdbc.password=wusc.123#----- MySQL 5.xsonar.jdbc.url=jdbc:mysql://localhost:3306/sonarqube?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformancesonar.web.host=0.0.0.0sonar.web.context=/sonarqubesonar.web.port=9090

保存以上配置(注意,要看看默认的 9000 端口是否已被占用)此处以占用改为9090

防火墙中打开 9090 端口:

# vi /etc/sysconfig/iptables-A INPUT -m state --state NEW -m tcp -p tcp --dport 9090 -j ACCEPT

重启防火墙,使端口配置生效

# service iptables restart

启动 SonarQube Web Server

# /root/sonarqube/bin/linux-x86-64/sonar.sh start(初次启动会自动建表和做相应的初始化)

浏览器中输入:http://192.168.4.221:9090/sonarqube/
这里写图片描述

登录,默认用户名/密码为 admin/admin
这里写图片描述

这里写图片描述

阅读全文
1 0