ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

day15

2022-03-21 22:37:29  阅读:171  来源: 互联网

标签:ntp 0224 day15 time yuanlai root ntpd


ntp时间服务部署

NTP是用来使计算机时间同步的一种协议。它可以使计算机对其服务器或时钟源做同步化,它可以提供高精准度的时间校正,切可介由加密确认的方式来防止恶意的协议攻击。

timedaectl

可以修改linux的日期,时间

cetnso6版本修改时间日期命令
		date 改时间日期(软件时间,你的系统运行了,程序计算的时间)
		hwclock  改硬件时间(计算的主板上,有一个BISO系统,以及纽扣电池,提供电量)
	
cetnso7版本修改时间命令,代替date
	timedatectl


查看系统中有哪些时区文件

ls /usr/share/zoneinfo/
ll /usr/share/zoneinfo/Asia/Shanghai


修改硬件时间:hwclock命令

具体参数

status                   Show current time settings 查看当前状态
  set-time TIME            Set system time  设置当前的时间 
  set-timezone ZONE        Set system time zone 设置当前的时区
  list-timezones           Show known time zones 查看系统支持哪些时区

查看当前时间

[root@localhost ~]#  timedatectl
      Local time: Mon 2022-03-21 22:00:34 CST
  Universal time: Mon 2022-03-21 14:00:34 UTC
        RTC time: Mon 2022-03-21 14:00:35
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a
[root@localhost ~]# 

解释:
当地时间
世界时间
RTC时间,本地硬件时钟,默认以UTC为准了
时区,亚洲上海
是否启用NTP
NTP同步状态
本地时区的RTC
DST是否激活

修改时间,时区

[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

ntp时间同步

强制同步时间命令  ntpdate

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

这个是强制性更新整个系统的时间,不友好的强制同步时间

搭建ntpd服务

1.安装ntp软件
yum install  ntp -y

2.找到ntp软件的配置文件
[root@yuanlai-0224 ~]# rpm -ql ntp |grep conf
/etc/ntp.conf
/etc/sysconfig/ntpd
/usr/share/man/man5/ntp.conf.5.gz


3.修改ntp配置文件,
vim /etc/ntp.conf, 做如下修改

driftfile /var/lib/ntp/drift


# 添加ntp的运行日志
logfile /var/log/my_ntp.log

# 记录程序的运行进程号的,可以用于写脚本,读取这个文件,就找到了程序的进程id
pidfile /var/run/ntpd.pid


# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default nomodify notrap nopeer noquery

# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict ::1

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).


server ntp.aliyun.com iburst prefer
server cn.pool.ntp.org iburst 


4.修改机器的时间为错误时间
[root@yuanlai-0224 ~]# timedatectl set-time '2018-11-8 10:00'
[root@yuanlai-0224 ~]# 
[root@yuanlai-0224 ~]# 
[root@yuanlai-0224 ~]# 
[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


5.启动ntpd服务,等待时间是否同步
关于ntpd的服务脚本文件/usr/lib/systemd/system/ntpd.service 

[root@yuanlai-0224 ~]# systemctl start  ntpd
[root@yuanlai-0224 ~]# 
[root@yuanlai-0224 ~]# 
[root@yuanlai-0224 ~]# systemctl status ntpd
● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
   Active: active (running) since 四 2018-11-08 10:01:43 CST; 1s ago
  Process: 20653 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 20654 (ntpd)
    Tasks: 1
   CGroup: /system.slice/ntpd.service
           └─20654 /usr/sbin/ntpd -u ntp:ntp -g

11月 08 10:01:43 yuanlai-0224 systemd[1]: Starting Network Time Service...
11月 08 10:01:43 yuanlai-0224 systemd[1]: Started Network Time Service.
11月 08 10:01:43 yuanlai-0224 ntpd[20654]: proto: precision = 0.026 usec
11月 08 10:01:43 yuanlai-0224 ntpd[20654]: 0.0.0.0 c01d 0d kern kernel time sync enabled
[root@yuanlai-0224 ~]# 
[root@yuanlai-0224 ~]# 
[root@yuanlai-0224 ~]# 



6.查看ntp是否和上游服务器同步
[root@yuanlai-0224 ~]# ntpstat
unsynchronised
   polling server every 64 s


7.查看时间同步的状态
uanlai-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
[root@yuanlai-0224 ~]# 

知识点拓展

解析域名的ip
 正常想到的去查找域名ip的命令就是ping,但是ping的真正用途是让你用来测试某个域名能不能和你正常连同,它是不是对外开放的
ping 会自动帮你去做域名查找
ping baidu.com
(ping 在你本机,去测一测,你和对方的机器,是否通信,ping命令会不断的发送数据包,给对方服务器,对方如果存活,会给你响应)

但是linux提供了更专业化的,域名查找,解析的命令

- dig

dig @223.5.5.5   你的域名



- nslookup (分为交互式和非交互式)

# 交互式,直接输入该命令
[root@yuanlai-0224 test_tar]# nslookup 
> www.yuchaoit.cn


Server:		114.114.114.114
Address:	114.114.114.114#53

Non-authoritative answer:
Name:	www.yuchaoit.cn
Address: 123.206.16.61



# 非交互式
[root@yuanlai-0224 test_tar]# nslookup apecome.com
Server:		114.114.114.114
Address:	114.114.114.114#53

Non-authoritative answer:
Name:	apecome.com
Address: 123.57.242.10

scp远程传输
语法
scp  源数据的机器   远程机器

scp -r   把自己的 /var/log/整个目录,全发过去

也可以从别人的机器上获取想要的数据 (前提是人家愿意)

scp  远程机器数据     想要放到自己机器的哪个目录

scp -r 远程机器     想要存放到自己的哪个目录

-r 参数就是递归传输一个目录下的所有东西

标签:ntp,0224,day15,time,yuanlai,root,ntpd
来源: https://www.cnblogs.com/xinxin0425/p/16037006.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有