企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[root@jenkins ~]# cd /usr/local/src/ [root@jenkins src]# wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-6.7.zip [root@jenkins src]# unzip sonarqube-6.7.zip [root@jenkins src]# mv sonarqube-6.7 /usr/local/ [root@jenkins src]# ln -s /usr/local/sonarqube-6.7/ /usr/local/sonarqube 准备sonar数据库并授权用户 注意(要求mysql数据库版本要在5.6及以上) mysql> create database sonar character set utf8 collate utf8_general_ci; mysql> grant all on sonar.* to 'sonar'@'localhost' identified by 'Sonar@123321'; mysql> grant all on sonar.* to 'sonar'@'%' identified by 'Sonar@123321'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) 配置sonar [root@jenkins src]# cd /usr/local/sonarqube/conf/ [root@jenkins conf]# ls sonar.properties wrapper.conf [root@jenkins conf]# vim sonar.properties sonar.jdbc.username=sonar sonar.jdbc.password=Sonar@123321 sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false sonar.web.host=10.2.11.248 # Web context. When set, it must start with forward slash (for example /sonarqube). # The default value is root context (empty value). #sonar.web.context= # TCP port for incoming HTTP connections. Default value is 9000. sonar.web.port=9000 配置Java访问数据库驱动(可选) 默认情况Sonar有自带的嵌入的数据库,那么你如果使用类是Oracle数据库,必须手动复制驱动类到${SONAR_HOME}/extensions/jdbc-driver/oracle/目录下,其它支持的数据库默认提供了驱动。其它数据库的配置可以参考官方文档: http://docs.sonarqube.org/display/HOME/SonarQube+Platform 启动sonar [root@jenkins logs]# visudo (授权www用户) [root@jenkins logs]# chown -R www.www /usr/local/sonarqube-6.7/ [root@jenkins logs]# su - www [www@jenkins ~]$ cd /usr/local/sonarqube/bin/ [www@jenkins bin]$ ./linux-x86-64/sonar.sh start Starting SonarQube... Started SonarQube. 二)安装插件 ![](https://box.kancloud.cn/e22a23857e8d589bb9d535613c280d68_1356x586.png) 三)安装sonar scanner 官网:https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner [root@jenkins ~]# cd /usr/local/src/ [root@jenkins src]# wget https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.0.3.778-linux.zip [root@jenkins src]# mv sonar-scanner-3.0.3.778-linux/ /usr/local/ [root@jenkins src]# ln -s /usr/local/sonar-scanner-3.0.3.778-linux/ /usr/local/sonar-scanner [root@jenkins src]# cd /usr/local/sonar-scanner [root@jenkins sonar-scanner]# ll total 16 drwxr-xr-x. 2 root root 4096 May 12 2017 bin drwxr-xr-x. 2 root root 4096 Dec 27 23:21 conf drwxr-xr-x. 4 root root 4096 Dec 27 23:22 jre drwxr-xr-x. 2 root root 4096 Dec 27 23:21 lib 配置 [root@jenkins src]# cd /usr/local/sonar-scanner [root@jenkins sonar-scanner]# ll total 16 drwxr-xr-x. 2 root root 4096 May 12 2017 bin drwxr-xr-x. 2 root root 4096 Dec 27 23:21 conf drwxr-xr-x. 4 root root 4096 Dec 27 23:22 jre drwxr-xr-x. 2 root root 4096 Dec 27 23:21 lib [root@jenkins sonar-scanner]# cd conf/ [root@jenkins conf]# ll total 4 -rw-r--r--. 1 root root 295 May 12 2017 sonar-scanner.properties [root@jenkins conf]# pwd /usr/local/sonar-scanner/conf [root@jenkins conf]# vim sonar-scanner.properties #Configure here general information about the environment, such as SonarQube DB details for example #No information about specific project should appear here #----- Default SonarQube server sonar.host.url=http://localhost:9000 #----- Default source code encoding sonar.sourceEncoding=UTF-8 #-----Global database settings sonar.jdbc.username=sonar sonar.jdbc.password=Sonar@123321 #-----MySQL sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8