카이도스의 Tech Blog

Sonarqube 설치 본문

CI CD

Sonarqube 설치

카이도스 2024. 2. 27. 12:22
728x90
반응형
  • OS : ubuntu 22.04
  • JAVA 17
  • sonarqube-9.9.4

기본 설치

# apt 최신화
sudo apt update && sudo apt upgrade -y

# sysctl.conf 설정
sudo vi /etc/sysctl.conf
vm.max_map_count=262144
fs.file-max=65536

sudo sysctl -p

# limits.conf 설정
sudo vi /etc/security/limits.conf
sonarqube  nofile   131072
sonarqube  nproc    8192

# Java 설치 및 확인
sudo apt-get install openjdk-17-jdk -y
java -version
openjdk version "17.0.9" 2023-10-17
OpenJDK Runtime Environment (build 17.0.9+9-Ubuntu-122.04)
OpenJDK 64-Bit Server VM (build 17.0.9+9-Ubuntu-122.04, mixed mode, sharing)

# 환경 설정
cat <<EOT>> ~/.bashrc
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
EOT
source ~/.bashrc

# Postgres 설치
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -
sudo apt install postgresql postgresql-contrib -y

# psql 실행 및 확인
sudo systemctl enable postgresql && sudo systemctl start postgresql
sudo systemctl status postgresql

# 패스워드 설정 후 로그
sudo passwd postgres
sudo -u postgres psql

# Postgres User 생성
create user sonar with password 'sonar';

# sonarqube용 DB 생성 및 권한 설정
CREATE DATABASE sonarqube OWNER sonar;
GRANT ALL PRIVILEGES ON DATABASE sonarqube to sonar;
\q

Sonarqube 설치

# zip install
sudo apt-get install zip -y
sudo wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-9.9.4.87374.zip
unzip sonarqube-9.9.4.87374.zip
sudo mv sonarqube-9.9.4.87374 /opt/sonarqube

# sonar group,user 생성
sudo groupadd sonar
sudo useradd -d /opt/sonarqube -g sonar sonar
sudo chown -R sonar:sonar /opt/sonarqube

# sonar configure settings
sudo vi /opt/sonarqube/conf/sonar.properties
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonarqube

# systemd 데몬 설정
sudo su -
cat <<EOT>> /etc/systemd/system/sonar.service
[Unit]
Description=SonarQube service
After=syslog.target network.target

[Service]
Type=forking

ExecStart=/opt/sonarqube/bin/linux-x86-64/sonar.sh start
ExecStop=/opt/sonarqube/bin/linux-x86-64/sonar.sh stop

User=sonar
Group=sonar
Restart=always

LimitNOFILE=65536
LimitNPROC=4096

[Install]
WantedBy=multi-user.target
EOT

# 실행 및 확인
sudo systemctl daemon-reload
sudo systemctl enable sonar && sudo systemctl start sonar
sudo systemctl status sonar

# 9000 port UI 접속(admin/admin)
curl http://10.10.x.177:9000

728x90
반응형

'CI CD' 카테고리의 다른 글

Sonarqube Upgrade  (2) 2024.02.27
jenkins 설치  (0) 2024.02.26
Comments