ubuntu16.04配置sonarqube+MySQL

前端之家收集整理的这篇文章主要介绍了ubuntu16.04配置sonarqube+MySQL前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

环境:

root@ubuntu:~#uname-a
Linuxubuntu4.4.0-21-generic#37-UbuntuSMPMonApr1818:33:37UTC2016x86_64x86_64x86_64GNU/Linux
root@ubuntu:~#
root@ubuntu:~#cat/etc/issue
Ubuntu16.04LTS\n\l

root@ubuntu:~#

安装配置MysqL

1、更新源

root@ubuntu:~#apt-getupdate

2、安装MysqL

root@ubuntu:~#apt-getinstall-yMysqL-serverMysqL-client
#中间会有一个为root用户添加密码的,可以添加也可以忽略

3、启动MysqL

root@ubuntu:~#systemctlstartMysqL
root@ubuntu:~#ps-ef|grepMysqL
MysqL112681015:58?00:00:00/usr/sbin/MysqLd
root113624143016:00pts/000:00:00grep--color=autoMysqL
root@ubuntu:~#netstat-lntup|grepMysqL
tcp00127.0.0.1:33060.0.0.0:*LISTEN11268/MysqLd
root@ubuntu:~#

4、安装PHP支持MysqL模块

root@ubuntu:~#apt-getinstallPHP5-MysqL

出现错误

root@ubuntu:~#apt-getinstallPHP5-MysqL
Readingpackagelists...Done
Buildingdependencytree
Readingstateinformation...Done
PackagePHP5-MysqLisnotavailable,butisreferredtobyanotherpackage.
Thismaymeanthatthepackageismissing,hasbeenobsoleted,or
isonlyavailablefromanothersource

E:Package'PHP5-MysqL'hasnoinstallationcandidate
root@ubuntu:~#

解决方法一:

root@ubuntu:~#apt-getupdate#更新源
root@ubuntu:~#apt-getupgrade#升级

如果还是不能解决,尝试添加第三方地址。

解决方法二:

root@ubuntu:~#add-apt-repository"debhttp://archive.canonical.com/lucidpartner"
root@ubuntu:~#apt-getupdate

解决方法三:

root@ubuntu:~#tail-3/etc/apt/sources.list
debhttp://mirrors.163.com/ubuntu/hardymainuniverse
debhttp://tw.archive.ubuntu.com/ubuntu/hardymainuniverse
root@ubuntu:~#apt-getupdate

安装sonarqube

1、登陆MysqL创建sonar数据库用户

MysqL>CREATEDATABASEsonarDEFAULTCHARACTERSETutf8COLLATEutf8_general_ci;
QueryOK,1rowaffected(0.00sec)

MysqL>
MysqL>CREATEUSER'sonar'IDENTIFIEDBY'sonar';
QueryOK,0rowsaffected(0.10sec)

MysqL>GRANTALLONsonar.*TO'sonar'@'%'IDENTIFIEDBY'sonar';
QueryOK,0rowsaffected,1warning(0.00sec)

MysqL>GRANTALLONsonar.*TO'sonar'@'localhost'IDENTIFIEDBY'sonar';
QueryOK,1warning(0.00sec)

MysqL>FLUSHPRIVILEGES;
QueryOK,0rowsaffected(0.00sec)

MysqL>

2、下载sonarqube-5.3和sonar-scanner

root@ubuntu:~#cd/etc
root@ubuntu:/etc#wget
#在此地下载Scanner,然后上传
root@ubuntu:/etc#apt-getinstalllrzsz#没有上传下载工具的可以用此命令安装
root@ubuntu:/etc#ll*.zip#查看下载好的两个包
-rw-r--r--1rootroot111318629Jan82016sonarqube-5.3.zip
-rw-r--r--1rootroot499181Mar2019:44sonar-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.3sonar-scanner-2.9.0.670
root@ubuntu:/usr/sonar#
root@ubuntu:/usr/sonar#apt-getinstallunzip#有的人没有这个解压工具,可以用此命令安装

4、配置环境变量,同时将SONAR_RUNNER_HOME变量加入PATH

root@ubuntu:/usr/sonar#sudotail-2/etc/profile
exportSONAR_HOME="/usr/sonar/sonarqube-5.3/"
exportSONAR_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#cdsonarqube-5.3/bin/linux-x86-64/
root@ubuntu:/usr/sonar/sonarqube-5.3/bin/linux-x86-64#./sonar.shstart
StartingSonarQube...
FailedtostartSonarQube.
root@ubuntu:/usr/sonar/sonarqube-5.3/bin/linux-x86-64#./sonar.shstatus
SonarQubeisnotrunning.
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#tarxfjdk-8u121-linux-x64.tar.gz
root@ubuntu:/usr/local/src#mkdir../java
root@ubuntu:/usr/local/src#mvjdk1.8.0_121../java/

3、设置jdk环境变量

root@ubuntu:/usr/local/src#tail-4/etc/bash.bashrc
exportJAVA_HOME=/usr/local/java/jdk1.8.0_121
exportJRE_HOME=${JAVA_HOME}/jre
exportCLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
exportPATH=${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
javaversion"1.8.0_121"
Java(TM)SERuntimeEnvironment(build1.8.0_121-b13)
JavaHotSpot(TM)64-BitServerVM(build25.121-b13,mixedmode)
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.shstart
StartingSonarQube...
StartedSonarQube.
root@ubuntu:/usr/sonar/sonarqube-5.3/bin/linux-x86-64#./sonar.shstatus
SonarQubeisrunning(14033).
root@ubuntu:/usr/sonar/sonarqube-5.3/bin/linux-x86-64#ps-ef|grepsonar
root140331013: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.confwrapper.syslog.ident=SonarQubewrapper.pidfile=/usr/sonar/sonarqube-5.3/bin/linux-x86-64/./SonarQube.pidwrapper.daemonize=TRUEwrapper.lockfile=/var/lock/subsys/SonarQube
root1403514033613:13?00:00:01java-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=1org.tanukisoftware.wrapper.WrapperSimpleApporg.sonar.application.App
root14060140354513: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
root14164140359913: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.jarorg.sonar.server.app.WebServer/tmp/sq-process8773907296141005182properties
root1420613703013:14pts/300:00:00grep--color=autosonar
root@ubuntu:/usr/sonar/sonarqube-5.3/bin/linux-x86-64#

6、浏览器查看

http://localhost:9000/


wKioL1jQuGyBI_qFAACiR220agg144.png-wh_50

原文链接:https://www.f2er.com/ubuntu/353928.html

猜你在找的Ubuntu相关文章