操作系统:centos 7
sonarqube版本:7.9.5
https://docs.sonarqube.org/7.9/
JDK: 11
postgresql: 10
1.安装数据库:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install yum install -y postgresql10-server
初始化数据库:
/usr/pgsql-10/bin/postgresql-10-setup initdb
启动数据库:systemctl start postgresql-10
修改数据库配置:
vim /var/lib/pgsql/10/data/pg_hba.conf
host all all 0.0.0.0/0 trust
vim /var/lib/pgsql/10/data/postgresql.conf
listen_addresses = '*'
重启数据库服务:systemctl restart postgresql-10
登录数据库,创建数据库:
su postgres
psql
修改管理员密码:
ALTER USER postgres with encrypted password 'xxxxxx';
创建用户:
create user sonarqube with password 'xxxxx';
创建数据库:
create database sonarqube owner sonarqube;
授权:
grant all on database sonarqube to sonarqube;
查看数据库:
\l
退出:
\q
2.系统参数优化配置:
创建普通用户:
useradd sonarqube
passwd sonarqube
sysctl -w vm.max_map_count=262144
sysctl -w fs.file-max=65536
ulimit -u 4096 sonarqube
ulimit -n 65536 sonarqube
vim /etc/security/limits.conf
@sonarqube hard nofile 65536
@sonarqube soft nofile 65536
3.上传sonarqube:
授权:
chown -R sonarqube.sonarqube /opt/sonarqube
修改配置:
cd /opt
grep -v "^#" sonarqube/conf/sonar.properties | grep -v "^$"
sonar.jdbc.username=sonarqube
sonar.jdbc.password=sonarqube
sonar.jdbc.url=jdbc:postgresql://127.0.0.1/sonarqube
sonar.web.host=0.0.0.0
sonar.web.port=9000
su sonarqube
配置环境变量:
vim ~/.bashrc
export PATH=/opt/sonarqube/bin:$PATH
source ~/.bashrc
启动服务:
sonar.sh start
查看状态:sonar.sh status
4.nginx反向代理:
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install -y nginx
sudo systemctl start nginx.service
sudo systemctl enable nginx.service
主配置文件:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 65535;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
server_tokens off;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
tcp_nodelay on;
keepalive_timeout 65;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1100;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 9;
gzip_types text/plain text/css application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_vary on;
include /etc/nginx/conf.d/*.conf;
}
vhost配置文件:
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://127.0.0.1:9000;
index index.htm index.html;
}
}
5.防火墙设置:
setenforce 0
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
6.SonarQube Runner
https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner
https://www.jianshu.com/p/7d1c0f5dcc78
https://docs.sonarqube.org/7.9/analysis/scan/sonarscanner/
这里有多种客户端方式扫描器
选择使用Jenkins的方式(https://docs.sonarqube.org/7.9/analysis/scan/sonarscanner-for-jenkins/)
或者maven的方式(https://docs.sonarqube.org/7.9/analysis/scan/sonarscanner-for-maven/)