《Linux系统搭建NTP服务器教程.docx》由会员分享,可在线阅读,更多相关《Linux系统搭建NTP服务器教程.docx(7页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Linux系统搭建NTP服务器教程实施环境服务器配置:虚拟机,2cpu,2G内存,50G硬盘linux 系统:服务器 步骤一:操作系统安装步骤略过,进入操作系统,首先手动配置IP地址#vi /etc/sysconfig/network-scripts/ifcfg-eth0注:最后一个讦cfg-ethO为网卡名称rootlocalhost # cat /etc/sysconfig/network-scripts/ifcfg-ethO TYPE=EthernetPROXY_METHOD=noneBROWSER_ONLY=nO ).BOOTPROTO=Stati c DEFROUTE=yeS IPV
2、4_FAILURE_FATAL=no !PV6lNlT=yes IPV6_AUTOCONF=yes IPV6-DEFROUTE=yes IPV6_FAILURE_FATAL=no lPV6_ADDR_GEN_MODE=stable-pri vacy NAME=ethOUUID=le6d826O-b587-4cdc-9663-7676dl3319eODEVICE=ethO , ONBOOT=yesroca!hcGT需配置的几个关键参数如上图红色地方。修改后重启一下网络服务即可#systemctl restart network步骤二:安装NTP服务1、检查该系统是否已安装NTP服务rpm -q
3、ntprootlocalhost # ntD-4 2 6P5-29 el7 centos.x86_64已安装,可直接编辑/etc/ntp.conf配置文件。2、如未安装,使用如下命令在线安装。#yum install ntpdate ntp -y安装完可用1的命令再检查是否安装成功。步骤三:修改ntp配置文件,红色字体是修改项。vi /etc/ntp.confFor more information about this file, see the man pages# ntp.conf(5) ntp_acc,ntp_auth(5) ntp_clock,ntp_misc,ntp_mon (5)
4、.driftfile /var/lib/ntp/drift新增:日志目录.不需要可不配置logfile /var/log/ntpd.logPermit 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 #允许所有客户端同步时间Permit all access over the loopback interface. This could# b
5、e tightened as well, but to do so would effect some ofthe administrative functions.restrict :1# Hosts on local network are less restricted.# restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap这一行的含义是授权0网段的客户端可以从这台机器上查询和同步时间.需将上一条 命令注释掉restrict 10.0.0.0 mask 255.0.0.0 nomodify notrapUse public se
6、rvers from the project.# Please consider joining the pool ().# server iburstserver iburst# server iburstserver iburst#新增:配置国内公共的时间服务器列表.也可换成别的地址server #broadcast 192.168.1.255 autokey # broadcast server#broadcastclient # broadcast client#broadcast 224.0.1.1 autokey # multicast server#muIticastclient
7、 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.#cryptoincludefile /etc/ntp/crypto/pw# Key file containing the keys and key identifiers used when operatingwith symmetric key crypto
8、graphy.keys /etc/ntp/keysSpecify the key identifiers which are trusted.# trustedkey 4 8 42Specify the key identifier to use with the ntpdc utility.# requestkey 8Specify the key identifier to use with the ntpq utility.# controlkey 8Enable writing of statistics records.#statistics clockstats cryptosta
9、ts loopstats peerstatsDisable the monitoring facility to prevent amplification attacks using ntp de# monlist command when default restrict does not include the noquery flag. S eeCVE-2013-5211 for more details.# Note: Monitoring will not be disabled with the limited restriction flag.disable monitor注:
10、修改后记得保存配置文件。restrict控制相关权限。语法为:restrict IP地址mask子网掩码 参数其中IP地址也可以是default , default就是指所有的IP。参数有以下几个:ignore :关闭所有的NTP联机服务nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务 端进行网络校时。notrust :客户端除非通过认证,否那么该客户端来源将被视为不信任子网noquery :不提供客户端的时间查询:用户端不能使用ntpq, ntpc等命令 来查询ntp服务器notrap :不提供trap远端登陆:拒绝为匹配的主机提供模式6控制消息 陷阱服务。陷阱服务是
11、ntpdq控制消息协议的子系统,用于远程事件日志记录 程序。nopeer :用于阻止主机尝试与服务器对等,并允许欺诈性服务器控制时 钟kod :访问违规时发送KoD包。restrict -6表示IPV6地址的权限设置。步骤四:设置NTP服务开机启动systemctl enable ntpd# systemctl enable ntpdatesystemctl is-enabled ntpdrootlocalhost j# systemctl enable ntpdcreated symlink from /etc/systemd/system/multi-user.target.wants/n
12、tpd.service to /usr/lib/syste md/system/ntpcl. servi ce.root!ocalhost # systemctl enable ntpdateCreated symlink from /etc/systemd/system/multi-user.target.wants/ntpdate.service to /usr/lib/sy stemd/system/ntpdate.service.步骤五:启用ntp服务启动服务systemctl start ntpd查看NTP服务运行状态systemctl status ntpdrootlocalhos
13、t rootlocalhost ntpd.IUW# systemctI status ntpd eiwurk lime Aervlyservicelead G/uqr/Hh/fyqTQmd/y5Pm/nrprL rvirp; enabled; vendor preset: disabled) Active: active (running) iince 星崩二 2019-09-24 21:21:24 +08; 18h agoI carlad qM-4 13645 (rvtRd) ICGroup: /system, slice/ntpd. 113645 /usr/sbin/ntpd -u ntp
14、:ntp -g2421:21:241ocalhost.1ocaldomainntpd 13645:2421:21:241ocalhost.1ocaldomainntpd13645:2421:21:241ocalhost.1ocaldomainntpd 13645:2421:21:241ocalhost.1ocaldomainntpd13645:2421:21:241ocalhost.1ocaldomainntpd 13645:2421:21:241ocalhost.1ocaldomai nntpd13645:2421:21:241ocalhost.1ocaldomainntpd13645:24
15、21:24:401ocalhost.1ocaldomainntpd13645:2421:39:581ocalhost.1ocaldomainntpd 13645:2421:39:581ocalhost.1ocaldomainntpd13645:Some lineswere ellipsi zed, use -1 to show inrootlocalhost #Listen normally on m etho 10.1.0.145 UDP 123Listen normally on T lu . .1 UUP 1251Listen normally on 5 etho fe80:2ab3:a
16、5a2:122f.123 Listening on routing socket on fd #22 for inte.tes 0.0.0.0 c016 06 restart0.0.0.0 c012 02 freq_set kernel 0.000 PPM0.0.0.0 cOll 01 freq_not_set0.0.0.0 c614 04 freq_mode0.0.0.0 0612 02 freq_set kernel 0.576 PPM0.0.0.0 0615 05 clock_sync full.注:红色框的几个地方,状态active(running)说明服务运行,右下角红色 框为监听端
17、口 UDP 123o步骤六:本机防火墙放行UDP 123端口。Centos7安装完默认防火墙是启用状态,并且未放行业务端口,需手动放 行端口或关闭防火墙,为了服务器安装,建议采用放行端口的方式。# firewall-cmd -permanent -add-service=ntpfirewall-cmd -reload 增加放行端口必须要reload不然没生效NTP服务器配置完成。测试:NTP客户端:windows 7系统如上图所示,勾选与internet时间服务器同步,服务器输入框里填NTP服 务器IP地址,点立即更新按钮。等待一会下面出面同步成功的提示,说明NTP服务正常。如下出现如下提示,说明NTP服务端有问题,需要排查故障。Internet时间设置L公配置Internet时间设置:团与Internet时间照务器同步服务器: 广蠲嬴Windows在与进行同步时出错。臼于超时时间已过r该操作返 回.2019-09-25上时钟最近在15:52同步。2 取消排查故障大概的思路:1、确定NTP客户端与服务端的网络是否可达。2、确定NTP服务端的服务是否启动。3、确定NTP服务器的防火墙是否有放行端口或关闭防火墙。4、确定NTP客户端与服务端的网络中是否还有硬件防火墙阻止。5、以上排除完再检查ntp.conf配置文件的配置是否正确。
限制150内