Linux下安装SonarQube

本机Linux版本为CentOS7
1、Windows环境下载SonarQube安装包。此安装包同时适用于windows 32位/64位、Linux 32位/64位、MacOSX 64位系统。https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-7.5.zip
也可以使用下面的命令直接在Linux机器上下载,不过下载速度慢,不推荐。

wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-7.5.zip

2、将SonarQube安装包上传到Linux机器上
在这里插入图片描述
3、Linux下新建软件目录,将SonarQube安装包解压到该目录

mkdir /opt/softs
sudo unzip -q sonarqube-7.5.zip -d /opt/softs

4、打开/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&useSSL=false

5、进入对应系统的启动文件所在目录,启动SonarQube。

cd /opt/softs/sonarqube-7.5/bin/linux-x86-64
./sonar.sh start

这一步有个坑,启动程序不成功。
查看日志信息如下(日志文件位置: /logs/sonar.log):

--> Wrapper Started as Console
Launching a JVM...
Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
  Copyright 1999-2006 Tanuki Software, Inc.  All Rights Reserved.

2019.02.18 06:19:25 INFO  app[][o.s.a.AppFileSystem] Cleaning or creating temp directory /opt/snoar/sonarqube-7.5/temp
2019.02.18 06:19:25 INFO  app[][o.s.a.es.EsSettings] Elasticsearch listening on /127.0.0.1:9001
2019.02.18 06:19:26 INFO  app[][o.s.a.p.ProcessLauncherImpl] Launch process[[key='es', ipcIndex=1, logFilenamePrefix=es]] from [/opt/snoar/sonarqube-7.5/elasticsearch]: /opt/snoar/sonarqube-7.5/elasticsearch/bin/elasticsearch -Epath.conf=/opt/snoar/sonarqube-7.5/temp/conf/es
2019.02.18 06:19:26 INFO  app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
2019.02.18 06:19:26 INFO  app[][o.e.p.PluginsService] no modules loaded
2019.02.18 06:19:26 INFO  app[][o.e.p.PluginsService] loaded plugin [org.elasticsearch.transport.Netty4Plugin]
2019.02.18 06:19:27 WARN  app[][o.s.a.p.AbstractProcessMonitor] Process exited with exit value [es]: 1
2019.02.18 06:19:27 INFO  app[][o.s.a.SchedulerImpl] Process [es] is stopped
2019.02.18 06:19:27 INFO  app[][o.s.a.SchedulerImpl] SonarQube is stopped
<-- Wrapper Stopped

这里无法启动是因为当前用户位root用户,root用户启动es。这里需要新建一个用户,并赋权。

[root@localhost linux-x86-64]# adduser newuser
[root@localhost linux-x86-64]# passwd newuser
Changing password for user newuser.
####输入密码
New password: 
BAD PASSWORD: The password is shorter than 8 characters
####再次输入密码
Retype new password: 
passwd: all authentication tokens updated successfully.

####给 sonarqube-7.5 目录的拥有组改成非root用户
[root@localhost sonarqube7.5]# chown -R newuser:newuser sonarqube-7.5 
####创建新的目录,并将sonarqube-7.5目录移动到该目录下
[root@localhost linux-x86-64]# mkdir /opt/snoar
[root@localhost sonarqube]# mv sonarqube-7.5 /opt/snoar/
[root@localhost sonarqube]# cd /opt/snoar/
[root@localhost snoar]# ls -l
total 4
drwxr-xr-x 11 sonarUser sonarUser 4096 Jun 18 09:35 sonarqube-7.2
[root@localhost snoar]# cd sonarqube-7.5/
[root@localhost sonarqube-7.5]# ls -l
total 44
...............
...............
####切换到新建的用户,并启动应用
[root@localhost linux-x86-64]# su newuser
[sonarUser@localhost linux-x86-64]$ ./sonar.sh start
####查看是否启动成功,出现下面信息代表启动成功
[root@localhost linux-x86-64]# ./sonar.sh status
SonarQube is running (18481).

其他异常一:WrapperSimpleApp: Encountered an error running main: java.nio.file.AccessDeniedException
解决方法:进入sonarqube-7.5/temp目录,切换到root用户,删除该目录下的所有文件即可,删除后再切换回newuser用户启动服务。

其他异常二:
启动窗口提示以下信息:

2019.02.18 06:45:57 WARN  app[][startup] 
################################################################################
      Database must be upgraded. Please backup database and browse /setup
################################################################################

打开:127.0.0.1:9000访问SonarQube,页面提示:SonarQube is under maintenance. Please check back later.
Whilst waiting, you might want to check new plugins to extend the current functionality.
If you are an administrator and have no idea why this message is showing, you should read the upgrade guide
解决方法:打开:http://127.0.0.1:9000/setup 更新下 SonarQube的数据库表,这里可能更新失败,这时需要把数据库中SonarQube自动生成的所有表都删掉,然后重启SonarQube,就可以成功更新了。

猜你喜欢

转载自blog.csdn.net/qq_39387856/article/details/87633877