Sonar Qube搭建

配置基本环境

关闭selinux和防火墙

setenforce 0

sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

systemctl stop firewalld && systemctl disable firewalld

设置主机名

hostnamectl --static set-hostname controller

创建目录

mkdir -p /home/application/{packages,data,apps,log,temp}

配置jdk

安装jdk

yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel

设置java环境变量

cat >> /etc/profile << EOF

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk

export PATH=$PATH:$JAVA_HOME/bin

EOF

使文件生效

source /etc/profile

配置数据库

安装MySQL yum源

yum -y install http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

安装MySQL

yum -y install mysql mysql-devel mysql-server mysql-utilities

数据库相关配置

mysql -u root -p

mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;

mysql> CREATE USER 'sonar'@'%' IDENTIFIED BY 'sonar';

mysql> FLUSH PRIVILEGES;

启动MySQL

systemctl start mysqld && systemctl enable mysqld

配置SonarQube

配置内核
vm.max_map_count 大于等于 262144
fs.file-max 大于等于 65536

cat >> /etc/sysctl.conf <<EOF

vm.max_map_count=262144

fs.file-max=65536

EOF

下载并解压SonarQube

wget -P /home/application/packages/ https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-7.4.zip

cd /home/application/packages

unzip sonarqube-7.4.zip -d ../apps/

配置sonar

vim conf/sonar.properties

修改数据库相关配置:Host Port Username Password

创建用户

useradd sonar

chown -R sonar.sonar /root/application/apps/sonarqube-7.4/

说明:sonarqube依赖于Elasticsearch插件,es插件不能用root运行,所以使用普通用户运行sonar,否则将会出现如下报错:

启动SonarQube

su sonar ./bin/linux-x86-64/sonar.sh start

检查启动状态

Web管理

默认由9000端口提供UI管理页面,在浏览器访问:http://ip:9000,界面如下(管理员密码:admin,密码:admin):

配置ldap

配置完成后重启SonarQube

su sonar ./bin/linux-x86-64/sonar.sh restart

参考链接:https://docs.sonarqube.org/latest/instance-administration/delegated-auth/
posted @ 2023-02-17 16:59  ThirteenAnimation  阅读(105)  评论(0编辑  收藏  举报