首页 > 其他分享 >时间服务

时间服务

时间:2023-07-11 16:13:07浏览次数:20  
标签:服务 21 ntp 0224 时间 time yuanlai root

时间服务

  • 先理解时间对服务器的重要性

  • 全世界的服务器,时间统一标准,可以以这个为准,cn.ntp.org.cn

  • 学习linux的各种命令,对时间来修改,以及同步

timedaectl

可以修改linux的日期,时间

timedatectl
	date 改时间日期(软件时间,你的系统运行了,程序计算的时间)
	hwclock 改硬件时间(计算的主板上,有一个BISO系统,以及纽扣电池,提供电量)
修改时间、日期、date命令
centos6的修改时区的操作,时区就以亚洲上海为准了
修改时区,cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

# 查看系统中有哪些时区文件
ls /usr/share/zoneinfo/
ll /usr/share/zoneinfo/Asia/Shanghai

修改硬件时间使用 hwclock 命令

查看当前时间

[root@yuanlai-0224 ~]# timedatectl 
      Local time: 一 2022-03-21 12:21:42 CST(中国时区)
  Universal time: 一 2022-03-21 04:21:42 UTC
        RTC time: 一 2022-03-21 04:21:38
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a
[root@yuanlai-0224 ~]# 
[root@yuanlai-0224 ~]# 

[root@yuanlai-0224 ~]# timedatectl status
      Local time: 一 2022-03-21 12:21:46 CST
  Universal time: 一 2022-03-21 04:21:46 UTC
        RTC time: 一 2022-03-21 04:21:42
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

修改时间、修改时区

[root@yuanlai-0224 ~]# timedatectl --help
timedatectl [OPTIONS...] COMMAND ...

Query or change system time and date settings.

  -h --help                Show this help message
     --version             Show package version
     --no-pager            Do not pipe output into a pager
     --no-ask-password     Do not prompt for password
  -H --host=[USER@]HOST    Operate on remote host
  -M --machine=CONTAINER   Operate on local container
     --adjust-system-clock Adjust system clock when changing local RTC mode

指令
Commands:
  status                   Show current time settings 查看当前状态
  set-time TIME            Set system time  设置当前的时间 
  set-timezone ZONE        Set system time zone 设置当前的时区
  list-timezones           Show known time zones 查看系统支持哪些时区
  
  
  
  set-local-rtc BOOL       Control whether RTC is in local time
  set-ntp BOOL             Control whether NTP is enabled
[root@yuanlai-0224 ~]# timedatectl set-time '10:00'

[root@yuanlai-0224 ~]# timedatectl set-time '2018-11-8 10:00'

查看系统支持多少个时区
[root@yuanlai-0224 ~]# timedatectl list-timezones | wc -l
425

找出关于上海的时区,具体名字
[root@yuanlai-0224 ~]# timedatectl list-timezones | grep  -i   'shanghai'
Asia/Shanghai
[root@yuanlai-0224 ~]# timedatectl set-timezone Asia/Shanghai

ntp时间同步

  • 强制性更新整个系统的时间,ntpdate,不友好的强制同步时间
  • 搭建ntp服务,自动的,友好的更新,校准系统时间

其强制性ntpdate命令

1.找到时间服务器地址,强制更新即可
[root@yuanlai-0224 ~]# ntpdate -u ntp.aliyun.com


[root@yuanlai-0224 ~]# ntpdate -u ntp.aliyun.com
21 Mar 12:31:11 ntpdate[19892]: step time server 203.107.6.88 offset 106194278.720730 sec


[root@yuanlai-0224 ~]# timedatectl status
      Local time: 一 2022-03-21 12:31:32 CST
  Universal time: 一 2022-03-21 04:31:32 UTC
        RTC time: 四 2018-11-08 02:06:54
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

搭建ntpd服务

1.安装ntp软件

yum install  ntp -y

2.查看ntp软件信息

ls /usr/lib/systemd/system/ |grep ntp
ntpdate.service
ntpd.service

3.找到ntp软件的配置文件

rpm -ql ntp |grep conf
/etc/ntp.conf
/etc/sysconfig/ntpd
/usr/share/man/man5/ntp.conf.5.gz

4.修改ntp配置文件

vim /etc/ntp.conf

# 新增如下的配置
# 添加ntp的运行日志
logfile /var/log/my_ntp.log
# 记录程序的运行进程号的,可以用于写脚本,读取这个文件,就找到了程序的进程id
pidfile /var/run/ntpd.pid
# 修改同步的ntp服务节点为如下
server ntp.aliyun.com iburst prefer
server cn.pool.ntp.org iburst 

5.修改机器的时间为错误时间

[root@yuanlai-0224 ~]# timedatectl set-time '2018-11-8 10:00'
[root@yuanlai-0224 ~]# timedatectl 
      Local time: 四 2018-11-08 10:00:04 CST
  Universal time: 四 2018-11-08 02:00:04 UTC
        RTC time: 四 2018-11-08 02:00:04
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

6.启动ntpd服务,等待时间是否同步

[root@yuanlai-0224 ~]# systemctl start  ntpd
[root@yuanlai-0224 ~]# systemctl status ntpd

