1、配置jdk11
#创建文件夹 mkdir /sheyu #上传jdk jdk-11.0.17_linux-x64_bin.tar.gz #创建文件夹 mkdir /usr/local/java #cp文件到/usr/local/java/jdk11 cp -r jdk-11.0.17 /usr/local/java/jdk11 #配置环境变量 vi /etc/profile JAVA_HOME=/usr/local/java/jdk11 JRE_HOME=$JAVA_HOME/jre export JRE_HOME PATH=$JAVA_HOME/bin:$PATH CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar export PATH JAVA_HOME CLASSPATH #使配置生效 source /etc/profile
2、安装postgresql
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 -y postgresql13-server sudo /usr/pgsql-13/bin/postgresql-13-setup initdb # sudo systemctl enable postgresql-13 # sudo systemctl start postgresql-13 # su - postgres psql # CREATE ROLE sonar; ALTER ROLE sonar WITH PASSWORD '123456'; CREATE DATABASE sonarqube; \c sonarqube; grant connect on database sonarqube to sonar ; alter role sonar with login; grant usage on schema public to sonar; grant select,insert,update,delete on all tables in schema public to sonar;
开启远程外联(使用root用户)
#修改配置文件 vi /var/lib/pgsql/13/data/postgresql.conf
修改:取消# 注释或者按照我这样新增 listen_addresses = ‘*’
修改:新增 host all all 0.0.0.0/0 trust 访问规则
vi /var/lib/pgsql/13/data/pg_hba.conf 修改:新增 host all all 0.0.0.0/0 trust 访问规则
重启服务,测试
sudo systemctl start postgresql-13
3、安装sonarqbue
#添加用户,密码sonar useradd sonar passwd sonar # mkdir /opt/sonarqube #上传sonarqubezip包 #mv到指定目录 mv sonarqube-9.7.1.62043.zip /opt/sonarqube/ chown -R sonar:sonar /opt/sonarqube/ vi /etc/sysctl.conf vm.max_map_count=524288 #新增 #立即生效 /sbin/sysctl -p vi /etc/security/limits.conf * soft nofile 131072 * hard nofile 131072 #重启服务
启动sonarqube
su - sonar cd /opt/sonarqube/ unzip sonarqube-9.7.1.62043.zip
修改conf/sonar.properties
cd sonarqube-9.7.1.62043/conf/ vi sonar.properties sonar.jdbc.username=sonar sonar.jdbc.password=123456 sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube sonar.web.host=0.0.0.0 sonar.web.port=9000启动sonarqube cd /opt/sonarqube/sonarqube-9.7.1.62043 ./bin/linux-x86-64/sonar.sh start
4、访问
http://139.198.180.46:9000/
#默认用户名密码 admin/admin
5、sonar-scanner安装配置
#下载sonarscanner包并上传服务器 mkdir -p /opt/scanner unzip -q sonar-scanner-cli-4.7.0.2747-linux.zip -d /opt/scanner/ ln -s /opt/scanner/sonar-scanner-4.7.0.2747-linux/ /opt/scanner/sonar_scanner_stable #配置sonarscanner环境变量 echo export SONAR_SCANNER_HOME=/opt/scanner/sonar_scanner_stable >> ~/.bash_profile echo export PATH=$SONAR_SCANNER_HOME/bin:$PATH >> ~/.bash_profile source ~/.bash_profile echo export SONAR_SCANNER_HOME=/opt/scanner/sonar_scanner_stable >> ~/.bash_profile echo export PATH=$SONAR_SCANNER_HOME/bin:$PATH >> ~/.bash_profile source ~/.bash_profile
#编辑配置文件
vi /opt/scanner/sonar_scanner_stable/conf/sonar-scanner.properties
sonar.host.url=http://localhost:9000 sonar.sourceEncoding=UTF-8
6、代码扫描
#上传代码并解压 unzip boot_docker-master.zip
#进入代码根目录 #创建sonar-project.properties vi sonar-project.properties # must be unique in a given SonarQube instance sonar.projectKey=docker_boot sonar.projectName=docker_boot # defaults to 'not provided' sonar.projectVersion=1.0 sonar.sources=src/main/java sonar.java.binaries=target/classes sonar.language=java sonar.sourceEncoding=UTF-8 sonar.host.url=http://139.198.180.46:9000 sonar.login=admin sonar.password=Admin889@zsz
执行代码扫描
cd boot_docker-master
sonar-scanner
7、登录sonarqube查看代码扫描结果
标签:opt,postgresql,scanner,sonarqube,aaaa,sonar,HOME From: https://www.cnblogs.com/zszitman/p/16863998.html