Centos8安装 Prometheus2.31.1监控Go1.17.5\Python3.8.10\Mysql8.0.27\Node\Grafana8.3.3(亲测有效)

5 篇文章 0 订阅
2 篇文章 0 订阅

一、更换华为源

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-8-reg.repo
yum clean all 
yum makecache
cd /etc/yum.repos.d
mv CentOS-Base.repo CentOS-Base.repo.b

二、更新套件、库

yum  update -y
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
yum install libffi-devel -y
yum install -y gcc gcc-c++ openssl-devel zlib-devel
yum -y install  gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel firewalld autoconf automake

三、安装软件

1、go安装

下载:wget https://dl.google.com/go/go1.17.5.linux-amd64.tar.gz
压缩到/usr/local目录下:tar -C /usr/local -xzf go1.17.5.linux-amd64.tar.gz

配置go

vi /etc/profile
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=/root/go
export PATH=$PATH:$GOPATH/BIN

source /etc/profile

vi /etc/profile.d/golang.sh
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=/root/go
export PATH=$PATH:$GOPATH/BIN

执行 source /etc/profile.d/golang.sh

测试golang执行文件:vim Hello.go

package main
import "fmt"
 
func main() {
 
    fmt.Println("hello world")
    var str string = "hello agin"
    fmt.Println(str)
 
}

保存并执行:go run ./Hello.go

2、安装Prometheus2.31.1监控

下载:wget https://github.com/prometheus/prometheus/releases/download/v2.31.1/prometheus-2.31.1.linux-amd64.tar.gz
解压到/usr/local/目录下:tar xf prometheus-2.31.1.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv prometheus-2.31.1.linux-amd64/ prometheus
useradd -M -s /sbin/nologin prometheus
mkdir -p /data/prometheus
chown -R prometheus.prometheus /usr/local/prometheus /data/prometheus

配置service文件:vim /usr/lib/systemd/system/prometheus.service

[Unit]
Description=The Prometheus Server
After=network.target

[Service]
Restart=on-failure

Type=simple
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
RestartSec=15s

[Install]
WantedBy=multi-user.target

保存并执行:systemctl daemon-reload

启动参数介绍
--config.file             #加载prometheus的配置文件
--web.listen-address   #监听prometheus的web地址和端口
--web.enable-lifecycle #热启动参数,可以在不中断服务的情况下重启加载配置文件
--storage.tsdb.retention   #数据持久化的时间                         
--storage.tsdb.path        #数据持久化的保存路径

设置开机启动:systemctl enable prometheus
启动服务:systemctl start prometheus
重启服务:systemctl restart prometheus

访问:IP地址+9090端口号进行访问

3、安装python3.8.10

#下载
wget https://www.python.org/ftp/python/3.8.10/Python-3.8.10.tgz

#解压到3.8.10
tar -zxvf Python-3.8.10.tgz -C /usr/local/
cd /usr/local/
mv Python-3.8.10/ python3
cd python3
./configure --prefix=/usr/local/python3 --enable-optimizations --with-ssl 
make && make install

#设置软连接
ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
ln -s /usr/local/bin/python3 /usr/bin/python

#安装pip
pip3 install --upgrade pip

4、mysql8安装

删除mariadb
yum -y remove mariadb*

删除mysql
yum -y remove mysql*

wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
rpm -ivh mysql80-community-release-el7-1.noarch.rpm
yum install mysql-server

mysql -uroot -p(密码是空的直接回车进入)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newmysql';

创建用户和密码:CREATE USER 'root'@'%' IDENTIFIED BY 'newmysql';
权限赋给root用户,所有ip都能连接
GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION;
更新root密码否则,远程登录会报错
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'newmysql';
刷新
FLUSH  PRIVILEGES;
加入3306端口
firewall-cmd --permanent --zone=public --add-port=3306/tcp
开启刷新防火墙
firewall-cmd --reload


