Need to Install Prometheus on CentOS 7?
At Bobcares, we often get requests from our customers to install Prometheus on CentOS 7 as a part of our Server Management Services.
Today let’s see how our Support Engineers get this done with ease.
Prerequisites for Installing Prometheus on CentOS 7
Prometheus is an open-source monitoring system developed by SoundCloud which stores all its data in a time-series database.
And it also allows a multi-dimensional data-model and a powerful query language ensuring to generate more accurate reports.
To set up this monitoring we need to have one 64-bit CentOS 7 server and a non-root sudo user.
Steps for Installing Prometheus
The following steps are used by our Support Techs to complete the setup.
1. Installing Prometheus Server
a. Create a new ‘prometheus’ user with the following command:
$ useradd -m -s /bin/bash prometheus
b. Then update the system with the following command:
$ yum update -y
c. After that we need to download the latest build of the Prometheus server and time-series database using the below command:
$ curl -LO "https://github.com/prometheus/prometheus/releases/download/0.16.0/prometheus-0.16.0.linux-amd64.tar.gz"
d. Then run the following commands:
$ mkdir ~/Prometheus
$ cd ~/Prometheus
$ tar -xvzf ~/Downloads/prometheus-0.16.0.linux-amd64.tar.gz
e. We can verify the installation with the following command:
$ ~/Prometheus/prometheus-0.16.0.linux-amd64/prometheus -version
The result can be seen as shown below:
prometheus, version 0.16.0 (branch: HEAD, revision: dcb8ba4) build user: julius@desktop build date: 20151009-23:51:17 go version: 1.5.1
2. Installing Node Exporter
Node Exporter exports lots of metrics such as disk I/O statistics, CPU load, memory usage, network statistics, and more in a format Prometheus understands.
We can install this by giving the following commands:
$ cd ~/Downloads && curl -LO "https://github.com/prometheus/node_exporter/releases/download/0.11.0/node_exporter-0.11.0.linux-amd64.tar.gz"
$ mkdir ~/Prometheus/node_exporter
$ cd ~/Prometheus/node_exporter
$ tar -xvzf ~/Downloads/node_exporter-0.11.0.linux-amd64.tar.gz
3. Running Node Exporter as a Service
a. We can use the following commands to run Node Exporter as a service.
$ sudo vi /etc/systemd/system/node_exporter.service
b. And add the following:
/etc/init/node_exporter.conf [Unit] Description=Node Exporter [Service] User=prometheus ExecStart=/home/prometheus/Prometheus/node_exporter/node_exporter [Install] WantedBy=default.target
c. Then provide the following commands:
$ sudo systemctl daemon-reload
$ sudo systemctl enable node_exporter.service
$ sudo systemctl start node_exporter.service
[Need assistance? We can help you!]
4. Starting Prometheus Server
Before we start Prometheus, we can create a configuration file for it called prometheus.yml.
$ cd ~/Prometheus/prometheus-0.16.0.linux-amd64
$ vi ~/Prometheus/prometheus-0.16.0.linux-amd64/prometheus.yml
And copy the following code into the file:
scrape_configs: - job_name: "node" scrape_interval: "15s" target_groups: - targets: ['localhost:9100']
Then open port 9090 for the Prometheus access using firewall-cmd commands below.
$ firewall-cmd --add-port=9090/tcp --permanent
$ firewall-cmd --reload
5. Installing PromDash
One way to visualize the data in Prometheus’s time-series database is to use PromDash.
We can install this by giving the following commands:
$ cd ~/Prometheus
$ sudo yum install git ruby ruby-devel sqlite-devel zlib-devel gcc gcc-c++ automake patch
$ git clone https://github.com/prometheus/promdash.git
$ cd ~/Prometheus/promdash
$ gem install bundler
$ bundle install --without mysql postgresql
As we are configuring PromDash to work with SQLite3, we must ensure to exclude the gems for MySQL and PostgreSQL using the –without parameter.
Once done, we can see the following messages:
. . . Your bundle is complete! Gems in the groups mysql and postgresql were not installed. Use `bundle show [gemname]` to see where a bundled gem is installed.
6. Setting Up the Rails Environment
We have to create a directory to store the SQLite3 databases associated with PromDash.
$ mkdir ~/Prometheus/databases
Type in the following to PromDash create a SQLite3 database called mydb.sqlite3 inside the databases directory:
$ echo "export DATABASE_URL=sqlite3:$HOME/Prometheus/databases/mydb.sqlite3" >> ~/.bashrc
To set the RAILS_ENV environment variable to production.:
$ echo "export RAILS_ENV=production" >> ~/.bashrc
Apply the changes we made to the .bashrc file.
$ . ~/.bashrc
Next, we need to create PromDash’s tables in the SQLite3 database using the rake tool.
$ rake db:migrate
For precompiling give the following:
$ rake assets:precompile
[Need assistance? We can help you!]
7. Starting and Configuring PromDash
Start the server as a daemon with the following command:
$ bundle exec thin start -d
We need to wait for a few seconds for the server to start and then check http://your_server_ip:3000/ to view PromDash’s homepage.
Then click New Server, then in the form, we can give any name for the Prometheus server. Set the URL field to http://your_server_ip:9090 and the Server type field to Prometheus.
Finally, click on Create Server to complete the configuration.
8. Creating a Dashboard
The dashboard already has one graph, but it needs to be configured.
Hovering over the graph’s header (which says Title) will reveal various icons that let you configure the graph.
To change its title, we can click on the Graph and Axis Settings icon (fourth from the left) and type in a new title in the Graph Title field.
Click on the Datasources icon, which is the second to the left, to add one or more expressions to the graph.
Then click Add Expression, and enter nodeprocsrunning.
Now click on the Refresh icon in the graph’s header to update the graph.
We can add more graphs by clicking on the Add Graph button at the bottom.
After making all the changes we can Save Changes to make the changes permanent.
[Need assistance? We can help you!]
Conclusion
In short, saw how to install Prometheus on CentOS 7 along with the method used by Support Engineers for the setup.
0 Comments