学习笔记-Linux – NTP服务器部署

学习笔记-Linux – NTP服务器部署NTP 服务器搭建基本安装 检查系统是否安装有 NTP 服务 rpm qa grep ntp 安装 yum 服务 yum y install ntp ntpdate 设定时区 timedatectl set timezone

欢迎大家来到IT世界,在知识的湖畔探索吧!

NTP服务器搭建

基本安装

# 检查系统是否安装有NTP服务 rpm -qa | grep ntp # 安装yum服务 yum -y install ntp ntpdate # 设定时区 timedatectl set-timezone Asia/Shanghai # 选单设定时区 tzselect 5 9 1 1 # 将时区信息拷贝,覆盖原来的时区信息 cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

欢迎大家来到IT世界,在知识的湖畔探索吧!

环境配置

欢迎大家来到IT世界,在知识的湖畔探索吧!# 修改配置文件 nano /etc/ntp.conf

ntp.conf文件注释

# 第4行, 记录时间误差 driftfile /var/lib/ntp/drift # 无,替代第5行,新增日志文件 logfile /var/log/ntpd.log # 第8行,对NTP服务器作出限制,默认不限制。 # ignore:忽略所有类型的NTP连接请求 # nomodify:限制客户端不能使用命令ntpc和ntpq来修改服务器端的时间 # noquery:不提供NTP网络校时服务 # notrap:不接受远程登录请求 # notrust:不接受没有经过认证的客户端的请求 restrict default nomodify notrap nopeer noquery # 第17行,下方增加 restrict 172.16.28.0 mask 255.255.255.0 nomodify notrap # 第21~24行,NTP服务器地址 server ntp.aliyun.com server time1.cloud.tencent.com server 210.72.145.44 server time.windows.com # 无,替代第25行,使用本地作为NTP服务器 # startum为时间服务器的层次,0最高,默认设置10 fudge 127.0.0.1 stratum 10 

CentOS 7.9 默认ntp.conf文件

启动NTP服务器

欢迎大家来到IT世界,在知识的湖畔探索吧!# 同步系统时间 sudo ntpdate -u ntp.aliyun.com # 重新启动NTP服务 systemctl restart ntpd # 设置NTP服务为开机自启动 systemctl enable ntpd # 防火墙放行NTP服务 firewall-cmd --permanent --add-service=ntp && firewall-cmd --reload # 验证NTP服务是否正常启动,123端口被占用则表示成功启动 systemctl status ntpd | grep Active ; netstat -tlunp | grep ntp # 将当前日期时间写入 echo "SYNC_HWCLOCK=yes" >> /etc/sysconfig/ntpd # 验证NTP服务器 ntpq -p # 时间服务器生效时间比较长,需要等待很久才能同步时间
学习笔记-Linux - NTP服务器部署



欢迎大家来到IT世界,在知识的湖畔探索吧!

remote:即NTP主机的IP或主机名称。注意最左边的符号,如果由“+”则代表目前正在作用钟的上层NTP,如果是“*”则表示也有连上线,不过是作为次要联机的NTP主机。 refid:参考的上一层NTP主机的地址 st:即stratum阶层 when:几秒前曾做过时间同步更新的操作 poll:下次更新在几秒之后 reach:已经向上层NTP服务器要求更新的次数 delay:网络传输过程钟延迟的时间 offset:时间补偿的结果 jitter:Linux系统时间与BIOS硬件时间的差异时间

配置NTP服务

欢迎大家来到IT世界,在知识的湖畔探索吧!sudo yum -y install ntp # 配置NTP服务器地址 sudo ntpdate {NTP服务器地址} sudo ntpdate 172.16.28.122 # 设置本机时区为中国上海 timedatectl set-timezone Asia/Shanghai # 将当前时间写入BIOS sudo hwclock --localtime --systohc # 查看系统时间 timedatectl
学习笔记-Linux - NTP服务器部署

时区

时区概念

# UTC 整个地球分为二十四时区,每个时区都有自己的本地时间,在国际无线电通信场合,为了统一起见,使用一个统一的时间,称为通用协调时 # GMT 格林威治标准时间指位于英国伦敦郊区的皇家格林尼治天文台的标准时间,因为本初子午线被定义在通过那里的经线(UTC与GMT时间基本相同) # CST 中国标准时间 CST = UTC+8 = GMT+8 # DST 夏令时指在夏天太阳升起的比较早时,将时间拨快一小时,以提早日光的使用,中国不使用

时区相关命令

欢迎大家来到IT世界,在知识的湖畔探索吧!# 查看系统时区 timedatectl # 设置系统时区 timedatectl list-timezones timedatectl set-timezone Asia/Shanghai

原版配置文件

# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

driftfile /var/lib/ntp/drift

# 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 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst

#broadcast 192.168.1.255 autokey    # broadcast server
#broadcastclient            # broadcast client
#broadcast 224.0.1.1 autokey        # multicast server
#multicastclient 224.0.1.1        # multicast client
#manycastserver 239.255.254.254        # manycast server
#manycastclient 239.255.254.254 autokey # manycast client

# Enable public key cryptography.
#crypto

includefile /etc/ntp/crypto/pw

# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography. 
keys /etc/ntp/keys

# Specify the key identifiers which are trusted.
#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.
#requestkey 8

# Specify the key identifier to use with the ntpq utility.
#controlkey 8

# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats

# Disable the monitoring facility to prevent amplification attacks using ntpdc
# monlist command when default restrict does not include the noquery flag. See
# CVE-2013-5211 for more details.
# Note: Monitoring will not be disabled with the limited restriction flag.
disable monitor
学习笔记-Linux - NTP服务器部署

学习笔记-Linux - NTP服务器部署

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://itzsg.com/114906.html

(0)
上一篇 38分钟前
下一篇 13分钟前

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

联系我们YX

mu99908888

在线咨询: 微信交谈

邮件:itzsgw@126.com

工作时间:时刻准备着!

关注微信