目录
一、prometheus的安装
使用容器安装
[root@prometheus ~]# docker run -d -p 9090:9090 --name sc-prom-1 prom/prometheus
源码安装
[root@prometheus ~]# mkdir /prometheus
[root@prometheus ~]# cd /prometheus
[root@prometheus prometheus]# rz
[root@prometheus prometheus]# ls
prometheus-2.29.1.linux-amd64.tar.gz
[root@prometheus prometheus]# tar xf prometheus-2.29.1.linux-amd64.tar.gz
#修改PATH环境变量
[root@prometheus prometheus]# PATH=$PATH:/prometheus/prometheus-2.29.1.linux-amd64
[root@prometheus prometheus]# which prometheus
/prometheus/prometheus-2.29.1.linux-amd64/prometheus
[root@prometheus prometheus]# vim /root/.bashrc
PATH=$PATH:/prometheus/prometheus-2.29.1.linux-amd64 #添加到末尾
[root@prometheus prometheus]# cd /prometheus/prometheus-2.29.1.linux-amd64
[root@prometheus prometheus-2.29.1.linux-amd64]# vim prometheus.yml
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
#添加需要监控的服务器的信息
- job_name: "manager"
static_configs:
- targets: ["192.168.10.230:9100"]
- job_name: "node1"
static_configs:
- targets: ["192.168.10.231:9100"]
- job_name: "node2"
static_configs:
- targets: ["192.168.10.232:9100"]
- job_name: "node3"
static_configs:
- targets: ["192.168.10.234:9100"]
#后台运行
[root@prometheus prometheus-2.29.1.linux-amd64]# nohup ./prometheus --config.file=/prometheus/prometheus-2.29.1.linux-amd64/prometheus.yml &
二、在被监控的机器上下载node_exporter
[root@manager ~]# rz
[root@manager ~]# mkdir /exporter
[root@manager ~]# mv node_exporter-1.2.2.linux-amd64.tar.gz /exporter/
[root@manager ~]# cd /exporter/
[root@manager exporter]#
解压软件
[root@manager exporter]# tar xf node_exporter-1.2.2.linux-amd64.tar.gz
[root@manager exporter]# ls
node_exporter-1.2.2.linux-amd64 node_exporter-1.2.2.linux-amd64.tar.gz
[root@manager exporter]# cd node_exporter-1.2.2.linux-amd64
[root@manager node_exporter-1.2.2.linux-amd64]# ls
LICENSE node_exporter NOTICE
修改PATH环境变量
[root@manager node_exporter-1.2.2.linux-amd64]# PATH=/exporter/node_exporter-1.2.2.linux-amd64:$PATH
[root@manager node_exporter-1.2.2.linux-amd64]# which node_exporter
/exporter/node_exporter-1.2.2.linux-amd64/node_exporter
[root@manager node_exporter-1.2.2.linux-amd64]#
[root@manager node_exporter-1.2.2.linux-amd64]# vim /root/.bashrc
PATH=/exporter/node_exporter-1.2.2.linux-amd64:$PATH 在末尾添加
执行软件
[root@manager node_exporter-1.2.2.linux-amd64]# nohup ./node_exporter --web.listen-address="0.0.0.0:9100" &
[1] 96546
[root@manager node_exporter-1.2.2.linux-amd64]# nohup: 忽略输入并把输出追加到'nohup.out'
[root@manager node_exporter-1.2.2.linux-amd64]#
[root@manager node_exporter-1.2.2.linux-amd64]# ps aux|grep node
root 96546 0.1 0.2 716440 10996 pts/1 Sl 10:38 0:00 ./node_exporter --web.listen-address=0.0.0.0:9100
root 96551 0.0 0.0 12348 1144 pts/1 S+ 10:38 0:00 grep --color=auto node
[root@manager node_exporter-1.2.2.linux-amd64]#
三、grafana的安装
[root@grafana ~]# cd /etc/yum.repos.d/
#grafana.repo结尾的文件的作用是用来找到对方的软件的仓库
[root@grafana yum.repos.d]# vim grafana.repo
[root@grafana yum.repos.d]# cat grafana.repo
[grafana]
name=grafana
baseurl=https://packages.grafana.com/enterprise/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
[root@grafana yum.repos.d]# yum install grafana -y
[root@grafana yum.repos.d]# systemctl start grafana-server
[root@grafana yum.repos.d]# ss -anplut|grep grafana
tcp LISTEN 0 128 *:3000 *:* users:(("grafana-server",pid=43438,fd=8))
[root@nfs-server yum.repos.d]#
四、测试效果