What i explain in this post
- Install Prometheus service
- Start the service wit systemd
- Keep it sercure wit nginx
Prerequisites
Server centos7 minimal
VPS 2G RAM 1 VCPU
Update OS end install minimal tool, turn off Selinux
yum update -y && yum install wget vim bash-completion git -y
setenforce 0
Installation
Add user witout root privilege prometheus
# Utente di sistema, senza home, impediamo al utente di fare login
sudo adduser prometheus --system \
--no-create-home \
--shell /sbin/nologin
cd /tmp
We can download the binary file from official website https://prometheus.io/download/
Check the last version end extract the file
wget https://github.com/prometheus/prometheus/releases/download/v1.4.1/prometheus-1.4.1.linux-amd64.tar.gz
tar -zxvf prometheus-1.4.1.linux-amd64.tar.gz
sudo mkdir /opt/prometheus
sudo mv prometheus-1.4.1.linux-amd64 /opt/prometheus/prometheus
Rename the dir to Prometheus end fix the permission
chown -R prometheus:prometheus /opt/prometheus
Systemd Unit
# vim /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus server
After=network.target
[Service]
WorkingDirectory=/opt/prometheus/prometheus
PermissionsStartOnly=true
ExecStartPre=/bin/chown -R prometheus:prometheus /opt/prometheus/prometheus
User=prometheus
ExecStart=/opt/prometheus/prometheus/prometheus \
-config.file=/opt/prometheus/prometheus/prometheus.yml \
-alertmanager.url=http://localhost:9093/alert-manager \
Restart=always
[Install]
WantedBy=multi-user.target
Keep the unit available, start Prometheus
systemctl daemon-reload
systemctl start prometheus.service && systemctl status prometheus.service
systemctl enable prometheus.service
This is the result
[root@prometheus ~]# systemctl start prometheus.service && systemctl status prometheus.service
● prometheus.service - Prometheus server
Loaded: loaded (/etc/systemd/system/prometheus.service; disabled; vendor preset: disabled)
Active: active (running) since lun 2016-10-10 21:06:18 UTC; 15ms ago
Process: 18120 ExecStartPre=/bin/chown -R prometheus:prometheus /opt/prometheus/prometheus (code=exited, status=0/SUCCESS)
Main PID: 18123 (prometheus)
CGroup: /system.slice/prometheus.service
└─18123 /opt/prometheus/prometheus/prometheus -config.file=/opt/prometheus/prometheus/prometheus.yml -alertmanager.url=http://localhost:9093/alert-manager
ott 10 21:06:18 prometheus systemd[1]: Starting Prometheus server...
ott 10 21:06:18 prometheus systemd[1]: Started Prometheus server.
[root@prometheus ~]# systemctl enable prometheus.service
Created symlink from /etc/systemd/system/multi-user.target.wants/prometheus.service to /etc/systemd/system/prometheus.service.
Now keep it in security wit nginx
yum -y install epel-release
yum -y install nginx httpd-tools
Create htpasswd file
htpasswd -c /etc/nginx/htpasswd.users admin
Edit the nignx conf this is my conf.
vi /etc/nginx/nginx.conf
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
}
Add file in conf.d
vim /etc/nginx/conf.d/prometheus.conf
server {
listen 80;
server_name prometheus.greco.cf;
auth_basic "Restricted Access";
auth_basic_user_file /etc/nginx/htpasswd.users;
location / {
proxy_pass http://localhost:9090;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Check Nginx conf
nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Start nginx daemon
systemctl restart nginx.service && systemctl status nginx.service
systemctl enable nginx.service
Install firewalld
yum install firewalld
systemctl start firewalld && systemctl enable firewalld && systemctl status firewalld
Configure firewalld
firewall-cmd --zone=public --add-service=https --permanent
firewall-cmd --reload
In your preference firewalld, iptables other is the same keep open http port configure you DNS or your /etc/hosts.