CentOS7搭建NTP服务器及客户端同步时间
一、搭建NTP服务器
1、查看服务端操作系统版本
[root@web ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1804 (Core)
2、查看服务器是否安装ntp,系统默认安装ntpdate;
[root@web ~]# rpm -qa | grep ntp
3、安装ntp ntpdate,其中ntpdate默认安装,可以只安装ntp;
#yum install ntp ntpdate -y
4、修改配置文件,使该NTP服务器在不联网的情况下,使用本服务器的时间作为同步时间
#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
5、启动ntp服务并次查看服务器状态
#systemctl start ntpd
systemctl status ntpd
6、查看是否同步状态
[root@web ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
*LOCAL(0) .LOCL. 5 l 20 64 7 0.000 0.000 0.000
7、设置开机启动
systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd
service.
8、设置防火墙,打开udp123端口或者直接关闭防火墙(如关闭防火墙改步可跳过)
firewall-cmd --permanent --add-port=123/udp
success
firewall-cmd --reload
success
#iptables -L -n 查看防火墙已打开端口
二、客户端配置
1、查看客户端操作系统版本
[root@web ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1804 (Core)
2、查看服务器是否安装ntp,系统默认安装ntpdate;
[root@web ~]# rpm -qa | grep ntp
3、安装ntp ntpdate,其中ntpdate默认安装,可以只安装ntp;
#yum install ntp ntpdate -y
4、修改配置文件,修改配置文件,将刚刚搭建好的NTP服务器作为客户端上游时间服务器
#vim /etc/ntp.conf
5、与本地ntpd Server同步一下
#ntpdate -u 192.168.0.163
- List item
6、启动ntp服务并次查看服务器状态
#systemctl start ntpd
systemctl status ntpd
7、查看同步状态
ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*192.168.0.163 LOCAL(0) 11 u 21 64 377 0.068 -0.824 0.367
8、设置开机启动
systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd
service.