环境:
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模块
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 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/