Ubuntu 16.04下安装配置SonarQube+MySQL
环境:
root@ubuntu:~
# uname -a
Linux ubuntu 4.4.0-21-generic
#37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
root@ubuntu:~
#
root@ubuntu:~
# cat /etc/issue
Ubuntu 16.04 LTS \n \l
root@ubuntu:~
#
安装配置MySQL:
1、更新源
root@ubuntu:~
# apt-get update
2、安装MySQL
root@ubuntu:~
# apt-get install -y mysql-server mysql-client
#中间会有一个为root用户添加密码的,可以添加也可以忽略
3、启动MySQL
root@ubuntu:~
# systemctl start mysql
root@ubuntu:~
# ps -ef|grep mysql
mysql 11268 1 0 15:58 ? 00:00:00
/usr/sbin/mysqld
root 11362 4143 0 16:00 pts
/0
00:00:00
grep
--color=auto mysql
root@ubuntu:~
# netstat -lntup|grep mysql
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 11268
/mysqld
root@ubuntu:~
#
4、安装PHP支持MySQL模块
1 |
|
出现错误:
root@ubuntu:~
# apt-get install php5-mysql
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package php5-mysql is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another
source
E: Package
'php5-mysql'
has no installation candidate
root@ubuntu:~
#
解决方法一:
root@ubuntu:~
# apt-get update #更新源
root@ubuntu:~
# apt-get upgrade #升级包
如果还是不能解决,尝试添加第三方地址。
解决方法二:
root@ubuntu:~
# add-apt-repository "deb http://archive.canonical.com/ lucid partner"
root@ubuntu:~
# apt-get update
解决方法三:
root@ubuntu:~
# tail -3 /etc/apt/sources.list
deb http:
//mirrors
.163.com
/ubuntu/
hardy main universe
deb http:
//tw
.archive.ubuntu.com
/ubuntu/
hardy main universe
root@ubuntu:~
# apt-get update
安装sonarqube
1、登陆MySQL创建sonar数据库和用户
mysql> CREATE DATABASE sonar DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.00 sec)
mysql>
mysql> CREATE USER
'sonar'
IDENTIFIED BY
'sonar'
;
Query OK, 0 rows affected (0.10 sec)
mysql> GRANT ALL ON sonar.* TO
'sonar'
@
'%'
IDENTIFIED BY
'sonar'
;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> GRANT ALL ON sonar.* TO
'sonar'
@
'localhost'
IDENTIFIED BY
'sonar'
;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql>
2、下载sonarqube-5.3和sonar-scanner
root@ubuntu:~
# cd /etc
root@ubuntu:
/etc
# wget
#在此地下载Scanner,然后上传
root@ubuntu:
/etc
# apt-get install lrzsz #没有上传下载工具的可以用此命令安装
root@ubuntu:
/etc
# ll *.zip #查看下载好的两个包
-rw-r--r-- 1 root root 111318629 Jan 8 2016 sonarqube-5.3.zip
-rw-r--r-- 1 root root 499181 Mar 20 19:44 sonar-scanner-cli-2.9.0.670.zip
root@ubuntu:
/etc
#
3、解压到指定目录
root@ubuntu:
/etc
# mkdir /usr/sonar
root@ubuntu:
/etc
# cd /usr/sonar
root@ubuntu:
/usr/sonar
# unzip /etc/sonarqube-5.3.zip
root@ubuntu:
/usr/sonar
# unzip /etc/sonar-scanner-cli-2.9.0.670.zip
root@ubuntu:
/usr/sonar
# ls
sonarqube-5.3 sonar-scanner-2.9.0.670
root@ubuntu:
/usr/sonar
#
root@ubuntu:
/usr/sonar
# apt-get install unzip #有的人没有这个解压工具,可以用此命令安装
4、配置环境变量,同时将SONAR_RUNNER_HOME变量加入PATH
root@ubuntu:
/usr/sonar
# sudo tail -2 /etc/profile
export
SONAR_HOME=
"/usr/sonar/sonarqube-5.3/"
export
SONAR_RUNNER_HOME=
"/usr/sonar/sonar-scanner-2.9/"
root@ubuntu:
/usr/sonar
# . /etc/profile
root@ubuntu:
/usr/sonar
#
5、修改配置文件
root@ubuntu:
/usr/sonar
# pwd
/usr/sonar
root@ubuntu:
/usr/sonar
# grep "^[a-z]" sonarqube-5.3/conf/sonar.properties
sonar.jdbc.username=sonar
#数据库名
sonar.jdbc.password=sonar
#密码
sonar.jdbc.url=jdbc:mysql:
//localhost
:3306
/sonar
?useUnicode=
true
&characterEncoding=utf8&rewriteBatchedStatements=
true
&useConfigs=maxPerformance
root@ubuntu:
/usr/sonar
#
root@ubuntu:
/usr/sonar
# grep "^[a-z]" sonar-scanner-2.9/conf/sonar-scanner.properties
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:mysql:
//localhost
:3306
/sonar
?useUnicode=
true
&characterEncoding=utf8&rewriteBatchedStatements=
true
&useConfigs=maxPerformance
root@ubuntu:
/usr/sonar
#
6、运行
root@ubuntu:
/usr/sonar
# cd sonarqube-5.3/bin/linux-x86-64/
root@ubuntu:
/usr/sonar/sonarqube-5
.3
/bin/linux-x86-64
# ./sonar.sh start
Starting SonarQube...
Failed to start SonarQube.
root@ubuntu:
/usr/sonar/sonarqube-5
.3
/bin/linux-x86-64
# ./sonar.sh status
SonarQube is not running.
root@ubuntu:
/usr/sonar/sonarqube-5
.3
/bin/linux-x86-64
#
可以看到出错了,原因是少了Java,即没有安装jdk1.8
安装Java
1、下载
root@ubuntu:
/usr/sonar/sonarqube-5
.3
/bin/linux-x86-64
# cd /usr/local/src/
root@ubuntu:
/usr/local/src
# ls
jdk-8u121-linux-x64.
tar
.gz
root@ubuntu:
/usr/local/src
#
2、解压
root@ubuntu:
/usr/local/src
# tar xf jdk-8u121-linux-x64.tar.gz
root@ubuntu:
/usr/local/src
# mkdir ../java
root@ubuntu:
/usr/local/src
# mv jdk1.8.0_121 ../java/
3、设置jdk环境变量
root@ubuntu:
/usr/local/src
# tail -4 /etc/bash.bashrc
export
JAVA_HOME=
/usr/local/java/jdk1
.8.0_121
export
JRE_HOME=${JAVA_HOME}
/jre
export
CLASSPATH=.:${JAVA_HOME}
/lib
:${JRE_HOME}
/lib
export
PATH=${JAVA_HOME}
/bin
:$PATH
root@ubuntu:
/usr/local/src
# . /etc/bash.bashrc
root@ubuntu:
/usr/local/src
#
4、检验是否成功
root@ubuntu:
/usr/local/src
# java -version
java version
"1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
root@ubuntu:
/usr/local/src
#
5、继续运行sonar
root@ubuntu:
/usr/sonar/sonarqube-5
.3
/bin/linux-x86-64
# pwd
/usr/sonar/sonarqube-5
.3
/bin/linux-x86-64
root@ubuntu:
/usr/sonar/sonarqube-5
.3
/bin/linux-x86-64
#
root@ubuntu:
/usr/sonar/sonarqube-5
.3
/bin/linux-x86-64
# ./sonar.sh start
Starting SonarQube...
Started SonarQube.
root@ubuntu:
/usr/sonar/sonarqube-5
.3
/bin/linux-x86-64
# ./sonar.sh status
SonarQube is running (14033).
root@ubuntu:
/usr/sonar/sonarqube-5
.3
/bin/linux-x86-64
# ps -ef|grep sonar
root 14033 1 0 13:13 ? 00:00:00
/usr/sonar/sonarqube-5
.3
/bin/linux-x86-64/
.
/wrapper
/usr/sonar/sonarqube-5
.3
/bin/linux-x86-64/
../..
/conf/wrapper
.conf wrapper.syslog.ident=SonarQube wrapper.pidfile=
/usr/sonar/sonarqube-5
.3
/bin/linux-x86-64/
.
/SonarQube
.pid wrapper.daemonize=TRUE wrapper.lockfile=
/var/lock/subsys/SonarQube
root 14035 14033 6 13:13 ? 00:00:01 java -Djava.awt.headless=
true
-Xms3m -Xmx3m -Djava.library.path=.
/lib
-classpath ../..
/lib/jsw/wrapper-3
.2.3.jar:../..
/lib/sonar-application-5
.3.jar -Dwrapper.key=RLD1zL2ZQ9qqdiSt -Dwrapper.port=32000 -Dwrapper.jvm.port.min=31000 -Dwrapper.jvm.port.max=31999 -Dwrapper.pid=14033 -Dwrapper.version=3.2.3 -Dwrapper.native_library=wrapper -Dwrapper.service=TRUE -Dwrapper.cpu.timeout=10 -Dwrapper.jvmid=1 org.tanukisoftware.wrapper.WrapperSimpleApp org.sonar.application.App
root 14060 14035 45 13:13 ? 00:00:12
/usr/local/java/jdk1
.8.0_121
/jre/bin/java
-Djava.awt.headless=
true
-Xmx1G -Xms256m -Xss256k -Djava.net.preferIPv4Stack=
true
-XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -Djava.io.tmpdir=
/usr/sonar/sonarqube-5
.3
/temp
-
cp
.
/lib/common/
*:.
/lib/search/
* org.sonar.search.SearchServer
/tmp/sq-process4748582369994525447properties
root 14164 14035 99 13:13 ? 00:00:36
/usr/local/java/jdk1
.8.0_121
/jre/bin/java
-Djava.awt.headless=
true
-Dfile.encoding=UTF-8 -Djruby.management.enabled=
false
-Djruby.compile.invokedynamic=
false
-Xmx768m -Xms256m -XX:MaxPermSize=160m -XX:+HeapDumpOnOutOfMemoryError -Djava.net.preferIPv4Stack=
true
-Djava.io.tmpdir=
/usr/sonar/sonarqube-5
.3
/temp
-
cp
.
/lib/common/
*:.
/lib/server/
*:
/usr/sonar/sonarqube-5
.3
/lib/jdbc/mysql/mysql-connector-java-5
.1.35.jar org.sonar.server.app.WebServer
/tmp/sq-process8773907296141005182properties
root 14206 13703 0 13:14 pts
/3
00:00:00
grep
--color=auto sonar
root@ubuntu:
/usr/sonar/sonarqube-5
.3
/bin/linux-x86-64
#
6、浏览器查看
http:
//localhost
:9000/
配置Sonar、Jenkins进行持续审查 http://www.linuxidc.com/Linux/2016-08/133877.htm
sonarQube代码质量管理工具环境筹建笔记 http://www.linuxidc.com/Linux/2016-08/133878.htm
SonarQube代码质量管理平台安装与使用 http://www.linuxidc.com/Linux/2016-08/133879.htm
SonarQube升级过程记录 http://www.linuxidc.com/Linux/2016-08/133880.htm
在Fedora 21上搭建Jenkins+SonarQube的Maven项目自动化测试平台 http://www.linuxidc.com/Linux/2017-02/140780.htm
Sonar 的详细介绍:请点这里
Sonar 的下载地址:请点这里
本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-05/143860.htm