查看安装
[root@localhost ~]# rpm -qa | grep ntp
fontpackages-filesystem-1.44-8.el7.noarch
ntpdate-4.2.6p5-29.el7.centos.x86_64
python-ntplib-0.3.2-1.el7.noarch
安装相应的包
[root@localhost ~]# yum install ntp ntpdate -y
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.bfsu.edu.cn
* extras: mirrors.163.com
* updates: mirrors.163.com
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
正在解决依赖关系
--> 正在检查事务
---> 软件包 ntp.x86_64.0.4.2.6p5-29.el7.centos.2 将被 安装
--> 正在处理依赖关系 libopts.so.25()(64bit),它被软件包 ntp-4.2.6p5-29.el7.centos.2.x86_64 需要
---> 软件包 ntpdate.x86_64.0.4.2.6p5-29.el7.centos 将被 升级
---> 软件包 ntpdate.x86_64.0.4.2.6p5-29.el7.centos.2 将被 更新
--> 正在检查事务
---> 软件包 autogen-libopts.x86_64.0.5.18-5.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=======================================================================================
Package 架构 版本 源 大小
=======================================================================================
正在安装:
ntp x86_64 4.2.6p5-29.el7.centos.2 base 549 k
正在更新:
ntpdate x86_64 4.2.6p5-29.el7.centos.2 base 87 k
为依赖而安装:
autogen-libopts x86_64 5.18-5.el7 base 66 k
事务概要
=======================================================================================
安装 1 软件包 (+1 依赖软件包)
升级 1 软件包
总计:701 k
总下载量:615 k
Downloading packages:
(1/2): autogen-libopts-5.18-5.el7.x86_64.rpm | 66 kB 00:00:00
(2/2): ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm | 549 kB 00:00:00
---------------------------------------------------------------------------------------
总计 1.5 MB/s | 615 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : autogen-libopts-5.18-5.el7.x86_64 1/4
正在更新 : ntpdate-4.2.6p5-29.el7.centos.2.x86_64 2/4
正在安装 : ntp-4.2.6p5-29.el7.centos.2.x86_64 3/4
清理 : ntpdate-4.2.6p5-29.el7.centos.x86_64 4/4
验证中 : ntpdate-4.2.6p5-29.el7.centos.2.x86_64 1/4
验证中 : ntp-4.2.6p5-29.el7.centos.2.x86_64 2/4
验证中 : autogen-libopts-5.18-5.el7.x86_64 3/4
验证中 : ntpdate-4.2.6p5-29.el7.centos.x86_64 4/4
已安装:
ntp.x86_64 0:4.2.6p5-29.el7.centos.2
作为依赖被安装:
autogen-libopts.x86_64 0:5.18-5.el7
更新完毕:
ntpdate.x86_64 0:4.2.6p5-29.el7.centos.2
完毕!
再次查看 发现ntp-4.2.6p5-29.el7.centos.2.x86_64已安装
[root@localhost ~]# rpm -qa | grep ntp
ntpdate-4.2.6p5-29.el7.centos.2.x86_64
fontpackages-filesystem-1.44-8.el7.noarch
ntp-4.2.6p5-29.el7.centos.2.x86_64
python-ntplib-0.3.2-1.el7.noarch
显示ntp状态
[root@localhost ~]# systemctl status ntpd
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)
编辑内置文件设置无网络同步本机时间
[root@localhost ~]# vim /etc/ntp.conf
把如下四行代码注释掉:
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
在下面再添加一行:
server 127.127.1.0 iburst
启动服务
[root@localhost ~]# systemctl start ntpd
[root@localhost ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*LOCAL(0) .LOCL. 5 l 9 64 1 0.000 0.000 0.000
设置开机启动
[root@localhost ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
ntp服务使用的UDP协议的123端口
firewall-cmd --add-service=ntp --permanent
firewall-cmd --reload
[root@localhost ~]# firewall-cmd --permanent --add-port=123/udp
success
[root@localhost ~]# firewall-cmd --reload
success
查看打开的端口
[root@localhost ~]# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:53
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:53
ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:67
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:67
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
INPUT_direct all -- 0.0.0.0/0 0.0.0.0/0
INPUT_ZONES all -- 0.0.0.0/0 0.0.0.0/0
DROP all -- 0.0.0.0/0 0.0.0.0/0 ctstate INVALID
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- 0.0.0.0/0 192.168.122.0/24 ctstate RELATED,ESTABLISHED
ACCEPT all -- 192.168.122.0/24 0.0.0.0/0
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
FORWARD_direct all -- 0.0.0.0/0 0.0.0.0/0
FORWARD_IN_ZONES all -- 0.0.0.0/0 0.0.0.0/0
FORWARD_OUT_ZONES all -- 0.0.0.0/0 0.0.0.0/0
DROP all -- 0.0.0.0/0 0.0.0.0/0 ctstate INVALID
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:68
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
OUTPUT_direct all -- 0.0.0.0/0 0.0.0.0/0
Chain FORWARD_IN_ZONES (1 references)
target prot opt source destination
FWDI_public all -- 0.0.0.0/0 0.0.0.0/0 [goto]
FWDI_public all -- 0.0.0.0/0 0.0.0.0/0 [goto]
Chain FORWARD_OUT_ZONES (1 references)
target prot opt source destination
FWDO_public all -- 0.0.0.0/0 0.0.0.0/0 [goto]
FWDO_public all -- 0.0.0.0/0 0.0.0.0/0 [goto]
Chain FORWARD_direct (1 references)
target prot opt source destination
Chain FWDI_public (2 references)
target prot opt source destination
FWDI_public_log all -- 0.0.0.0/0 0.0.0.0/0
FWDI_public_deny all -- 0.0.0.0/0 0.0.0.0/0
FWDI_public_allow all -- 0.0.0.0/0 0.0.0.0/0
ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
Chain FWDI_public_allow (1 references)
target prot opt source destination
Chain FWDI_public_deny (1 references)
target prot opt source destination
Chain FWDI_public_log (1 references)
target prot opt source destination
Chain FWDO_public (2 references)
target prot opt source destination
FWDO_public_log all -- 0.0.0.0/0 0.0.0.0/0
FWDO_public_deny all -- 0.0.0.0/0 0.0.0.0/0
FWDO_public_allow all -- 0.0.0.0/0 0.0.0.0/0
Chain FWDO_public_allow (1 references)
target prot opt source destination
Chain FWDO_public_deny (1 references)
target prot opt source destination
Chain FWDO_public_log (1 references)
target prot opt source destination
Chain INPUT_ZONES (1 references)
target prot opt source destination
IN_public all -- 0.0.0.0/0 0.0.0.0/0 [goto]
IN_public all -- 0.0.0.0/0 0.0.0.0/0 [goto]
Chain INPUT_direct (1 references)
target prot opt source destination
Chain IN_public (2 references)
target prot opt source destination
IN_public_log all -- 0.0.0.0/0 0.0.0.0/0
IN_public_deny all -- 0.0.0.0/0 0.0.0.0/0
IN_public_allow all -- 0.0.0.0/0 0.0.0.0/0
ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
Chain IN_public_allow (1 references)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:22 ctstate NEW,UNTRACKED
ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:123 ctstate NEW,UNTRACKED
Chain IN_public_deny (1 references)
target prot opt source destination
Chain IN_public_log (1 references)
target prot opt source destination
Chain OUTPUT_direct (1 references)
target prot opt source destination
安装ntp
[root@localhost ~]# yum install ntp ntpdate -y
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.bfsu.edu.cn
* extras: mirrors.163.com
* updates: mirrors.163.com
软件包 ntp-4.2.6p5-29.el7.centos.2.x86_64 已安装并且是最新版本
软件包 ntpdate-4.2.6p5-29.el7.centos.2.x86_64 已安装并且是最新版本
无须任何处理
配置文件
[root@localhost ~]# vim /etc/ntp.conf
把如下四行代码注释掉:
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
添加
server 192.168.49.132
rsetrict 192.168.49.132 nomodify notrap noquery
与本地ntpd Server同步一下
[root@localhost ~]# ntpdate -u 192.168.49.132
启动ntp服务
[root@localhost ~]# systemctl start ntpd
设置ntp服务开机自启
[root@localhost ~]# systemctl enable ntpd
7.查看状态
[root@localhost ~]# ntpq -p