Last active
March 11, 2025 10:01
-
-
Save zguillez/508a08f1f2c15c7a7f8a5a9928c690fb to your computer and use it in GitHub Desktop.
Prometheus + Node_Exporter + Apache_Exporter + Grafana
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
| sudo apt update && apt upgrade -y | |
| sudo apt install apache2 php php-mysql mariadb-server unzip wget | |
| sudo apt install postfix apt-transport-https software-properties-common libapache2-mod-security2 | |
| sudo apt install -y php-curl php-imagick php-mbstring php-zip php-gd php-intl php-xml | |
| sudo snap install aws-cli --classic | |
| sudo a2enmod ssl | |
| sudo a2enmod headers | |
| sudo a2enmod status | |
| sudo a2enmod authz_core | |
| sudo a2enmod rewrite | |
| sudo systemctl restart apache2 | |
| ########################################################## | |
| wget https://github.com/prometheus/prometheus/releases/download/v2.47.0/prometheus-2.47.0.linux-arm64.tar.gz | |
| tar xvfz prometheus-2.47.0.linux-arm64.tar.gz | |
| sudo mv prometheus-2.47.0.linux-arm64 /opt/prometheus | |
| sudo useradd --no-create-home --shell /bin/false prometheus | |
| sudo chown -R prometheus:prometheus /opt/prometheus | |
| sudo vim /opt/prometheus/prometheus.yml | |
| ----------------------------------- | |
| global: | |
| scrape_interval: 15s | |
| scrape_configs: | |
| - job_name: 'prometheus' | |
| static_configs: | |
| - targets: ['localhost:9090'] | |
| - job_name: 'node_exporter' | |
| static_configs: | |
| - targets: ['localhost:9100'] | |
| - job_name: 'apache_exporter' | |
| static_configs: | |
| - targets: ['localhost:9117'] | |
| ----------------------------------- | |
| sudo vim /etc/systemd/system/prometheus.service | |
| ----------------------------------- | |
| [Unit] | |
| Description=Prometheus | |
| Wants=network-online.target | |
| After=network-online.target | |
| [Service] | |
| User=prometheus | |
| Group=prometheus | |
| ExecStart=/opt/prometheus/prometheus --config.file /opt/prometheus/prometheus.yml --storage.tsdb.path /opt/prometheus/data | |
| [Install] | |
| WantedBy=multi-user.target | |
| ----------------------------------- | |
| sudo systemctl daemon-reload | |
| sudo systemctl enable prometheus | |
| sudo systemctl start prometheus | |
| sudo journalctl -u prometheus | |
| ########################################################## | |
| wget https://github.com/prometheus/node_exporter/releases/download/v1.6.1/node_exporter-1.6.1.linux-arm64.tar.gz | |
| tar xvfz node_exporter-1.6.1.linux-arm64.tar.gz | |
| sudo mv node_exporter-1.6.1.linux-arm64/node_exporter /usr/local/bin/ | |
| sudo useradd --no-create-home --shell /bin/false node_exporter | |
| sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter | |
| sudo vim /etc/systemd/system/node_exporter.service | |
| ----------------------------------- | |
| [Unit] | |
| Description=Node Exporter | |
| Wants=network-online.target | |
| After=network-online.target | |
| [Service] | |
| User=node_exporter | |
| Group=node_exporter | |
| ExecStart=/usr/local/bin/node_exporter | |
| [Install] | |
| WantedBy=multi-user.target | |
| ----------------------------------- | |
| sudo systemctl daemon-reload | |
| udo systemctl enable node_exporter | |
| sudo systemctl start node_exporter | |
| sudo journalctl -u node_exporter | |
| ########################################################## | |
| wget https://github.com/Lusitaniae/apache_exporter/releases/download/v1.0.9/apache_exporter-1.0.9.linux-arm64.tar.gz | |
| tar xvf apache_exporter-1.0.9.linux-arm64.tar.gz | |
| sudo mv apache_exporter-1.0.9.linux-arm64/apache_exporter /usr/local/bin/ | |
| sudo chown root:root /usr/local/bin/apache_exporter | |
| sudo useradd --no-create-home --shell /bin/false apache_exporter | |
| sudo mkdir -p /etc/apache_exporter | |
| sudo vim /etc/apache_exporter/apache_exporter.yml | |
| ----------------------------------- | |
| access_log_path: /var/log/apache2/access.log | |
| error_log_path: /var/log/apache2/error.log | |
| web.listen-address: :9117 | |
| web: | |
| telemetry-path: /metrics | |
| ----------------------------------- | |
| sudo chown apache_exporter:apache_exporter /etc/apache_exporter/apache_exporter.yml | |
| sudo vim /etc/systemd/system/apache_exporter.service | |
| ----------------------------------- | |
| [Unit] | |
| Description=Apache Exporter | |
| Wants=network-online.target | |
| After=network-online.target | |
| [Service] | |
| User=apache_exporter | |
| Group=apache_exporter | |
| ExecStart=/usr/local/bin/apache_exporter --scrape_uri=http://127.0.0.1/server-status?auto | |
| Restart=always | |
| [Install] | |
| WantedBy=multi-user.target | |
| ----------------------------------- | |
| sudo vim /etc/apache2/sites-available/000-default.conf | |
| ----------------------------------- | |
| <VirtualHost *:80> | |
| ServerName domain.com | |
| ServerAlias www.domain.com | |
| RewriteEngine On | |
| RewriteCond %{REQUEST_URI} !^/server-status$ | |
| RewriteRule ^(.*)$ https://domain.com/$1 [R=301,L] | |
| <Location /server-status> | |
| SetHandler server-status | |
| # Require all granted | |
| Require local | |
| Require ip 127.0.0.1 | |
| </Location> | |
| </VirtualHost> | |
| <VirtualHost *:443> | |
| ServerName domain.com | |
| ServerAlias www.domain.com | |
| DocumentRoot /var/www/html | |
| SSLEngine on | |
| SSLCertificateFile /etc/letsencrypt/live/domain.com/cert.pem | |
| SSLCertificateKeyFile /etc/letsencrypt/live/domain.com/privkey.pem | |
| SSLCertificateChainFile /etc/letsencrypt/live/domain.com/chain.pem | |
| ErrorLog ${APACHE_LOG_DIR}/error.log | |
| CustomLog ${APACHE_LOG_DIR}/access.log combined | |
| <Directory /var/www/html> | |
| Options Indexes FollowSymLinks | |
| AllowOverride All | |
| Require all granted | |
| </Directory> | |
| </VirtualHost> | |
| ----------------------------------- | |
| sudo vim /etc/apache2/apache2.conf | |
| ----------------------------------- | |
| ... | |
| <Directory /var/www/html/> | |
| Options -Indexes +FollowSymLinks | |
| AllowOverride None | |
| Require all granted | |
| </Directory> | |
| ... | |
| ----------------------------------- | |
| sudo systemctl restart apache2 | |
| systemctl status apache2.service | |
| journalctl -xeu apache2.service | |
| sudo vim /var/www/html/.htaccess | |
| ----------------------------------- | |
| ... | |
| RewriteCond %{REQUEST_URI} !^(/(.+/)?feed/?|/(index.php/)?wp-json(/.*|$)|/server-status)$ [NC] | |
| ... | |
| ----------------------------------- | |
| sudo -u apache_exporter curl http://127.0.0.1/server-status?auto | |
| sudo systemctl daemon-reload | |
| sudo systemctl enable apache_exporter | |
| sudo systemctl start apache_exporter | |
| sudo systemctl status apache_exporter | |
| sudo journalctl -u apache_exporter | |
| ########################################################## | |
| wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add - | |
| echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee /etc/apt/sources.list.d/grafana.list | |
| sudo apt-get install grafana | |
| sudo systemctl daemon-reload | |
| sudo systemctl enable grafana-server | |
| sudo systemctl start grafana-server | |
| sudo journalctl -u grafana-server | |
| ########################################################## | |
| sudo systemctl daemon-reload | |
| sudo systemctl restart prometheus | |
| sudo systemctl restart node_exporter | |
| sudo systemctl restart apache_exporter | |
| sudo systemctl restart grafana-server | |
| sudo systemctl restart apache2 | |
| ########################################################## | |
| # DASHBOARDS: 1860 - 17898 - 11074 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment