<\/span><\/h2>\n\n\n\nFirst, log in to your Ubuntu 20.04 server via SSH as the root user:<\/p>\n\n\n\n
ssh root@IP_ADDRESS -p PORT_NUMBER<\/pre>\n\n\n\nDon\u2019t forget to replace IP_Address<\/strong> and Port_Number<\/strong> with your server\u2019s actual IP address and the SSH port number. Also, you should replace \u2018root\u2019 with the username of the admin account if needed.<\/p>\n\n\n\nOnce you are in, run the following commands to update the package index and upgrade all installed packages to the latest available version<\/p>\n\n\n\n
apt-get update \napt-get upgrade<\/pre>\n\n\n\n<\/span>Step 2. Creating Prometheus System Users and Directory<\/span><\/h2>\n\n\n\nThe Prometheus server requires a service user account to run. You can name your user however you like, but we will create a user named prometheus<\/code>. This user will be a system user (-r<\/code>) who will be unable to get a shell (-s \/bin\/false<\/code>)<\/p>\n\n\n\nuseradd --no-create-home -rs \/bin\/false prometheus<\/pre>\n\n\n\nAlso, we need to create directories for configuration files and other Prometheus data.<\/p>\n\n\n\n
mkdir \/etc\/prometheus\nmkdir \/var\/lib\/prometheus<\/pre>\n\n\n\nNow we will have to update the group and user ownership on the newly created directories.<\/p>\n\n\n\n
chown prometheus:prometheus \/etc\/prometheus<\/pre>\n\n\n\nchown prometheus:prometheus \/var\/lib\/prometheus<\/pre>\n\n\n\n<\/span>Step 3. Download Prometheus Binary File<\/span><\/h2>\n\n\n\nPrometheus is included by default on the Ubuntu 20.04 repositories.<\/p>\n\n\n\n
apt-cache policy prometheus<\/pre>\n\n\n\nprometheus:\nInstalled: (none)\nCandidate: 2.15.2+ds-2\nVersion table:\n2.15.2+ds-2 500\n500 http:\/\/us.archive.ubuntu.com\/ubuntu focal\/universe amd64 Packages<\/pre>\n\n\n\nHowever, the Prometheus release version provided by the default Ubuntu repositories may not be up-to-date. At the time of writing this article, the latest stable version of Prometheus is 2.30.3.<\/p>\n\n\n\n
But before downloading, visit the official Prometheus downloads page and check if there is a new version available.<\/p>\n\n\n\n
You can download it using the following command:<\/p>\n\n\n\n
wget https:\/\/github.com\/prometheus\/prometheus\/releases\/download\/v2.30.3\/prometheus-2.30.3.linux-amd64.tar.gz<\/pre>\n\n\n\nOnce the tarball is downloaded, verify the tarball checksum with the following command:<\/p>\n\n\n\n
sha256sum prometheus-2.30.3.linux-amd64.tar.gz<\/pre>\n\n\n\nYou should see an output that looks similar to the one below:<\/p>\n\n\n\n
1ccd386d05f73a98b69aa5e0ed31fffac95cd9dadf7df1540daf2f182c5287e2 prometheus-2.30.3.linux-amd64.tar.gz<\/pre>\n\n\n\nCompare the hash value from the above output to the checksum value on the Prometheus download page. If they match, that means the file\u2019s integrity is validated.<\/p>\n\n\n\n
Now you have successfully downloaded the Prometheus file and now you will extract it to the \/opt<\/code><\/strong> directory using the tar command:<\/p>\n\n\n\ntar xvzf prometheus-2.30.3.linux-amd64.tar.gz -C \/opt<\/pre>\n\n\n\nNext, you need to copy the binary files to \/usr\/local\/bin<\/code> directory and fix the permissions. This is done with the following commands:<\/p>\n\n\n\nmv \/opt\/prometheus-2.30.3.linux-amd64\/prometheus \/opt\/prometheus-2.30.3.linux-amd64\/promtool \/usr\/local\/bin\/\nchown prometheus:prometheus \/usr\/local\/bin\/prometheus \/usr\/local\/bin\/promtool\n<\/pre>\n\n\n\nAlso, we need to copy the consoles<\/code> and console_libraries<\/code> directories to Prometheus configuration directory, \/etc\/prometheus<\/code><\/p>\n\n\n\nmv \/opt\/prometheus-2.30.3.linux-amd64\/consoles \/opt\/prometheus-2.30.3.linux-amd64\/console_libraries \/etc\/prometheus\/\nchown -R prometheus:prometheus \/etc\/prometheus\/consoles \/etc\/prometheus\/console_libraries<\/pre>\n\n\n\n<\/span>Step 4: Create Prometheus Configuration file<\/span><\/h2>\n\n\n\nPrometheus configuration file has been prepared and available on the extracted archive folder, and you need just to copy it to the Prometheus configuration \/etc\/prometheus<\/code> directory.<\/p>\n\n\n\nmv \/opt\/prometheus-2.30.3.linux-amd64\/prometheus.yml \/etc\/prometheus\/prometheus.yml\nchown prometheus:prometheus \/etc\/prometheus\/prometheus.yml<\/pre>\n\n\n\nThe content of theprometheus.yml<\/code> file:<\/p>\n\n\n\n# my global config\nglobal:\nscrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.\nevaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.\n# scrape_timeout is set to the global default (10s).\n\n# Alertmanager configuration\nalerting:\nalertmanagers:\n- static_configs:\n- targets:\n# - alertmanager:9093\n\n# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.\nrule_files:\n# - \"first_rules.yml\"\n# - \"second_rules.yml\"\n\n# A scrape configuration containing exactly one endpoint to scrape:\n# Here it's Prometheus itself.\nscrape_configs:\n# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.\n- job_name: \"prometheus\"\n\n# metrics_path defaults to '\/metrics'\n# scheme defaults to 'http'.\n\nstatic_configs:\n- targets: [\"localhost:9090\"]<\/pre>\n\n\n\nThe configuration is set up to scrape every 15 seconds and Prometheus listens on port 9090<\/code>.<\/p>\n\n\n\n