一、Linux 时间同步
1、时间同步一次:ntpdate ntp1.aliyun.com
2、定时任务同步
(1)crontab -e
(2)按i 写入*/10 * * * * ntpdate ntp1.aliyun.com
说明放入定时任务中每隔10分钟执行一次
crontab -l 查看定时任务
#监控Linux主机系统指标


#服务端配置

#安装prometheus(端口9000)
tar -zxf prometheus-2.22.0.linux-amd64.tar.gz
#创建工作目录
mkdir /opt/monitor
mv prometheus-2.22.0.linux-amd64 /opt/monitor/prometheus
#配置为系统服务管理
vi /usr/lib/systemd/system/prometheus.service
[Unit]
Description=prometheus
[Service]
ExecStart=/opt/monitor/prometheus/prometheus --config.file=/opt/monitor/prometheus/prometheus.yml
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
#加载服务配置启动,开机启动
systemctl daemon-reload
systemctl start prometheus
systemctl enable prometheus

#安装grafana(端口3000)
tar -zxf grafana-7.2.2.linux-amd64.tar.gz
mv grafana-7.2.2 /opt/monitor/grafana
#配置为系统服务管理
vi /usr/lib/systemd/system/grafana.service
[Unit]
Description=grafana
[Service]
ExecStart=/opt/monitor/grafana/bin/grafana-server -homepath=/opt/monitor/grafana
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
#加载服务配置启动,开机启动
systemctl daemon-reload
systemctl start grafana
systemctl enable grafana
#在Prometheus配置文件添加被监控端
vim /opt/monitor/prometheus/prometheus.yml:
scrape_configs:
- job_name: 'linux server'
basic_auth:
username: prometheus
password: 123.com
static_configs:
- targets: ['192.168.0.13:9100']
-------------------------------------------------------------------
#配置完成后,使用promtool工具检查配置文件是否有误
cd /opt/monitor/prometheus
./promtool check config ./prometheus.yml
#查看prometheus的进程id,上面修改配置进行热加载配置
ps -ef |grep prometheus
kill -HUP 62291

#被监控端配置


#安装node_exporter采集器(端口9100)
tar -zxf node_exporter-1.0.1.linux-amd64.tar.gz
mv node_exporter-1.0.1.linux-amd64 /usr/local/node_exporter
#启用HTTP认证:
cd /usr/local/node_exporter
vi config.yml
basic_auth_users:
prometheus: $2y$12$F8D.zKZEh9SRCLD4D6YnK.hNRWwWJQjD5guti5N846lTDsY.ToHMq
用户名 :密码
-----------------------------------------------------------------
#上面密码用下面命令生成:
yum install httpd-tools –y
htpasswd -nBC 12 '' | tr -d ':\n'
#配置为系统服务管理:
vi /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
[Service]
ExecStart=/usr/local/node_exporter/node_exporter --web.config=/usr/local/node_exporter/config.yml
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
#加载服务配置启动,开机启动
systemctl daemon-reload
systemctl start node_exporter
systemctl enable node_exporter

#监控被systemd管理的系统服务
cat /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
[Service]
ExecStart=/usr/local/node_exporter/node_exporter --web.config=/usr/local/node_exporter/config.yml --collector.systemd --collector.systemd.unit-whitelist=(docker|sshd|nginx).service
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
------------------------------------------------------------
--collector.systemd #采集被systemd管理的服务
--collector.systemd.unit-whitelist=(docker|sshd|nginx).service #采集相关的服务

学习:

https://www.cnblogs.com/chenqionghe/p/10494868.html