Prometheus + Node_exporter + Grafana implement monitoring host
If there is no installation-related configuration, you must first install and configure it. The environment is based on Linux. The relevant environment configuration of the virtual machine is given at the end of the article. Now we will explain the installation and use of Prometheus + Node_exporter + Grafana.
1. Prometheus installation
Although Prometheus can be installed locally on a virtual machine, the download speed may be slow, and it is relatively troublesome to find the configuration later, and it is not convenient to operate during the configuration file process. Therefore, in this article, I use the installation package to configure the corresponding environment. On the other hand, to facilitate the operation of virtual machine instructions and file transfer, I use remote control to operate.
1.FinalShell remote control connection
- Enable remote login in shared services on the virtual machine
-
The virtual machine Ubuntu does not have the ssh server installed by default and needs to be installed.
apt-get install openssh-server
-
Allow remote use of root account ssh to connect to the machine, modify the configuration vim /etc/ssh/sshd_config and the content is as follows
#PermitRootLogin prohibit-password
PermitRootLogin yes
-
Need to restart the system or sshd service
sudo /etc/init.d/ssh stop
sudo /etc/init.d/ssh start
sudo service ssh restart -
System sshd is enabled by default
sudo systemctl enable ssh
-
After checking the virtual machine IP address, open FinalShell to create a new SS connection.
-
After the connection is successful, you can operate it in the terminal
-
Select usr/local/ as the installation directory. All three installation packages are installed and configured in this directory. At the same time, right-click the corresponding file under the terminal to transfer the file to Linux through Windows.
2. Configure the Go environment
-
Since Prometheus is developed in the go language, you need to install the go environment on the monitoring host before installing Prometheus. Download link: https://pan.baidu.com/s/1gefGeXmoFmjGxSGxgCuQfw Extraction code: cz6l
-
Unzip the installation package:
tar -xvf go1.13.1.linux-amd64.tar.gz
-
Configure environment variables
# vim /etc/profile //Add in the last line export GOROOT=/usr/local/go export PATH=$PATH:$GOROOT/bin // source wq after saving and exiting # source /etc/profile
3. Install Prometheus
Download link: Index of /github-release/prometheus/prometheus/ | Tsinghua University Open Source Software Mirror Station | Tsinghua Open Source Mirror
-
Upload the downloaded installation package to the /usr/local directory
-
Unzip and rename to prometheus
tar -xvf prometheus-2.47.2.linux-amd64.tar.gz
mv prometheus-2.47.2.linux-amd64/ prometheus -
Create services service file
vim /etc/systemd/system/prometheus.service [Unit] Description=prometheus After=network.target [Service] Type=simple ExecStart=/usr/local/prometheus --config.file=/usr/local/prometheus.yml Restart=on-failure [Install] WantedBy=multi-user.target
-
Start Prometheus and set the service to start automatically at boot
#Reload configuration file systemctl daemon-reload #Start service systemctl start prometheus.service #View status systemctl status prometheus.service #The service starts automatically after booting, no need to start it every time systemctl enable prometheus.service
-
If the status is displayed normally, then there is no problem with the configuration, as shown in the following figure.
-
Visit http:127.0.0.1:9090 in the virtual machine browser to view
2. Install Node_exporter
Download address: Index of nodejs-local (huaweicloud.com)
-
After downloading, upload the file to the /usr/local directory
-
Unzip the installation package:
tar -xvf node_exporter-0.17.0.linux-amd64.tar.gz
-
Configure environment variables
vim /etc/systemd/system/node_exporter.service [Unit] Description=node_exporter Monitoring System Documentation=node_exporter Monitoring System [Service] ExecStart=/usr/local/node_exporter --web.listen-address=:9100 [Install] WantedBy=multi-user.target
-
Set up auto-start at boot
#Set auto-start at boot systemctl daemon-reload systemctl start node_exporter.service systemctl status node_exporter.service systemctl enable node_exporter.service
-
Status shows normal activity and can be accessed through the virtual machine browser
3. Install Grafana visualization panel
Download address: Index of /grafana/apt/dists/beta/ | Tsinghua University Open Source Software Mirror Station | Tsinghua Open Source Mirror
- After downloading, upload the file to the /usr/local directory
-
Unzip and rename
tar -xvf grafana-enterprise-10.0.2.linux-amd64.tar.gz
mv grafana-enterprise-10.0.2.linux-amd64.tar.gz grafana
-
Configure environment variables to automatically start vim /usr/lib/systemd/system/grafana.service at boot
[Unit] Description=Grafana After=network.target [Service] Type=notify ExecStart=/data/grafana/bin/grafana-server -homepath /data/grafana Restart=on-failure [Install] WantedBy=multi-user.target
-
Configuration related instructions
#Reload service configuration file systemctl daemon-reload #Start grafana systemctl start grafana.service #View grafana status systemctl status grafana.service #Set auto-start at boot systemctl enable grafana.service #restartgrafana systemctl restart grafana.service #stopgrafana systemctl stop grafana.service
-
To access Grafana, the access address is http:127.0.0.1:3000, and the initial account password is admin and admin (j remember to change it)
4. Monitor multiple Linux servers
-
First, the monitored host must install node_exporter to provide a data interface. The configuration process is the same as configuring Node_exporter on the host. Please refer to the above.
-
Configure the prometheus server to pull node information
vim /usr/local/prometheus/prometheus.yml
-
Add content at the end of the file
- job_name: 'linux' static_configs: - targets: ['192.168.45.143:9100','192.168.45.22:9100']
-
Restart prometheus after the addition is complete
systemctl restart prometheus.service
-
At this time, if the corresponding port is not open and you still cannot see the data, the added hosts need to open the corresponding 9100 port so that Prometheus can pull the data.
firewall-cmd –zone=public –add-port=9100/tcp –permanent
Open specified port firewall-cmd --zone=public --add-port=1935/tcp --permanent Command meaning: --zone #scope --add-port=1935/tcp #Add port, the format is: port/communication protocol --permanent #Permanently effective, without this parameter it will be invalid after restarting
- Get host data
5. Grafana adds data source display
-
Select data source and configure
-
Visualize templates and import them
-
Finally the monitoring data can be displayed
That’s all I recorded today, I hope it helps!