SonarQube安装
https://docs.sonarqube.org/6.7/RunningSonarQubeasaServiceonLinux.html
主机配置:CPU 2C 内存>4G
-
数据库安装
-
安装依赖包
yum install vim gcc gcc-c++ wget autoconf net-tools lrzsz iotop lsof iotop bash-completion curl policycoreutils openssh-clients postfix -y
-
安装数据库5.6版本
tar -xvf mysql-5.6.48-linux-glibc2.12-x86_64.tar.gz mv mysql-5.6.48-linux-glibc2.12-x86_64 /usr/local/mysql groupadd mysql useradd -r -g mysql mysql cd /usr/local/mysql/ mkdir ./data/mysql chown -R mysql:mysql ./ ./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/mysql cp support-files/mysql.server /etc/init.d/mysqld chmod 755 /etc/init.d/mysqld cp support-files/my-default.cnf /etc/my.cnf chown -R mysql:mysql /usr/local/mysql/* vim /etc/init.d/mysqld basedir=/usr/local/mysql/ datadir=/usr/local/mysql/data/mysql service mysqld start
-
测试连接数据库
./bin/mysql -uroot create database sonar default character set utf8 collate utf8_general_ci; GRANT ALL PRIVILEGES ON sonar.* TO 'sonar'@'172.24.77.%' IDENTIFIED BY '123456'; mysql -usonar -p123456 -h172.24.77.242
-
修改配置环境变量
vim /etc/profile export PATH=$PATH:/usr/local/mysql/bin source /etc/profile ##给sonar账户开启远程登陆 mysql -uroot GRANT ALL PRIVILEGES ON *.* TO 'sonar'@'172.24.77.241' IDENTIFIED BY '123456' WITH GRANT OPTION;
-
-
部署SonarQube
-
确认JAVA版本为1.8以上
yum install java-1.8.0-openjdk -y java -version openjdk version "1.8.0_262"
-
修改内核参数
vim /etc/sysctl.conf vm.max_map_count=262144 fs.file-max=65536 vim /etc/security/limits.conf sonarqube - nofile 65536 sonarqube - nproc 2048 useradd -s /bin/bash -m sonarqube reboot su - sonarqube [sonarqube@noteb ~]$ ulimit -n 65536
-
安装并修改配置
yum install unzip -y unzip sonarqube-6.7.7.zip ln -sv /usr/local/src/sonarqube-6.7.7 /usr/local/sonarqube chown sonarqube.sonarqube /usr/local/src/sonarqube-6.7.7 /usr/local/sonarqube -R su - sonarqube cd /usr/local/sonarqube vim /usr/local/sonarqube/conf/sonar.properties # The schema must be created first. sonar.jdbc.username=sonar sonar.jdbc.password=123456 sonar.jdbc.url=jdbc:mysql://172.24.77.241:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false sonar.web.host=0.0.0.0 sonar.web.port=9000 #查看修改的配置 grep "^[a-Z]" conf/sonar.properties /usr/local/sonarqube/bin/linux-x86-64/sonar.sh start tail -f /usr/local/sonarqube/logs/sonar.log
-
-
登录页面
http://172.24.77.242:9000 admin admin
-
安装中文插件
-
查看插件安装位置
https://github.com/SonarQubeCommunity/sonar-l10n-zh/releases?after=sonar-l10n-zh-plugin-1.25
-
yum install -y git
cd /usr/local/sonarqube/extensions/plugins/
wget https://github.com/SonarQubeCommunity/sonar-l10n-zh/releases/download/sonar-l10n-zh-plugin-1.19/sonar-l10n-zh-plugin-1.19.jar
2. 重启服务
```
su - sonarqube
/usr/local/sonarqube/bin/linux-x86-64/sonar.sh restart
#如果出现报错运行以下命令
rm -f /usr/local/src/sonarqube/temp
```
3. 登录
![](https://s4.51cto.com/images/blog/202009/21/55864aba1a17eade587913809e6454bd.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
-
部署扫描器,在Jenkis服务器
-
部署sonar-scanner
unzip sonar-scanner-cli-4.0.0.1744-linux.zip mv sonar-scanner-4.0.0.1744-linux /usr/local/src ln -sv /usr/local/src/sonar-scanner-4.0.0.1744-linux /usr/local/sonar-scanner vim /usr/local/sonar-scanner/conf/sonar-scanner.properties sonar.host.url=http://172.24.77.242:8800 sonar.sourceEncoding=UTF-8 sonar.jdbc.username=sonar sonar.jdbc.password=123456 sonar.jdbc.url=jdbc:mysql://172.24.77.242:3306/sonar?useUnicode=true&character Encoding=utf8
-
准备测试代码
cd /usr/local/src/ #上传测试代码至Jenkins服务器 unzip sonar-examples-master.zip
-
扫描代码
cd /usr/local/src/sonar-examples-master/projects/languages/php/php-sonar-runner /usr/local/sonar-scanner/bin/sonar-scanner
-
-
Jenkins关联至SonarQube
-
安装sonarqube插件
-
系统管理--系统配置
-
-
配置jenkins关联sonar scanner
-
系统管理--全局工具配置--新增Sonar-scanner
-
选择自动安装
-
选择手动安装
-
配置扫描
- 修改任务--test1--配置
#Analysis properties sonar.projectKey=test-demo1 sonar.projectName=test-demo1 sonar.projectVersion=1.0 sonar.sources=./ sonar.language=php sonar.sourceEncoding=UTF-8
-
构建项目并测试soner scanner是否生效
立即构建
-
-
查看扫描结果
来源:oschina
链接:https://my.oschina.net/u/4364022/blog/4652871