Last active
January 27, 2023 20:18
-
-
Save erikrs92/3a6318b4714ecb6f008a2886deb4ddfa to your computer and use it in GitHub Desktop.
Install sonarqube + Proxy NGINX in Ubuntu 20.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Paso 1. Modificación de Parámetros | |
$ sudo nano /etc/sysctl.conf | |
#Agreagr en archivo | |
vm.max_map_count=262144 | |
fs.file-max=65536 | |
ulimit -n 65536 | |
ulimit -u 4096 | |
$ sudo nano /etc/security/limits.conf | |
#Agreagr en archivo | |
sonarqube - nofile 65536 | |
sonarqube — nproc 4096 | |
$ sudo reboot | |
# Paso 2. Instalación de Java OpenJDK 11 y otras herramientas que vamos a utilizar. | |
$ ubuntu@ubuntu:~$ sudo apt-get update -y | |
$ ubuntu@ubuntu:~$ sudo apt-get install wget unzip net-tools openjdk-11-jdk -y | |
$ ubuntu@ubuntu:~$ java -version | |
# Paso 3. Instalación de PostgreSQL:. Otro server. | |
# En el servudor PostgreSQL | |
$ sudo su postgres | |
psql | |
\connect devops; | |
CREATE SCHEMA sonarqube; | |
GRANT ALL ON SCHEMA sonarqube TO cicd; | |
# Paso 4. Instalación de Sonarqube | |
$ sudo wget (url zip zonar) https://binaries.sonarsource.com/Distribution/sonarqube/ | |
$ sudo unzip sonarqube-*.zip -d /opt | |
$ sudo mv /opt/sonarqube-* /opt/sonarqube | |
# Step 5: Configure SonarQube | |
$ sudo groupadd sonar | |
$ sudo useradd -c "user to run SonarQube" -d /opt/sonarqube -g sonar sonar | |
$ sudo chown sonar:sonar /opt/sonarqube -R | |
$ sudo nano /opt/sonarqube/conf/sonar.properties | |
$ sudo nano /opt/sonarqube/conf/sonar.properties | |
sonar.jdbc.username=cicd | |
sonar.jdbc.password=cide | |
sonar.jdbc.url=jdbc:postgresql://192.168.174.14:5432/devops?currentSchema=sonarqube | |
#sonar.search.javaOpts=-Xmx512m -Xms512m -XX:+HeapDumpOnOutOfMemoryError | |
#sonar.web.host=192.168.174.15 | |
#sonar.web.port=9000 | |
# Paso 6 dit the sonar script file and set RUN_AS_USER | |
$ sudo nano /opt/sonarqube/bin/linux-x86-64/sonar.sh | |
RUN_AS_USER=sonar | |
# Step 7: Configure Systemd service | |
$ sudo nano /etc/systemd/system/sonar.service | |
#Agregar en archivo | |
[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 | |
#Fin Agregar en archivo | |
$ sudo systemctl start sonar | |
$ sudo systemctl enable sonar | |
$ sudo systemctl status sonar | |
# Step 8: Access SonarQube | |
http://server_IP:9000 OR http://localhost:9000 | |
# Step 9:How to install and configure NGINX | |
$ sudo apt-get install nginx -y | |
$ sudo systemctl enable nginx | |
$ sudo systemctl start nginx | |
$ sudo nano /etc/nginx/sites-available/default | |
#Agregar en archivo | |
server{ | |
listen 80 default_server; | |
listen [::]:80 default_server; | |
#server_name sonar-master; | |
server_name _; | |
access_log /var/log/nginx/sonar.access.log; | |
error_log /var/log/nginx/sonar.error.log; | |
proxy_buffers 16 64k; | |
proxy_buffer_size 128k; | |
location / { | |
proxy_pass http://127.0.0.1:9000; | |
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; | |
proxy_redirect off; | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Proto http; | |
} | |
} | |
#Fin Agregar en archivo | |
$ sudo systemctl restart nginx | |
Extra. Habilitar ufw (con http) | |
$ sudo ufw enable | |
#enable http openssh port 22: | |
$ sudo ufw allow OpenSSH | |
#enable http ufw: | |
$ sudo ufw allow http | |
#ingresar a IP de servidor, y listo con puerto 80, sin puerto 9000. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment