目录
前言
ntp服务作为内网常用的时钟同步服务,在集群的搭建中有比较常见的使用
一、Ntp
Ntp 作为内网常用的时钟同步服务,在银河麒麟V10 SP1 到 SP2 服务器操作系统当中默认继承了相关软件包。
二、使用步骤
1.矫正本机时区/时间
1.# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 2.# date -s "12/10/16 09:44" 3.# hwclock -w 把系统时间同步到硬件时间
2.配置主配置文件
driftfile /var/lib/ntp/drift 记录上次的ntp服务与上层ntp服务连接所花费的时间
restrict default kod nomodify notrap nopeer noquery //对默认的客户端拒绝所有操作
restrict -6 default kod nomodify notrap nopeer noquery //针对ipv6的设置
restrict 127.0.0.1 //允许本地地址一切的操作 127.0.0.1本地回环地址
restrict -6 ::1
server 0.rhel.pool.ntp.org iburst //设置上层服务器做同步ip地址(内网ntp服务器的上一级ntp服务器)
server 1.rhel.pool.ntp.org iburst
server 2.rhel.pool.ntp.org iburst
server 3.rhel.pool.ntp.org iburst
server 127.127.1.0 // local地址,根据实际网络来指定
fudge 127.127.1.0 stratum 10 //这行是服务器的层次。设置为0则为顶级 0—16
server 192.168.1.5
fudge 192.168.1.5 stratum 10
server 201.72.145.44 //中国国家时间授权中心 设定服务器
3.重启ntp服务
5./etc/init.d/ntpd restart
6.netstat -tulnp | grep ntp
7.ntpstat 检测服务器自身是否同步
8.ntpstat 查看服务器状态(重启ntp需要5分钟)
ntpstat
synchronised to local net at stratum 11 //进行时间校对的ntp服务器
time correct to within 12 ms //本地主机与上层ntp服务器的时间差
polling server every 64 s //下次同步时间(更新频率)
三.客户端配置
客户端:
同步:
ntpdate ip
手动设置
ntpdate 192.168.1.5
ntp一般只能同步系统时钟
vim /etc/sysconfig/ntpd
SYNC_HWCLOCK=yes
hwclock -w
计划任务 每分钟去同步
crontab -e
* * * * * /usr/sbin/ntpdate 192.168.1.5
* * * * * /usr/sbin/hwclock -w