2021-05-12 14:32:11
Ubuntu 16.04下安裝設定SonarQube+MySQL
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 |
出現錯誤:
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
相關文章