sonarqube代码质量检测工具安装(docker安装篇)
一、sonarqube介绍
SonarQube 是一个开源的代码分析平台, 用来持续分析和评测项目源代码的质量。 通过SonarQube我们可以检测出项目中重复代码, 潜在bug, 代码规范,安全性漏洞等问题, 并通过SonarQube web UI展示出来。
说明:sonarqube7.9版本以上不支持mysql,支持postgresql、oracle、Microsoft SQLServer
环境:
系统:centos 7.2
工具:postgresql、sonarqube-8.2
安装方式:doucker
二、docker安装
1:前期准备,关闭iptables、selinux(做测试防止不必要的错误,线上环境误用)
[root@localhost ~]# iptables -F [root@localhost ~]# setenforce 0
2:开启转发功能
[root@localhost ~]# vim /etc/sysctl.conf # sysctl settings are defined through files in # /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/. # # Vendors settings live in /usr/lib/sysctl.d/. # To override a whole file, create a new file with the same in # /etc/sysctl.d/ and put new settings there. To override # only specific settings, add a file with a lexically later # name in /etc/sysctl.d/ and put new settings there. # # For more information, see sysctl.conf(5) and sysctl.d(5). net.ipv4.ip_forward=1 [root@localhost ~]# systemctl restart network
3:拉取postgresql镜像
[root@localhost ~]# docker pull postgres Using default tag: latest Trying to pull repository docker.io/library/postgres ... latest: Pulling from docker.io/library/postgres 68ced04f60ab: Pull complete 59f4081d08e6: Pull complete 74fc17f00df0: Pull complete 8e5e30d57895: Pull complete a1fd179b16c6: Pull complete 7496d9eb4150: Pull complete 0328931819fd: Pull complete 8acde85a664a: Pull complete 38e831e7d2d3: Pull complete 582b4ba3b134: Pull complete cbf69ccc1db5: Pull complete 1e1f3255b2e0: Pull complete c1c0cedd64ec: Pull complete 6adde56874ed: Pull complete Digest: sha256:110d3325db02daa6e1541fdd37725fcbecb7d51411229d922562f208c51d35cc Status: Downloaded newer image for docker.io/postgres:latest
4:启动postgresql容器
说明:
--name:指定容器别名
-e :设置用户和用户密码环境变量
-v:挂载数据存放目录,防止容器关闭数据丢失
-d:后台运行
[root@localhost ~]# mkdir -p /data/docker/postgressql/data [root@localhost ~]# docker run --name sonarqube_postgres -e POSTGRES_USER=sonar -e POSTGRES_PASSWORD=sonar -v /data/docker/postgressql/data:/var/lib/postgresql/data -d postgres 196ebb695e3b79054e0880dd1d9add39879379773d9fd87aefa963e684802b45 [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 196ebb695e3b postgres "docker-entrypoint..." 21 seconds ago Up 20 seconds 5432/tcp sonarqube_postgres
5:拉取sonarqube镜像
[root@localhost ~]# docker pull sonarqube Using default tag: latest Trying to pull repository docker.io/library/sonarqube ... latest: Pulling from docker.io/library/sonarqube 68ced04f60ab: Already exists 4874c5772968: Pull complete 8afa8e973e22: Pull complete d5c28bc4eb55: Pull complete d725e653d5dd: Pull complete 5a2166bcb54c: Pull complete 26fec801bfc2: Pull complete 570f1b7f4bb6: Pull complete 15c7236cf7b2: Pull complete Digest: sha256:f39e0b109cb13e9701f789707ea5d0234a86b44eff61b46a03cbf66401583b4a Status: Downloaded newer image for docker.io/sonarqube:latest
6:启动sonarqube容器
说明:
--name sonarqube:定义别名sonarqube
--link sonarqube_postgres:连接另一个sonarqube_postgres容器,让其可以访问对方容器
-e SONARQUBE_JDBC_USERNAME=sonar:设置连接sonarqube_postgres容器用户环境变量
-e SONARQUBE_JDBC_PASSWORD="sonar":设置连接sonarqube_postgres容器用户密码环境变量
-e SONARQUBE_JDBC_URL=jdbc:postgresql://sonarqube_postgres:5432/sonar:设置连接sonarqube_postgres容器地址
-p:宿主机端口9000映射容器的9000端口
-d:后台启动
[root@localhost ~]# mkdir -p /data/docker/sonarqube/data [root@localhost ~]# mkdir -p /data/docker/sonarqube/logs [root@localhost ~]# mkdir -p /data/docker/sonarqube/conf [root@localhost ~]# mkdir -p /data/docker/sonarqube/extensions [root@localhost ~]# docker run --name sonarqube --link sonarqube_postgres -e SONARQUBE_JDBC_USERNAME=sonar -e SONARQUBE_JDBC_PASSWORD="sonar" -e SONARQUBE_JDBC_URL=jdbc:postgresql://sonarqube_postgres:5432/sonar -p 9000:9000 -v /data/docker/sonarqube/conf:/opt/sonarqube/conf -v /data/docker/sonarqube/data:/opt/sonarqube/data -v /data/docker/sonarqube/logs:/opt/sonarqube/logs -v /data/docker/sonarqube/extensions:/opt/sonarqube/extensions -d sonarqube 627cefa36183607b3bd0524126e1b64c5e1c86daf5e03406ba5f5b238928a377 [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 627cefa36183 sonarqube "./bin/run.sh" 4 seconds ago Up 3 seconds 0.0.0.0:9000->9000/tcp sonarqube 196ebb695e3b postgres "docker-entrypoint..." 4 minutes ago Up 4 minutes 5432/tcp sonarqube_postgres
7:在浏览器访问IP:9000地址
说明:首次登陆默认用户名和密码:admin
8:登录之后,安装中文汉化包,并重启
9:重启后登录就可以看到汉化的界面了
记录每一天有趣的事情!!