启动:systemctl start mysqld.service 
查看mysql状态:systemctl status mysqld.service
开机自启动
systemctl enable mysqld
systemctl daemon-reload

数据库登录
mysql -uroot -p

5、mysqld_exporter安装

https://github.com/prometheus/mysqld_exporter/releases/mysqld_exporter-0.13.0.linux-amd64.tar.gz 
tar -xvf mysqld_exporter-0.13.0.linux-amd64.tar.gz
mv mysqld_exporter-0.13.0.linux-amd64 /usr/local/prometheus/P_tools/mysqld_exporter

授权后进入mysqld_exporter安装目录创建.my.cnf配置文件,并运行mysqld_exporter
cd /usr/local/prometheus/P_tools/mysqld_exporter/
vim .my.cnf

[client]
user=root
password=你的密码

保存文件后执行以下语句
./mysqld_exporter --config.my-cnf=.my.cnf &(启动mysqld_exporter)

6、node_exporter安装

https://github.com/prometheus/node_exporter/releases/node_exporter-1.3.1.linux-amd64.tar.gz
tar zxvf node_exporter-1.3.1.linux-amd64.tar.gz
mv node_exporter-1.3.1.linux-amd64 /usr/local/prometheus/P_tools/node_exporter

cd /usr/local/prometheus/P_tools/node_exporter/

./node_exporter &(启动node_exporter)

下面配置mysql监控:mysql -u root -p

grant select on performance_schema.* to root@"localhost";

进入prometheus安装路径并修改配置文件
cd /usr/local/prometheus
注:不能使用localhost,必须使用IP+端口号!编辑prometheus.yml文件,所有代码不可以粘贴或复制(原因是yml文件的语言严谨性非常高)
vim prometheus.yml

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).
 
# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093
 
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"
 
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
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: ['192.168.159.131:9090']
  
  - job_name: 'node'
    static_configs:
    - targets: ['192.168.159.131:9100']
 
  - job_name: 'mysql'
    static_configs:
    - targets: ['192.168.159.131:9104']

保存文件
./prometheus --config.file=./prometheus.yml &
启动服务:systemctl start prometheus
重启服务:systemctl restart prometheus
查看端口:ss -anlt

(注:先启动Mysql再启动Node,最后启动Prometheus,都是进入目录后进行启动)

 7、Grafana8.3.3安装

wget https://dl.grafana.com/enterprise/release/grafana-enterprise-8.3.3-1.x86_64.rpm
sudo yum install grafana-enterprise-8.3.3-1.x86_64.rpm

启动服务
systemctl start grafana-server

设置开机启动
systemctl enable grafana-server

如果需要局域网访问就打开3000端口:firewall-cmd --add-port=3000/tcp --permanent
重启防火墙:systemctl restart firewalld.service
浏览器访问:IP:3000/login,账号密码都是admin,然后设置新密码

进入后选择右侧的菜单栏里的data source后再选择Prometheus,然后找到HTTP里的URL填写你的IP地址+端口号,最后点击下方的Save&test按钮,如出现“Data source is working”即可(这里是填入您Prometheus的IP地址+端口号)。

由于Dashboard是json文件所以我们直接去官网下载json模板文件,进入dashboards模板地址https://grafana.com/dashboards,进入后直接搜索Node Exporter Quickstart and Dashboard
,就出现了所有的关于Node的json模板,我这里选择的是Node Exporter Quickstart and Dashboard,进入页面后可以看见展示的样式,包含采集的所有数据项。我这里直接点击右侧的Download Json。

把刚才下载的json模板文件在Grafana平台里点击左侧菜单的Import导入按钮进行导入,也可以直接输入下载json模板文件的ID编号后点击load进行读取

成功导入json模板文件后,监控的各项模块相继的就展示出来了。

下面的是进入dashboards模板地址https://grafana.com/dashboards,进入后直接搜索MySQL Overview然后下载json模板文件,进行导入模板后的监控数据截图

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值