环境:
root@ubuntu:~# uname -aLinux ubuntu 4.4.0-21-generic #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linuxroot@ubuntu:~# root@ubuntu:~# cat /etc/issueUbuntu 16.04 LTS \n \lroot@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 mysqlroot@ubuntu:~# ps -ef|grep mysqlmysql 11268 1 0 15:58 ? 00:00:00 /usr/sbin/mysqldroot 11362 4143 0 16:00 pts/0 00:00:00 grep --color=auto mysqlroot@ubuntu:~# netstat -lntup|grep mysqltcp 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-mysqlReading package lists... DoneBuilding dependency tree Reading state information... DonePackage php5-mysql is not available, but is referred to by another package.This may mean that the package is missing, has been obsoleted, oris only available from another sourceE: Package 'php5-mysql' has no installation candidateroot@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.listdeb http://mirrors.163.com/ubuntu/ hardy main universedeb http://tw.archive.ubuntu.com/ubuntu/ hardy main universeroot@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 /etcroot@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.ziproot@ubuntu:/etc#
3、解压到指定目录
root@ubuntu:/etc# mkdir /usr/sonarroot@ubuntu:/etc# cd /usr/sonarroot@ubuntu:/usr/sonar# unzip /etc/sonarqube-5.3.ziproot@ubuntu:/usr/sonar# unzip /etc/sonar-scanner-cli-2.9.0.670.ziproot@ubuntu:/usr/sonar# lssonarqube-5.3 sonar-scanner-2.9.0.670root@ubuntu:/usr/sonar#root@ubuntu:/usr/sonar# apt-get install unzip #有的人没有这个解压工具,可以用此命令安装
4、配置环境变量,同时将SONAR_RUNNER_HOME变量加入PATH
root@ubuntu:/usr/sonar# sudo tail -2 /etc/profileexport SONAR_HOME="/usr/sonar/sonarqube-5.3/"export SONAR_RUNNER_HOME="/usr/sonar/sonar-scanner-2.9/"root@ubuntu:/usr/sonar# . /etc/profileroot@ubuntu:/usr/sonar#
5、修改配置文件
root@ubuntu:/usr/sonar# pwd/usr/sonarroot@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=maxPerformanceroot@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=maxPerformanceroot@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 startStarting SonarQube...Failed to start SonarQube.root@ubuntu:/usr/sonar/sonarqube-5.3/bin/linux-x86-64# ./sonar.sh statusSonarQube 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# lsjdk-8u121-linux-x64.tar.gzroot@ubuntu:/usr/local/src#
2、解压
root@ubuntu:/usr/local/src# tar xf jdk-8u121-linux-x64.tar.gzroot@ubuntu:/usr/local/src# mkdir ../javaroot@ubuntu:/usr/local/src# mv jdk1.8.0_121 ../java/
3、设置jdk环境变量
root@ubuntu:/usr/local/src# tail -4 /etc/bash.bashrcexport JAVA_HOME=/usr/local/java/jdk1.8.0_121export JRE_HOME=${JAVA_HOME}/jreexport CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATHroot@ubuntu:/usr/local/src# . /etc/bash.bashrcroot@ubuntu:/usr/local/src#
4、检验是否成功
root@ubuntu:/usr/local/src# java -versionjava 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-64root@ubuntu:/usr/sonar/sonarqube-5.3/bin/linux-x86-64# root@ubuntu:/usr/sonar/sonarqube-5.3/bin/linux-x86-64# ./sonar.sh startStarting SonarQube...Started SonarQube.root@ubuntu:/usr/sonar/sonarqube-5.3/bin/linux-x86-64# ./sonar.sh statusSonarQube is running (14033).root@ubuntu:/usr/sonar/sonarqube-5.3/bin/linux-x86-64# ps -ef|grep sonarroot 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/SonarQuberoot 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.Approot 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-process4748582369994525447propertiesroot 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-process8773907296141005182propertiesroot 14206 13703 0 13:14 pts/3 00:00:00 grep --color=auto sonarroot@ubuntu:/usr/sonar/sonarqube-5.3/bin/linux-x86-64#
6、浏览器查看
http://localhost:9000/