Ubuntu 18.0.4 SonarQube-7.1.x 安装教程
docker安装未成功
zip安装
1. 下载地址
- sonarQube最新版下载地址:(最新版不支持mysql)https://www.sonarqube.org/downloads/
- 7.1版本下载地址: https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-7.1.zip
- Sonar-Scanner 2.5下载地址: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/
下载不了:参考该地址中的下载:
https://blog.51cto.com/u_14082075/5465953#1__6
2. 环境准备
(1)Java环境(1.8+)
(2)MySql数据库(5.6+)
(3)SonarQube 7.1
注意:sonarQube 7.9的版本之后就不在支持mysql,所以下载的是7.1版本。
3.上传到ubuntu
//解压
unzip sonarqube-6.7.7.zip
//移动目录
mv sonarqube-6.7.7 /usr/local/sonar
4. 数据库配置
.进入mysql容器并创建用户账户密码均为sonar
# docker exec -it mysql bash
# mysql -u root -p
# create database sonar;
# CREATE USER 'sonar'@'%' IDENTIFIED WITH mysql_native_password BY 'sonar';
# GRANT ALL PRIVILEGES ON *.* TO 'sonar'@'%';
# exit
5.配置sonar的数据库信息(vim conf/sonar.properties)
安装目录下的conf中的配置文件,
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
6.启动
不能使用root用户启动,新建个用户
//新建用户
useradd sonar
//赋权
chown -R sonar.sonar /usr/local/sonar
//修改密码
passwd sonar
//切换到sonar用户
su sonar
//启动
./bin/linux-x86-64/sonar.sh console
7. 登录系统
http://ip:9000 用户名密码:admin
汉化,重启服务即可
安装后,汉化
如果出现“Error while downloading plugin ‘l10nzhtw’ with version ‘1.0’. No compatible plugin found.”错误,那说明版本不兼容,可到官网查找对应版本的插件放到…/…/extensions/plugins目录下,重新启动sonar服务【使用命令…/…/sonar.sh start 也可以通过页面操作“配置->系统->重启服务器”】,即可生效。但如果安装的插件比当前版本低的话,会出现部分显示还是英文。
汉化插件下载[找到对应的版本,下载对应的插件]:https://github.com/xuhuisheng/sonar-l10n-zh/releases?page=2
放到该路径下:
cd /usr/local/sonarqube-8.6.0/extensions/plugins
重启服务即可【不可使用root用户登录】
- 生成令牌(需要将生成的令牌复制下来):
启动成功后,会在对应的sonar中创建对应的数据库
错误总结
错误1:Elasticsearch 虚拟内存需要至少[262144]
# docker logs sonarqube_sonarqube_1
ERROR: [1] bootstrap checks failed. You must address the points described in the following [1] lines before starting Elasticsearch.
bootstrap check failure [1] of [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
ERROR: Elasticsearch did not exit normally - check the logs at /opt/sonarqube/logs/sonarqube.log
解决方案:
大致看了一下,是因为ElasticSearch运行的时候最小内存消耗要达到262144,所以,如果是在自己的虚拟机运行,可以临时调整vm.max_map_count的大小,max_map_count文件包含限制一个进程可以拥有的VMA(虚拟内存区域)的数量,临时调整的语句如下:
sysctl -w vm.max_map_count=262144
调整之后再运行es集群就不会有问题了。
如果想永久修改vm.max_map_count的大小,则可以使用如下命令:
echo vm.max_map_count=262144>> /etc/sysctl.conf sysctl -p
未解决问题【docker安装】
一开始为了省事,使用docker安装,但是一直启动不起来,报错 Can not connect to database. Please check connectivity and settings (see the properties prefixed by ‘sonar.jdbc.’).
根据网上提供的方案,都没有用
- 1.数据库用户名、密码均使用sonar/sonar 数据库名:sonar
-
docker安装步骤【未成功】
1…docker拉取sonarqube镜像
docker pull sonarqube:7.8-community
可在官网查找你想要的版本:https://hub.docker.com/_/sonarqube?tab=tags&page=9
2…进入mysql容器并创建用户账户密码均为sonar
# docker exec -it mysql bash
# mysql -u root -p
# create database sonar;
# CREATE USER 'sonar'@'%' IDENTIFIED WITH mysql_native_password BY 'sonar';
# GRANT ALL PRIVILEGES ON *.* TO 'sonar'@'%';
# exit
3.启动sonarqube
docker run -d --name sonar -p 9000:9000 -p 9092:9092 -v /data/sonar/conf:/opt/sonarqube/conf -v /data/sonar/data:/opt/sonarqube/data -v /data/sonar/logs:/opt/sonarqube/logs -v /data/sonar/extensions:/opt/sonarqube/extensions -e "SONARQUBE_DATABASE_USER=sonar" -e "SONARQUBE_DATABASE_NAME=sonar" -e "SONARQUBE_DATABASE_PASSWORD=sonar" -e "SONARQUBE_JDBC_URL=jdbc:mysql://127.0.0.1:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false" sonarqube:7.8-community
4.对应的映射配置/data/sonar/conf中的数据库配置是否正确
vi sonar.properties
#sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformanc
e#sonar.jdbc.username=sonar
#sonar.jdbc.password=sonar
#sonar.sorceEncoding=UTF-8
root@koal-ipsec:/data/sonar/conf# docker logs sonar
2022.12.26 05:15:07 INFO app[][o.s.a.AppFileSystem] Cleaning or creating temp directory /opt/sonarqube/temp
2022.12.26 05:15:07 INFO app[][o.s.a.es.EsSettings] Elasticsearch listening on /127.0.0.1:9001
2022.12.26 05:15:07 INFO app[][o.s.a.p.ProcessLauncherImpl] Launch process[[key='es', ipcIndex=1, logFilenamePrefix=es]] from [/opt/sonarqube/elasticsearch]: /opt/sonarqube/elasticsearch/bin/elasticsearch -Epath.conf=/opt/sonarqube/temp/conf/es
2022.12.26 05:15:07 INFO app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
2022.12.26 05:15:07 INFO app[][o.e.p.PluginsService] no modules loaded
2022.12.26 05:15:07 INFO app[][o.e.p.PluginsService] loaded plugin [org.elasticsearch.transport.Netty4Plugin]
2022.12.26 05:15:14 INFO app[][o.s.a.SchedulerImpl] Process[es] is up
2022.12.26 05:15:14 INFO app[][o.s.a.p.ProcessLauncherImpl] Launch process[[key='web', ipcIndex=2, logFilenamePrefix=web]] from [/opt/sonarqube]: /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/opt/sonarqube/temp -Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -Djava.security.egd=file:/dev/./urandom -cp ./lib/common/*:./lib/server/*:/opt/sonarqube/lib/jdbc/mysql/mysql-connector-java-5.1.42.jar org.sonar.server.app.WebServer /opt/sonarqube/temp/sq-process8004789798386622755properties
2022.12.26 05:15:14 INFO web[][o.s.p.ProcessEntryPoint] Starting web
2022.12.26 05:15:15 INFO web[][o.a.t.u.n.NioSelectorPool] Using a shared selector for servlet write/read
2022.12.26 05:15:15 INFO web[][o.e.p.PluginsService] no modules loaded
2022.12.26 05:15:15 INFO web[][o.e.p.PluginsService] loaded plugin [org.elasticsearch.index.reindex.ReindexPlugin]
2022.12.26 05:15:15 INFO web[][o.e.p.PluginsService] loaded plugin [org.elasticsearch.join.ParentJoinPlugin]
2022.12.26 05:15:15 INFO web[][o.e.p.PluginsService] loaded plugin [org.elasticsearch.percolator.PercolatorPlugin]
2022.12.26 05:15:15 INFO web[][o.e.p.PluginsService] loaded plugin [org.elasticsearch.transport.Netty4Plugin]
2022.12.26 05:15:16 INFO web[][o.s.s.e.EsClientProvider] Connected to local Elasticsearch: [127.0.0.1:9001]
2022.12.26 05:15:16 INFO web[][o.s.s.p.LogServerVersion] SonarQube Server / 6.7.5.38563 / ec8ab77fa180a9edaf664075e8e76ae0b4a2d9f1
2022.12.26 05:15:16 INFO web[][o.sonar.db.Database] Create JDBC data source for jdbc:mysql://127.0.0.1:3306/db_sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
2022.12.26 05:15:16 ERROR web[][o.s.s.p.Platform] Web server startup failed
java.lang.IllegalStateException: Can not connect to database. Please check connectivity and settings (see the properties prefixed by 'sonar.jdbc.').
at org.sonar.db.DefaultDatabase.checkConnection(DefaultDatabase.java:108)
at org.sonar.db.DefaultDatabase.start(DefaultDatabase.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.invokeMethod(ReflectionLifecycleStrategy.java:110)
at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.start(ReflectionLifecycleStrategy.java:89)
at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.start(AbstractInjectionFactory.java:84)
at org.picocontainer.behaviors.AbstractBehavior.start(AbstractBehavior.java:169)
at org.picocontainer.behaviors.Stored$RealComponentLifecycle.start(Stored.java:132)
at org.picocontainer.behaviors.Stored.start(Stored.java:110)
at org.picocontainer.DefaultPicoContainer.potentiallyStartAdapter(DefaultPicoContainer.java:1016)
at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1009)
at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:767)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:134)
at org.sonar.server.platform.platformlevel.PlatformLevel.start(PlatformLevel.java:90)
at org.sonar.server.platform.Platform.start(Platform.java:211)
at org.sonar.server.platform.Platform.startLevel1Container(Platform.java:170)
at org.sonar.server.platform.Platform.init(Platform.java:86)
at org.sonar.server.platform.web.PlatformServletContextListener.contextInitialized(PlatformServletContextListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at org.sonar.db.profiling.NullConnectionInterceptor.getConnection(NullConnectionInterceptor.java:31)
at org.sonar.db.profiling.ProfiledDataSource.getConnection(ProfiledDataSource.java:323)
at org.sonar.db.DefaultDatabase.checkConnection(DefaultDatabase.java:106)
... 29 common frames omitted
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:989)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:341)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2192)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2225)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2024)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:779)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
... 34 common frames omitted
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:211)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:300)
... 50 common frames omitted
2022.12.26 05:15:17 INFO app[][o.s.a.SchedulerImpl] Process [web] is stopped
2022.12.26 05:15:17 WARN app[][o.s.a.p.AbstractProcessMonitor] Process exited with exit value [es]: 143
2022.12.26 05:15:17 INFO app[][o.s.a.SchedulerImpl] Process [es] is stopped
2022.12.26 05:15:17 INFO app[][o.s.a.SchedulerImpl] SonarQube is stopped