环境:
[email protected]:~
# 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
[email protected]:~
# cat /etc/issue
Ubuntu 16.04 LTS \n \l
安装配置MySQL:
1、更新源
[email protected]:~
# apt-get update
2、安装MySQL
[email protected]:~
# apt-get install -y mysql-server mysql-client
#中间会有一个为root用户添加密码的,可以添加也可以忽略
3、启动MySQL
[email protected]:~
# systemctl start mysql
[email protected]:~
# 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
[email protected]:~
# netstat -lntup|grep mysql
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 11268
/mysqld
4、安装PHP支持MySQL模块
1 |
[email protected]:~ # apt-get install php5-mysql
|
出现错误:
[email protected]:~
# 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
解决方法一:
[email protected]:~
# apt-get update #更新源
[email protected]:~
# apt-get upgrade #升级包
如果还是不能解决,尝试添加第三方地址。
解决方法二:
[email protected]:~
# add-apt-repository "deb http://archive.canonical.com/ lucid partner"
[email protected]:~
# apt-get update
解决方法三:
[email protected]:~
# 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
[email protected]:~
# 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
-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
3、解压到指定目录
sonarqube-5.3 sonar-scanner-2.9.0.670
4、配置环境变量,同时将SONAR_RUNNER_HOME变量加入PATH
export
SONAR_HOME=
"/usr/sonar/sonarqube-5.3/"
export
SONAR_RUNNER_HOME=
"/usr/sonar/sonar-scanner-2.9/"
5、修改配置文件
/usr/sonar
sonar.jdbc.username=sonar
#数据库名
sonar.jdbc.password=sonar
#密码
sonar.jdbc.url=jdbc:mysql:
//localhost
:3306
/sonar
?useUnicode=
true
&characterEncoding=utf8&rewriteBatchedStatements=
true
&useConfigs=maxPerformance
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:mysql:
//localhost
:3306
/sonar
?useUnicode=
true
&characterEncoding=utf8&rewriteBatchedStatements=
true
&useConfigs=maxPerformance
6、运行
Starting SonarQube...
Failed to start SonarQube.
SonarQube is not running.
可以看到出错了,原因是少了Java,即没有安装jdk1.8
安装Java
1、下载
2、解压
3、设置jdk环境变量
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
4、检验是否成功
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)
5、继续运行sonar
/usr/sonar/sonarqube-5
.3
/bin/linux-x86-64
Starting SonarQube...
Started SonarQube.
SonarQube is running (14033).
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
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