1.1 查看系统是否已经安装ntp服务组件
rpm -qa | grep "ntp" #<==查看是否已经安装ntp组件,有如下两个组件说明已经安装
ntpdate-4.2.6p5-1.el6.centos.x86_64
ntp-4.2.6p5-1.el6.centos.x86_64
1.2 yum安装
yum -y install ntp
1.3 ntp服务器端的配置
1.3.1 配置文件
Ø 配置文件
/etc/ntp.conf
Ø 配置文件默认内容
egrep -v "^$|#" /etc/ntp.conf #<==排除默认注释及空行
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery #<==对默认的client拒绝所有操作
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1 #<==允许本地地址的一切操作
restrict -6 ::1
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
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
Ø 修改配置
cat /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery #<==对默认的client拒绝所有操作
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1 #<==允许本机的一切操作
restrict 192.168.1.0 mask 255.255.255.0 nomodify #<==允许局域网内所有client连接到这台服务器
restrict -6 ::1 同步时间.但是拒绝让他们修改服务器上的时间
#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 ntp1.aliyun.com #<==同步公网的时间
server 127.127.1.0 #<==如果无法连接公网,则使用自己本身的时间作为标准时间。
fudge 127.127.1.0 stratum 10 #<==设置stratum级别
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
1.4服务启动
systemctl start ntpd
systemctl enable ntpd
1.5客户端同步
yum -y install ntpdate
ntpdate -u IP地址(ntp服务的IP地址)