页面“Monitoring with prometheus”与“Linux时间同步的那些事儿”之间的差异

来自linux中国网wiki
(页面间的差异)
跳到导航 跳到搜索
 
 
第1行: 第1行:
==
+
== centos7(debian10)从外网同步时间和时区设置==
 +
<pre>
  
 +
# 设置亚洲时区 tzselect 有时不准备
 +
timedatectl set-timezone Asia/Shanghai
 +
# 启用NTP同步 #关闭是 false
 +
timedatectl set-ntp true # yes
 +
#关闭 时间同步  关了 就可以改时间了
 +
timedatectl set-ntp false
  
=book=
 
  
[https://www.bookstack.cn/read/prometheus-book/README.md  Prometheus操作指南]
+
set-ntp [BOOL]
=进阶=
+
          Takes a boolean argument. Controls whether network time synchronization is active and enabled (if available). If the argument is true, this enables and starts the first
以后全改成自己 docker-compose build
+
          existed service listed in the environment variable $SYSTEMD_TIMEDATED_NTP_SERVICES of systemd-timedated.service. If the argument is false, then this disables and stops the
 +
          all services listed in $SYSTEMD_TIMEDATED_NTP_SERVICES.
  
[https://blog.51cto.com/wzlinux/2487300 prometheus 监控概述(一)有常用监控警告]
+
#NOTE
 +
ntpdate cn.pool.ntp.org #发现有效果  直接这样同步就行了,不用像下面一样设置一个时间点
  
[https://blog.51cto.com/wzlinux/2490670 PromQL 内置函数(三)]
+
date -s "2019-05-23 01:01:01"
  
 +
019
 +
[root@prod-sns-php01 ~]#  timedatectl set-ntp true
 +
Failed to set ntp: NTP not supported.
 +
yum install -y ntp
  
  
[https://www.jb51.net/article/189679.htm  prometheus python 库编写自定义指标的方法(完整代码)]
+
也许可以用这个
 +
ln -sf  /usr/share/zoneinfo/Asia/Shanghai  /etc/localtime
  
  
[https://www.jianshu.com/p/19442595e886 promethues + python + flask监控后端服务状态]
 
  
[https://blog.csdn.net/weixin_33754913/article/details/91803530  prometheus python client]
+
#下面几个可以不要    安装
 +
yum install chrony
 +
# 启用
 +
systemctl start chronyd
 +
systemctl enable chronyd
  
[https://blog.csdn.net/JackLiu16/article/details/80381201?utm_medium=distribute.pc_relevant.none-task-blog-title-7&spm=1001.2101.3001.4242 使用Python和Flask编写Prometheus监控]
+
timedatectl set-time 15:58:30
 +
Failed to set time: Automatic time synchronization is enabled
 +
root@debian-hyper:~# timedatectl set-ntp  no  #or
 +
timedatectl set-ntp false
 +
root@debian-hyper:~# timedatectl set-time 15:58:30 #修改时间
  
[https://blog.csdn.net/specter11235/article/details/87927202 python开发prometheus exporter]
 
  
=ins on docker-composer=
+
</pre>
git clone https://github.com/evan886/docker-compose-monitor.git
 
  
 +
==基础知识==
 +
timedatectl命令对于RHEL / CentOS 7和基于Fedora 21+的分布式系统来说,是一个新工具,它作为systemd系统和服务管理器的一部分,代替旧的传统的用在基于Linux分布式系统的sysvinit守护进程的date命令、
 +
在最新的 Ubuntu 版本中,timedatectl 替代了老旧的 ntpdate。默认情况下,timedatectl 在系统启动的时候会立刻同步时间,并在稍后网络连接激活后通过 socket 再次检查一次。
  
https://gitee.com/atompi/PrometheusStackDockerCompose
+
  如果已安装了 ntpdate / ntp,timedatectl 会退而让你使用之前的设置。这样确保了两个时间同步服务不会相互冲突,同时在你升级的时候还保留原本的行为和配置。但这也意味着从旧版本的发行版升级时ntp/ntpdate 仍会安装,因此会导致新的基于 systemd 的时间服务被禁用。
  
=安全=
 
<pre>
 
node exporter 添加防火墙
 
  
curl -Lo /etc/yum.repos.d/_copr_ibotty-prometheus-exporters.repo https://copr.fedorainfracloud.org/coprs/ibotty/prometheus-exporters/repo/epel-7/ibotty-prometheus-exporters-epel-7.repo
 
# yum install node_exporter
 
</pre>
 
  
=prometheus=
+
    UTC 整个地球分为二十四时区,每个时区都有自己的本地时间。在国际无线电通信场合,为了统一起见,使用一个统一的时间,称为通用协调时(UTC, Universal Time Coordinated)。
[[Nginx用户密码认证配置 Basic HTTP authentication]]
 
  
不错的书
+
    GMT 格林威治标准时间 (Greenwich Mean Time)指位于英国伦敦郊区的皇家格林尼治天文台的标准时间,因为本初子午线被定义在通过那里的经线。(UTC与GMT时间基本相同,本文中不做区分)
https://yunlzheng.gitbook.io/prometheus-book/
 
  
 +
    CST 中国标准时间 (China Standard Time)
  
  
 +
[https://my.oschina.net/airship/blog/1544886 timedatectl时钟同步]
  
[https://blog.csdn.net/lijiaocn/article/details/81865120 新型监控告警工具prometheus(普罗米修斯)的入门使用(附视频讲解)]
+
[https://blog.csdn.net/l1212xiao/article/details/80328918 CentOS 7时间和日期和时间同步]
  
[https://www.lijiaocn.com/%E9%A1%B9%E7%9B%AE/2018/08/03/prometheus-usage.html#prometheus%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6 【视频】新型监控告警工具prometheus(普罗米修斯)入门使用(附视频讲解)]
+
==centos7  chrony 自建的时间同步 server==
 
 
[https://zhuanlan.zhihu.com/p/91215371 为什么说 Prometheus 是足以取代 Zabbix 的监控神器?]
 
 
 
[https://zhuanlan.zhihu.com/p/24811652 基于Prometheus的分布式在线服务监控实践]
 
 
 
==usage==
 
[https://www.jianshu.com/p/03cf0fc9c746 Grafana单图表告警邮件&面板图(Dashboard)日报邮件]
 
 
 
[https://prometheus.io/docs/practices/rules/ Recording rules ]
 
 
 
https://github.com/prometheus/blackbox_exporter/blob/master/blackbox.yml
 
 
 
=grafana=
 
 
<pre>
 
<pre>
#防火墙  grafana ng 在 10.3.10.10
+
Chrony是一个开源的自由软件,它能保持系统时钟与时钟服务器(NTP)同步,让时间保持精确。它由两个程序组成:chronyd和chronyc。
firewall-cmd  --permanent --add-rich-rule="rule family="ipv4" source address="10.3.10.10" port protocol="tcp" port="3000" accept "
+
          chronyd是一个后台运行的守护进程,用于调整内核中运行的系统时钟和时钟服务器同步。它确定计算机增减时间的比率,并对此进行补偿。
firewall-cmd --reload
+
          Chrony 是网络时间协议的另一种实现,与网络时间协议后台程序(ntpd)不同,它可以更快地且准确的同步系统时钟。
  
</pre>
 
  
 +
centos7  建议是用 chrony
  
[https://grafana.com/docs/grafana/latest/installation/docker/ grafana.com Run Grafana Docker image]
+
yum -y install chrony ntp  -y
  
[https://grafana.com/grafana/dashboards/8919 中文 Node Exporte for Prometheus Dashboard]
+
systemctl start chronyd
 +
systemctl status chronyd
 +
systemctl enable  chronyd
  
usage  creat-->import --> id  8919
 
  
Container
+
timedatectl set-timezone Asia/Shanghai
 
 
 
 
 
 
https://grafana.com/grafana/dashboards/11174
 
  
 +
timedatectl set-ntp true
 
   
 
   
  docker-grafana/config.env https://github.com/stefanwalther/docker-grafana/blob/master/config.env  
+
  crontab -l #如果实在要用
 
+
* */2 * * * ntpdate time.windows.com
==grafana 添加源和数据 ==
 
 
 
[https://www.bookstack.cn/read/prometheus-book/quickstart-use-grafana-create-dashboard.md 使用Grafana创建可视化Dashboard]
 
  
===Panel plugin not found: grafana-piechart-panel===
+
yum install chrony -y
<pre>
 
  
升级为7.0.0就好了 不过要看其它模板还能用么
+
#改配置
 +
cat /etc/chrony.conf
  
#这个放弃了 是在 6.x系列的  还不好用
+
#没用的全删除了
grafana-cli plugins install grafana-piechart-panel
+
# Use public servers from the pool.ntp.org project.
 +
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
 +
server  news.neu.edu.cn iburst
 +
#server 0.centos.pool.ntp.org iburst
  
docker-compose  restart  grafana
 
  
 +
systemctl  start chronyd.service && systemctl  enable chronyd.service
  
执行过程
 
grafana-cli plugins install grafana-piechart-panel
 
installing grafana-piechart-panel @ 1.6.1
 
from: https://grafana.com/api/plugins/grafana-piechart-panel/versions/1.6.1/download
 
into: /var/lib/grafana/plugins
 
  
✔ Installed grafana-piechart-panel successfully
+
测试
  
Restart grafana after installing plugins . <service grafana-server restart>
+
故意超时
 +
date -s "2020-11-11 11:11:11"
  
[https://github.com/unifi-poller/unifi-poller/issues/248 RESOLVED: Panel plugin not found: table-old ]
+
哪个命令fix对了时间的
 +
重启这个就行了 其实是不是不用动也行 过了阵就会自己同步
 +
  systemctl restart chronyd.service
  
 +
timedatectl set-ntp yes
  
 
</pre>
 
</pre>
[https://www.jianshu.com/p/153d944ab836 Panel plugin not found: grafana-piechart-panel]
+
===chrony 使用 ===
 
 
==grafana 添加用户 ==
 
 
<pre>
 
<pre>
1.Users-->  2.Invite -->
+
使用chronyc
 
+
你也可以通过运行chronyc命令来修改设置,命令如下:
3.进行邀请
 
Email or Username:输入用户邮箱,建议先跟用户名保持相同,然后在后面在写邮箱,后面会说到,这样不会报错
 
Name:输入用户名
 
Role:配置用户权限(只读Viewer 编辑Editor 管理员Admin)
 
Send invite email:勾选时,会将新用户的设置密码的链接发到邮箱
 
  
点击创建之后回调到新用户设置密码
+
accheck - 检查NTP访问是否对特定主机可用
  
-->
+
activity - 该命令会显示有多少NTP源在线/离线
  
4.创建好之后,点击Pending Invites
 
复制链接到浏览器的地址栏中访问(也可从邮件中收到链接)
 
进去之后是下面的界面,这里有个坑,复制的IP地址是localhost,我们这里改为自己搭建的IP地址,然后在Email填写邮箱地址,设置新用户的密码
 
设置完成后,会直接以新用户身份登陆
 
  
  
http://localhost:3000/invite/PAhyq4gzfA3ugRiw0PH2RC2vsIuSTa
+
add server - 手动添加一台新的NTP服务器。
  
http://a.linuxsa.org/invite/PAhyq4gzfA3ugRiw0PH2RC2vsIuSTa
+
clients - 在客户端报告已访问到服务器
  
  -->
+
delete - 手动移除NTP服务器或对等服务器
  
</pre>
+
settime - 手动设置守护进程时间
  
[https://blog.csdn.net/liuxiangyang_/article/details/86737103  grafana的用户及权限的配置]
+
tracking - 显示系统时间信息
  
[https://blog.csdn.net/GX_1_11_real/article/details/85119451  grafana的用户及权限的配置]
 
  
[https://blog.csdn.net/kozazyh/article/details/93759717?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase  grafana-利用Google OAuth2 身份验证]
 
  
== ng config==
+
#有用 ?
<pre>
+
将系统时间写入硬件时间
cat gf.conf
 
server
 
{
 
    listen 80;
 
    server_name gf.linuxsa.org;
 
#   access_log  /var/log/nginx/test-nuxt-bcb-blockchain-website.lliao.net.log;
 
    #error_log /var/log/nginx/test-nux-bcb.evan.error.log;
 
  
 +
sudo hwclock --systohc
  
    client_max_body_size 10m;
+
</pre>
 
 
    location / {
 
      proxy_pass http://10.3.10.124:3000;
 
      proxy_http_version 1.1;
 
  
#set_real_ip_from 10.0.0.0/8;
+
==老方法 centos7==
#set_real_ip_from 172.16.0.0/12;
+
<pre>
#set_real_ip_from 192.168.0.0/16;
+
#proxmox 上的 vm centos7 老是时间不对 ,以前用的ntpd老是不成功呢
#real_ip_header X-Forwarded-For;
 
  
        proxy_set_header        Host                $host;
+
yum install ntp  -y
        proxy_set_header        X-Real-IP            $remote_addr;
+
timedatectl set-timezone Asia/Shanghai
        proxy_set_header        X-Forwarded-For      $proxy_add_x_forwarded_for;
+
timedatectl set-ntp true
        proxy_set_header        X-Remote-Port        $remote_port;
+
ntpq -p
        proxy_set_header        X-Forwarded-Proto    $scheme;
 
        proxy_redirect          off;
 
  
          proxy_connect_timeout 1800s;
 
          proxy_send_timeout 1800s;
 
          proxy_read_timeout 1800s;
 
  
 +
#设置系统时间为中国时区并启用NTP同步
 +
yum install ntp -y#//安装ntp服务
 +
systemctl enable ntpd #//开机启动服务
 +
systemctl start ntpd #//启动服务
 +
timedatectl set-timezone Asia/Shanghai #//更改时区
 +
timedatectl set-ntp yes # 用的是true ?//启用ntp同步
 +
ntpq -p //同步时间
  
 
      real_ip_recursive on;
 
#      real_ip_header X-Forwarded-For;
 
#      set_real_ip_from 0.0.0.0/0;
 
#      proxy_set_header Host            $host;
 
#      proxy_set_header X-Real-IP $remote_addr;
 
#      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 
 
 
#proxy_set_header Host            $host:$server_port;
 
#proxy_set_header    HTTP_X_FORWARDED_FOR $remote_addr;
 
#proxy_set_header X-NginX-Proxy true;
 
 
#      proxy_set_header X-Real-IP        $remote_addr;
 
#    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 
#      proxy_set_header Upgrade $http_upgrade;
 
#      proxy_set_header Connection "upgrade";
 
    }
 
}
 
  
 
</pre>
 
</pre>
  
==使用教程==
 
[https://yuerblog.cc/2019/01/04/grafana-usage/ grafana配置与简单使用]
 
  
[https://blog.csdn.net/bbwangj/article/details/81109615  Grafana使用教程]
 
  
[https://blog.csdn.net/Sagitarioo/article/details/102805852?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-2&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-2  grafana数据可视化-使用教程]
+
<pre>
 +
CentOS配置时间同步NTP
 +
为什么要使用ntpd而不是ntpdate?
 +
原因很简单,ntpd是步进式的逐渐调整时间,而ntpdate是断点更新,比如现在服务器时间是9.18分,而标准时间是9.28分,ntpd会在一段时间内逐渐的把时间校准到与标准时间相同,而ntpdate会立刻把时间调整到9.28分,如果你往数据库内写入内容或在其他对时间有严格要求的生产环境下,产生的后果会是很严重的。(注:当本地时间与标准时间相差30分钟以上是ntpd会停止工作)
  
[https://www.cnblogs.com/xkus/p/7462742.html  grafana快速入门 ]
+
NTP通信协议原理
  
[https://blog.csdn.net/u012062455/article/details/79214700  grafana使用教程之基本概念(basic concepts)]
+
/usr/sbin/ntpd: 主要提供 NTP 服务的程序啰!配置文件为 /etc/ntp.conf
 +
/usr/sbin/ntpdate: 用于客户端的时间校正,如果你没有要启用 NTP 而仅想要使用 NTP Client 功能的话,那么只会用到这个指令而已啦!
  
[https://blog.csdn.net/weixin_42674978/article/details/102681969 Grafana从无到有的一个相当粗略的资料总结]
+
#这个运行不了 ali的是直接跑在  /etc/ntpd.conf配置的 
 +
*/10 * * * * /usr/sbin/ntpd cn.pool.ntp.org > /dev/null 2>&1
  
 +
*/10 * * * * /usr/sbin/ntpdate cn.pool.ntp.org > /dev/null  2>&1
 +
</pre>
  
[https://blog.csdn.net/Sagitarioo/article/details/102805852?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-2&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-2  grafana数据可视化-使用教程]
+
=debian=
 
+
<pre>
[https://ken.io/note/grafana-quickstart-influxdb-datasource-graph Grafana快速入门:InfluxDB数据源以及曲线图表仪表盘配置]
+
UTC时区切换到CST 时区
  
 +
#用这个啦
 +
# 设置亚洲时区
 +
timedatectl set-timezone Asia/Shanghai
 +
# 启用NTP同步 #关闭是 false
 +
timedatectl set-ntp yes
  
[https://www.cnblogs.com/fatyao/p/11192234.html Grafana报警]
 
  
 +
echo "export TZ='Asia/Shanghai'"  >> /etc/profile 
 +
cat /etc/profile |grep TZ 
 +
source /etc/profile
 +
date -R
 +
date
 +
Sat Aug 19 17:03:17 CST 2017
  
  apached conf
+
debian 手工修改时间  
<pre>
 
##/etc/httpd/conf.d/gf.conf
 
  
 +
#将系统日期设定成1996年6月10日的命令
 +
date -s 06/22/96
  
<VirtualHost *:80>
+
sudo  date  -s 10:20:00
      ServerName gf.linuxsa.org
+
sudo hwclock -w  #当前时间和日期写入BIOS,避免重启后失效 2020用了这种 有效果
      ServerAlias gf.linuxsa.org
 
   
 
      ProxyRequests off
 
   
 
      <Proxy *>
 
        Order deny,allow
 
        Allow from all
 
      </Proxy>
 
   
 
      <Location />
 
        ProxyPass http://localhost:3000/
 
        ProxyPassReverse http://localhost:3000/
 
      </Location>
 
    </VirtualHost>
 
  
 
</pre>
 
</pre>
  
=vm监控[[Node-exporter]]=
+
==我的kali==
可以如上的  node
+
本本老是时间不对 
[[Node-exporter]]
+
ntpdate cn.pool.ntp.org #发现有效果
 
 
=Blackbox=  
 
 
 
[[Blackbox exporter]]
 
 
 
=pushgateway=
 
 
 
[[pushgateway]]
 
  
[https://www.cnblogs.com/xiao987334176/p/9933963.html  基于Prometheus的Pushgateway实战 ]
 
  
https://songjiayang.gitbooks.io/prometheus/content/pushgateway/how.html
+
1,查看debian当前时间
 +
  debian:~# date
 +
2,手动更改系统时间
 +
  debian:~# date 120110552007.12
 +
  顺序为      月 日时分 年 .
  
=[[Process-exporter]]=
+
3,同步Internet时间,首先安装时间同步软件
 +
  apt-get install ntpdate
  
=应用监控=
+
4,手动同步系统时间
==redis==
+
  ntpdate cn.pool.ntp.org
[[prometheus监控Redis集群]]
 
  
[https://blog.csdn.net/weixin_43832846/article/details/90024274  pika主备部署(redis-sentinel)+监控(prometheus+grafana)]
+
5,如果重新启动后时间不是Internet时间可采取以下方法
 
 
[https://blog.csdn.net/weixin_34289744/article/details/92725774?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-16.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-16.nonecase  Prometheus监控 Redis , redis-cli_exporter]
 
 
 
==监控MQ==
 
[https://www.rabbitmq.com/prometheus.html  Monitoring with Prometheus & Grafana ]
 
 
 
==监控ES==
 
https://github.com/slok/ecs-exporter
 
==docker==
 
[https://blog.csdn.net/palet/article/details/82889493?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-7.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-7.nonecase  Prometheus+grafana监控:cAdvisor输出的容器内存相关的指标的解读]
 
 
 
== mysql==
 
[https://blog.csdn.net/qq_25934401/article/details/82594478  prometheus 监控之 mysql 篇(含mysql报警规则)]
 
 
 
[https://jiajunhuang.com/articles/2018_12_16-prometheus_mysqld_exporter.md.html Prometheus MySQL Exporter源码阅读与分析]
 
 
 
[https://www.jianshu.com/p/27b979554ef8 python + promethues 监控mysql]
 
 
 
==Spring boot==
 
https://www.bookstack.cn/read/prometheus_practice/application-spring.md
 
 
 
 
 
[https://blog.csdn.net/liangcha007/article/details/86699013#7.%E5%85%B3%E4%BA%8Epushgateway  Prometheus基于java开发exporter样例以及pushgateway的应用]
 
 
 
=ng conf=
 
 
<pre>
 
<pre>
cat  alert.conf
+
vim  /etc/default/ntpdate
server
+
法1.修改/etc/default目录下的ntpdate
{
+
  在配置文件中发现了它设定时间服务器为cn.pool.ntp.org,
    listen 80;
 
    server_name alert.com;
 
#    access_log  /var/log/nginx/test-nuxt-bcb-blockchain-website.lliao.net.log;
 
    #error_log /var/log/nginx/test-nux-bcb.evan.error.log;
 
 
 
 
 
    client_max_body_size 10m;
 
 
    
 
    
    location / {
+
# Not used if NTPDATE_USE_NTP_CONF is yes.
  #      auth_basic "Prometheus";
+
NTPSERVERS="cn.pool.ntp.org  0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org"
  #     auth_basic_user_file "/usr/local/openresty/nginx/conf/hosts/.htpasswd";
+
#NTPSERVERS="0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org"
      proxy_pass http://10.3.10.124:9093;
 
      proxy_http_version 1.1;
 
  
#s#et_real_ip_from 10.0.0.0/8;
+
</pre>
#set_real_ip_from 172.16.0.0/12;
 
#set_real_ip_from 192.168.0.0/16;
 
#real_ip_header X-Forwarded-For;
 
        proxy_set_header        Host                $host;
 
        proxy_set_header        X-Real-IP            $remote_addr;
 
        proxy_set_header        X-Forwarded-For      $proxy_add_x_forwarded_for;
 
        proxy_set_header        X-Remote-Port        $remote_port;
 
        proxy_set_header        X-Forwarded-Proto    $scheme;
 
        proxy_redirect          off;
 
          proxy_connect_timeout 1800s;
 
          proxy_send_timeout 1800s;
 
          proxy_read_timeout 1800s;
 
  
      real_ip_recursive on;
+
法2.做一个同步的脚本ntpupdate在开机时调用,内容如下
#     real_ip_header X-Forwarded-For;
+
<pre>
#      set_real_ip_from 0.0.0.0/0;
+
  #!/bin/sh
#      proxy_set_header Host            $host;
+
  /usr/sbin/ntpdate time.nist.gov | logger -t NTP
#      proxy_set_header X-Real-IP $remote_addr;
+
  /sbin/hwclock -w</pre>
#      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+
==Linux 修改系统时间成功未生效==
 +
<pre>
 +
使用 date -s “2019-02-02 02:02:02” 命令修改系统时间,提示修改成功但是系统时间未发生变化;
  
  
#proxy_set_header Host            $host:$server_port;
+
使用timedatectl命令查看系统时间
#proxy_set_header    HTTP_X_FORWARDED_FOR $remote_addr;
 
#proxy_set_header X-NginX-Proxy true;
 
  
#      proxy_set_header X-Real-IP        $remote_addr;
+
timedatectl
#    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+
              Local time: Wed 2020-02-26 22:28:22 PST
#      proxy_set_header Upgrade $http_upgrade;
+
          Universal time: Thu 2020-02-27 06:28:22 UTC
#      proxy_set_header Connection "upgrade";
+
                RTC time: Thu 2020-02-27 06:28:22
    }
+
                Time zone: America/Los_Angeles (PST, -0800)
}
+
System clock synchronized: yes
 +
              NTP service: active
 +
          RTC in local TZ: no
  
 +
关闭ntp同步 timedatectl set-ntp false
  
  
cat  pro.conf
 
server
 
{
 
    listen 80;
 
    server_name pro.linuxsa.org;
 
#    access_log  /var/log/nginx/test-nuxt-bcb-blockchain-website.lliao.net.log;
 
    #error_log /var/log/nginx/test-nux-bcb.evan.error.log;
 
  
 +
</pre>
  
    client_max_body_size 10m;
+
=see also=
 
 
    location / {
 
        auth_basic "Prometheus";
 
        auth_basic_user_file "/usr/local/openresty/nginx/conf/hosts/.htpasswd";
 
      proxy_pass http://10.3.10.124:9090;
 
      proxy_http_version 1.1;
 
  
#set_real_ip_from 10.0.0.0/8;
 
#set_real_ip_from 172.16.0.0/12;
 
#set_real_ip_from 192.168.0.0/16;
 
#real_ip_header X-Forwarded-For;
 
  
        proxy_set_header        Host                $host;
+
[https://www.cnblogs.com/zhi-leaf/p/6282301.html  Linux下使用timedatectl命令时间时区操作详解]
        proxy_set_header        X-Real-IP            $remote_addr;
 
        proxy_set_header        X-Forwarded-For      $proxy_add_x_forwarded_for;
 
        proxy_set_header        X-Remote-Port        $remote_port;
 
        proxy_set_header        X-Forwarded-Proto    $scheme;
 
        proxy_redirect          off;
 
  
          proxy_connect_timeout 1800s;
+
[https://www.fujieace.com/linux/man/ntpdate-hwclock.html Linux时间同步命令:ntpdate(系统时间)、hwclock(硬件时间)]
          proxy_send_timeout 1800s;
 
          proxy_read_timeout 1800s;
 
  
 +
[https://www.iteye.com/blog/justcoding-1962519 Linux查看与修改时区、时间的命令 ]
  
 +
[https://www.digitalocean.com/community/tutorials/how-to-set-up-time-synchronization-on-debian-10 How To Set Up Time Synchronization on Debian 10]
  
      real_ip_recursive on;
+
[[Centos7 NTP网络时间协议]]
#      real_ip_header X-Forwarded-For;
 
#      set_real_ip_from 0.0.0.0/0;
 
#      proxy_set_header Host            $host;
 
#      proxy_set_header X-Real-IP $remote_addr;
 
#      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 
  
 +
[https://www.cnblogs.com/tangxiaosheng/p/4986375.html CentOS 7 时间, 日期设置 (含时间同步)]
  
#proxy_set_header Host            $host:$server_port;
+
http://cn.linux.vbird.org/linux_server/0440ntp.php
#proxy_set_header    HTTP_X_FORWARDED_FOR $remote_addr;
 
#proxy_set_header X-NginX-Proxy true;
 
  
#      proxy_set_header X-Real-IP        $remote_addr;
+
[https://blog.itnmg.net/2015/03/03/centos-7-time-date/ CentOS 7 时间, 日期设置]
#    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 
#      proxy_set_header Upgrade $http_upgrade;
 
#      proxy_set_header Connection "upgrade";
 
    }
 
}
 
  
 +
[https://blog.csdn.net/scorpio3k/article/details/49645219 CentOS7 中使用NTP进行时间同步]
  
cat blackbox.conf
+
[http://blog.51cto.com/dadonggg/1947882 使用NTP进行CentOS7时间同步]
server
 
{
 
    listen 80;
 
    server_name blackbox.com;
 
#    access_log  /var/log/nginx/test-nuxt-bcb-blockchain-website.lliao.net.log;
 
    #error_log /var/log/nginx/test-nux-bcb.evan.error.log;
 
    client_max_body_size 10m;
 
    location / {
 
  #      auth_basic "Prometheus";
 
  #      auth_basic_user_file "/usr/local/openresty/nginx/conf/hosts/.htpasswd";
 
      proxy_pass http://10.3.10.124:9115;
 
      proxy_http_version 1.1;
 
  
        proxy_set_header        Host                $host;
+
[http://luijnijei.blog.163.com/blog/static/350245942010913912192/ linux时间同步,ntpd、ntpdate ]
        proxy_set_header        X-Real-IP            $remote_addr;
 
        proxy_set_header        X-Forwarded-For      $proxy_add_x_forwarded_for;
 
        proxy_set_header        X-Remote-Port        $remote_port;
 
        proxy_set_header        X-Forwarded-Proto    $scheme;
 
        proxy_redirect          off;
 
  
          proxy_connect_timeout 1800s;
+
[http://151wqooo.blog.51cto.com/2610898/1336282 服务器时间同步]
          proxy_send_timeout 1800s;
 
          proxy_read_timeout 1800s;
 
      real_ip_recursive on;
 
    }
 
}
 
  
  
 +
[http://xstarcd.github.io/wiki/sysadmin/ntpd.html ntpd时钟同步服务]
  
</pre>
+
==chrony==
 
 
=告警=
 
 
 
[[Alertmanager]]
 
 
 
==telegram==
 
通过 prome or grafana ?
 
 
 
[https://nova.moe/manage-host-alert-on-telegram-with-grafana/ 在 Telegram 中管理主机监控和警报信息]
 
 
 
https://github.com/inCaller/prometheus_bot
 
 
 
https://github.com/metalmatze/alertmanager-bot
 
 
 
[https://blog.csdn.net/weixin_34242331/article/details/91875514  基于prometheus + grafana + mysql + Telegram 监控告警]
 
 
 
https://my.oschina.net/54188zz/blog/3030618
 
 
 
[https://yunlzheng.gitbook.io/prometheus-book/parti-prometheus-ji-chu/alert/prometheus-alert-rule 自定义Prometheus告警规则]
 
 
 
[https://www.linux.org.ru/forum/general/14894302  prometheus alertmanager telegram ]
 
 
 
=教程=
 
[https://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_liunx_60_prometheus_config.html  prometheus学习系列五: Prometheus配置文件 ]
 
 
 
=see also=
 
 
 
[https://www.jianshu.com/p/93412a925da2 规划 Prometheus 的存储用量]
 
  
[https://blog.csdn.net/lemon89/article/details/104088184 深入理解监控系统——Prometheus核心特点]
+
[https://soyoger.blog.csdn.net/article/details/77868337 使用chrony代替ntp同步时间]
  
[https://blog.csdn.net/qq_21816375/article/details/80462445?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-12.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-12.nonecase  prometheus部署node,server以及域名加告警]
+
[https://blog.csdn.net/Linuxprobe18/article/details/80460068 详解:Linux Chrony 设置服务器集群同步时间]
  
[https://www.cnblogs.com/chenqionghe/p/10494868.html 从零搭建Prometheus监控报警系统]
+
[https://blog.csdn.net/openbox2008/article/details/80250027 centos7.4 用chrony代替ntpd时间同步服务器]
  
[https://www.jianshu.com/p/1f05476ebcee 使用prometheus自定义监控]
+
[https://blog.csdn.net/JIANG123456T/article/details/77966627 Centos 7.3_1611使用chrony做时间同步]
  
[https://zhuanlan.zhihu.com/p/91215371 为什么说 Prometheus 是足以取代 Zabbix 的监控神器?]
+
[https://blog.csdn.net/weixin_43875013/article/details/86485798 linux中时间同步服务(chronyd服务)以及系统时间设定]
  
[https://blog.51cto.com/wzlinux/2487300 prometheus 监控概述(一)]
+
[https://blog.csdn.net/hnhuangyiyang/article/details/52711631 CentOS7.2 chrony替代ntp搭建时间服务器]
  
[https://my.oschina.net/54188zz/blog/3030618 基于prometheus + grafana + mysql + Telegram 监控告警]
+
[https://blog.csdn.net/weixin_34290631/article/details/90571832 CentOS 7.x中正确设置时间与时钟服务器同步]
  
 +
[https://blog.csdn.net/hnhuangyiyang/article/details/52711631  CentOS7.2 chrony替代ntp搭建时间服务器]
  
[[category:ops]] [[category:container]] [[category:prom]]
+
[[category:ops]]

2020年10月16日 (五) 02:37的版本

centos7(debian10)从外网同步时间和时区设置

 

# 设置亚洲时区 tzselect 有时不准备
timedatectl set-timezone Asia/Shanghai
# 启用NTP同步 #关闭是 false 
timedatectl set-ntp true # yes
#关闭 时间同步   关了 就可以改时间了 
timedatectl set-ntp false


set-ntp [BOOL]
           Takes a boolean argument. Controls whether network time synchronization is active and enabled (if available). If the argument is true, this enables and starts the first
           existed service listed in the environment variable $SYSTEMD_TIMEDATED_NTP_SERVICES of systemd-timedated.service. If the argument is false, then this disables and stops the
           all services listed in $SYSTEMD_TIMEDATED_NTP_SERVICES.

#NOTE
ntpdate cn.pool.ntp.org #发现有效果   直接这样同步就行了,不用像下面一样设置一个时间点 

date -s "2019-05-23 01:01:01"

019
[root@prod-sns-php01 ~]#  timedatectl set-ntp true 
Failed to set ntp: NTP not supported.
 yum install -y ntp


也许可以用这个
ln -sf  /usr/share/zoneinfo/Asia/Shanghai   /etc/localtime



#下面几个可以不要    安装
yum install chrony
# 启用
systemctl start chronyd
systemctl enable chronyd

timedatectl set-time 15:58:30
Failed to set time: Automatic time synchronization is enabled
root@debian-hyper:~# timedatectl set-ntp  no   #or
timedatectl set-ntp false
root@debian-hyper:~# timedatectl set-time 15:58:30  #修改时间 


 

基础知识

timedatectl命令对于RHEL / CentOS 7和基于Fedora 21+的分布式系统来说,是一个新工具,它作为systemd系统和服务管理器的一部分,代替旧的传统的用在基于Linux分布式系统的sysvinit守护进程的date命令、
在最新的 Ubuntu 版本中,timedatectl 替代了老旧的 ntpdate。默认情况下,timedatectl 在系统启动的时候会立刻同步时间,并在稍后网络连接激活后通过 socket 再次检查一次。
 如果已安装了 ntpdate / ntp,timedatectl 会退而让你使用之前的设置。这样确保了两个时间同步服务不会相互冲突,同时在你升级的时候还保留原本的行为和配置。但这也意味着从旧版本的发行版升级时ntp/ntpdate 仍会安装,因此会导致新的基于 systemd 的时间服务被禁用。


   UTC 整个地球分为二十四时区,每个时区都有自己的本地时间。在国际无线电通信场合,为了统一起见,使用一个统一的时间,称为通用协调时(UTC, Universal Time Coordinated)。
   GMT 格林威治标准时间 (Greenwich Mean Time)指位于英国伦敦郊区的皇家格林尼治天文台的标准时间,因为本初子午线被定义在通过那里的经线。(UTC与GMT时间基本相同,本文中不做区分)
   CST 中国标准时间 (China Standard Time)


timedatectl时钟同步

CentOS 7时间和日期和时间同步

centos7 chrony 自建的时间同步 server

Chrony是一个开源的自由软件,它能保持系统时钟与时钟服务器(NTP)同步,让时间保持精确。它由两个程序组成:chronyd和chronyc。
          chronyd是一个后台运行的守护进程,用于调整内核中运行的系统时钟和时钟服务器同步。它确定计算机增减时间的比率,并对此进行补偿。
          Chrony 是网络时间协议的另一种实现,与网络时间协议后台程序(ntpd)不同,它可以更快地且准确的同步系统时钟。


 centos7  建议是用 chrony

yum -y install chrony ntp  -y

systemctl start chronyd
systemctl status chronyd
systemctl enable  chronyd


timedatectl set-timezone Asia/Shanghai

timedatectl set-ntp true
 
 crontab  -l  #如果实在要用
* */2 * * * ntpdate time.windows.com

yum install chrony -y 

#改配置
 cat /etc/chrony.conf 

 #没用的全删除了 
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server   news.neu.edu.cn iburst 
#server 0.centos.pool.ntp.org iburst


systemctl  start chronyd.service && systemctl  enable chronyd.service


测试 

故意超时 
date -s "2020-11-11 11:11:11"

哪个命令fix对了时间的
重启这个就行了 其实是不是不用动也行 过了阵就会自己同步
  systemctl restart chronyd.service

timedatectl set-ntp yes

chrony 使用

使用chronyc
你也可以通过运行chronyc命令来修改设置,命令如下:

accheck - 检查NTP访问是否对特定主机可用

activity - 该命令会显示有多少NTP源在线/离线



add server - 手动添加一台新的NTP服务器。

clients - 在客户端报告已访问到服务器

delete - 手动移除NTP服务器或对等服务器

settime - 手动设置守护进程时间

tracking - 显示系统时间信息



#有用 ?
将系统时间写入硬件时间

 sudo hwclock --systohc

老方法 centos7

#proxmox 上的 vm centos7 老是时间不对 ,以前用的ntpd老是不成功呢 

yum install ntp  -y
timedatectl set-timezone Asia/Shanghai
timedatectl set-ntp true
ntpq -p


#设置系统时间为中国时区并启用NTP同步
yum install ntp -y#//安装ntp服务
systemctl enable ntpd #//开机启动服务
systemctl start ntpd #//启动服务
timedatectl set-timezone Asia/Shanghai #//更改时区
timedatectl set-ntp yes # 用的是true ?//启用ntp同步
ntpq -p //同步时间



CentOS配置时间同步NTP
为什么要使用ntpd而不是ntpdate?
原因很简单,ntpd是步进式的逐渐调整时间,而ntpdate是断点更新,比如现在服务器时间是9.18分,而标准时间是9.28分,ntpd会在一段时间内逐渐的把时间校准到与标准时间相同,而ntpdate会立刻把时间调整到9.28分,如果你往数据库内写入内容或在其他对时间有严格要求的生产环境下,产生的后果会是很严重的。(注:当本地时间与标准时间相差30分钟以上是ntpd会停止工作)

NTP通信协议原理

/usr/sbin/ntpd: 主要提供 NTP 服务的程序啰!配置文件为 /etc/ntp.conf
/usr/sbin/ntpdate: 用于客户端的时间校正,如果你没有要启用 NTP 而仅想要使用 NTP Client 功能的话,那么只会用到这个指令而已啦!

#这个运行不了 ali的是直接跑在  /etc/ntpd.conf配置的   
*/10 * * * * /usr/sbin/ntpd cn.pool.ntp.org > /dev/null  2>&1

*/10 * * * * /usr/sbin/ntpdate cn.pool.ntp.org > /dev/null  2>&1

debian

UTC时区切换到CST 时区

#用这个啦 
# 设置亚洲时区
timedatectl set-timezone Asia/Shanghai
# 启用NTP同步 #关闭是 false 
timedatectl set-ntp yes


 echo "export TZ='Asia/Shanghai'"  >> /etc/profile  
 cat /etc/profile |grep TZ  
source /etc/profile
date -R
 date 
Sat Aug 19 17:03:17 CST 2017

debian 手工修改时间  

#将系统日期设定成1996年6月10日的命令
date -s 06/22/96

sudo  date  -s 10:20:00
sudo hwclock -w   #当前时间和日期写入BIOS,避免重启后失效 2020用了这种 有效果

我的kali

本本老是时间不对

ntpdate cn.pool.ntp.org #发现有效果 


1,查看debian当前时间
 debian:~# date

2,手动更改系统时间

 debian:~# date 120110552007.12
 顺序为      月 日时分 年 . 秒

3,同步Internet时间,首先安装时间同步软件

 apt-get install ntpdate

4,手动同步系统时间

 ntpdate cn.pool.ntp.org

5,如果重新启动后时间不是Internet时间可采取以下方法

vim   /etc/default/ntpdate
法1.修改/etc/default目录下的ntpdate
  在配置文件中发现了它设定时间服务器为cn.pool.ntp.org,
  
# Not used if NTPDATE_USE_NTP_CONF is yes.
NTPSERVERS="cn.pool.ntp.org  0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org"
#NTPSERVERS="0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org"

法2.做一个同步的脚本ntpupdate在开机时调用,内容如下

  #!/bin/sh
  /usr/sbin/ntpdate time.nist.gov | logger -t NTP
  /sbin/hwclock -w

Linux 修改系统时间成功未生效

使用 date -s “2019-02-02 02:02:02” 命令修改系统时间,提示修改成功但是系统时间未发生变化;


使用timedatectl命令查看系统时间

 timedatectl 
               Local time: Wed 2020-02-26 22:28:22 PST
           Universal time: Thu 2020-02-27 06:28:22 UTC
                 RTC time: Thu 2020-02-27 06:28:22
                Time zone: America/Los_Angeles (PST, -0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

关闭ntp同步 timedatectl set-ntp false



see also

Linux下使用timedatectl命令时间时区操作详解

Linux时间同步命令:ntpdate(系统时间)、hwclock(硬件时间)

Linux查看与修改时区、时间的命令

How To Set Up Time Synchronization on Debian 10

Centos7 NTP网络时间协议

CentOS 7 时间, 日期设置 (含时间同步)

http://cn.linux.vbird.org/linux_server/0440ntp.php

CentOS 7 时间, 日期设置

CentOS7 中使用NTP进行时间同步

使用NTP进行CentOS7时间同步

linux时间同步,ntpd、ntpdate

服务器时间同步


ntpd时钟同步服务

chrony

使用chrony代替ntp同步时间

详解:Linux Chrony 设置服务器集群同步时间

centos7.4 用chrony代替ntpd时间同步服务器

Centos 7.3_1611使用chrony做时间同步

linux中时间同步服务(chronyd服务)以及系统时间设定

CentOS7.2 chrony替代ntp搭建时间服务器

CentOS 7.x中正确设置时间与时钟服务器同步

CentOS7.2 chrony替代ntp搭建时间服务器