7.查看ntp是否和上游服务器同步

[root@yuanlai-0224 ~]# ntpstat
unsynchronised
   polling server every 64 s

8.查看时间同步的状态

[root@yuanlai-0224 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 120.25.115.20   .STEP.          16 u    -   64    0    0.000    0.000   0.000
 203.107.6.88    10.137.38.86     2 u   28   64    1   26.495   -5.532  20.580
 a.chl.la        131.188.3.222    2 u   25   64    1  275.482   52.054  13.988
  1. 这台机器,就是一个时间服务器了,可以作为上游机器使用

date命令和hwclock命令

可以直接用timedatectl替代了

timedatectl直接修改硬件+软件时间了。

让软件时间和硬件时间同步

hwclock 可以将硬件和软件时间做同步
 -s, --hctosys        将硬件时钟同步为当前系统时间
 -w, --systohc        将当前系统时间同步为硬件时钟

标签:服务,21,ntp,0224,时间,time,yuanlai,root
From: https://www.cnblogs.com/chunjeh/p/17544999.html

相关文章

  • 云服务器的连接,客户端出现“服务器发送了一个意外的数据包。received: 3,expected: 2
    云服务器的连接,客户端出现“服务器发送了一个意外的数据包。received:3,expected:20的解决方案编辑/etc/ssh/sshd_config文件并添加四行代码ClientAliveInterval60ClientAliveCountMax3PermitRootLoginyesKexAlgorithmscurve25519-sha256@libssh.org,ecdh-sha2-......
  • 服务器数据恢复-RAID5故障导致ESXI虚拟机数据丢失的数据恢复案例
    服务器数据恢复环境:曙光某型号光纤存储柜,16块光纤磁盘组建了2组RAID5磁盘阵列,每组raid5阵列中有7块成员盘,另外2块磁盘配置为全局热备盘使用。第一组RAID5阵列划分了3个LUN:1个LUN分配给linux主机、第2个LUN分配给sun小型机,第3个LUN分配给esxi主机。第二组RAID5阵列全部分配给一台......
  • zabbix使用ICMP Ping模版实现对客户端网络状态的监控,监控丢包率、响应时间
    参考网站使用fping报错注意事项监控路由器丢包率:http://www.mamicode.com/info-detail-1519866.html(未测试)@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Zabbix使用外部命令fping处理ICMPping的请求,fping不包含在zabbix的发行版本中,需要额外去下载安装fping程序,安装完毕......
  • finshell 连接不到服务器,报Session.connect: java.net.SocketException: Connection r
    用finshell一段时间了,非常不错,但是有段时间突然连接不上服务器,各种重装,重启服务器都不行,在网上搜方法也没有好的办法。在我一次实在烦的不得了的时候,让我发现一个好的解决方案。先上图: 是不是出现这个问题,那么我的解决方案是啥呢?看我的手速,就是点击红色的闪电图标,一般连续点击......
  • sqlserver报错 "代理XP“组件已作为此服务器安全配置的一部分被关闭。系统管理员可以
    1、https://blog.csdn.net/fallingflower/article/details/128915014想为SQLServer数据库设置自动备份,点击维护计划向导的时候报错“代理XP"组件已作为此服务器安全配置的一部分被关闭。系统管理员可以使用sp_configure来启用"代理XP”。有关启用"代理XP"的详细信息,请参阅SQL......
  • C# DateDiff 计算时间间隔
     Dimdate2EnteredAsString=InputBox("Enteradate")TryDimdate2AsDate=Date.Parse(date2Entered)Dimdate1AsDate=Now'Determinethenumberofdaysbetweenthetwodates.DimdaysAsLong=DateDiff(DateInterv......
  • sshd服务部署
    sshd服务部署软件安装修改配置文件启动使用​1、搭建所有服务的套路关闭防火墙和selinux(实验环境都先关闭掉)配置yum源(公网源或者本地源)软件安装和检查了解并修改配置文件启动服务检查运行状态并设置开机自启动2、搭建SSH服务这部分内容可以参考于超老师......
  • 时间同步服务chrony的简单配置 (1)
    chrony配置手册一,chrony服务器的简介概述·chrony是一个开源自由的网络时间协议NTP的客户端和服务器软软件。它能让计算机保持系统时钟与时钟服务器(NTP)同步,因此让你的计算机保持精确的时间,Chrony也可以作为服务端软件为其他计算机提供时间同步服务。·chrony由两个程序组成,分......
  • pycharm安装django失败,原因是报了一个ssl异常,也就是说和国外源站服务器ssl失败。 所
    pycharm安装django失败,原因是报了一个ssl异常,也就是说和国外源站服务器ssl失败。所以选用国内源站安装:选中Options,输入:“-ihttps://pypi.tuna.tsinghua.edu.cn/simple” ......
  • 2023.7.10值得推荐的一款服务器空间
    已经体验一个月咯,非常不错的免费资源,适合大家去了解了解~!他们家的免费空间,免费服务器,非常稳定,非常靠谱,值得拥有,价格厚道~!免备案服务,域名管理等等服务,应有尽有,2023年你值得了解,他们家的免费云服务器还是独立IP的哦,非常非常好,非常NICE~! ......