centos ntp时钟同步
在我们某系统方案设计中,由于数据同步性要求需要将我们系统时钟与客户系统的时钟保持同步,以下采用NTP时钟同步的方式进行系统时间的同步。
1. 安装ntp服务
yum install ntp ntpdate crontabs -y #安装服务
systemctl start ntpd #启动服务
systemctl enable ntpd #开机启动
2.date 发现格式为EDT,我们需要修改为CST格式
vim /etc/sysconfig/clock #修改为上海时区
ZONE = "Asia/Shanghai"
UTC = false
ARC = false
3.设置时区为shagnhai即CST时间
[root@test ~]# mv /etc/localtime /etc/localtime.bak
[root@test ~]# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
[root@test ~]# date
4. 并用ntpdate同步网上的一台ntp服务器同步时间配置ntp时钟同步
ntpdate cn.pool.ntp.org 使用ntpdate同步cn.pool.ntp.org 时间
阿里云
ntp1.aliyun.com
ntp.sjtu.edu.cn 202.120.2.101 (上海交通大学网络中心NTP服务器地址)
s1b.time.edu.cn 清华大学
s1c.time.edu.cn 北京大学
s1d.time.edu.cn 东南大学
s1e.time.edu.cn 清华大学
ntp.ntsc.ac.cn 中国国家授时中心
Windows 系统上自带的俩个:
time.windows.com 和 time.nist.gov
Mac OS X 上自带的俩个:
time.apple.com 和 time.asia.apple.com
5. 将系统时间写入硬件时间
hwclock --systohc 将系统时间写入硬件时间
hwclock -w 强制系统时间写入 CMOS 中防止重启失效
6.配置开机启动校验
vim /etc/rc.d/rc.local
/usr/sbin/ntpdate ntp1.aliyun.com > /dev/null 2>&1; /sbin/hwclock -w
7.配置定时任务同步时间
crontab -e
00 12 * * * /usr/sbin/ntpdate cn.pool.ntp.org
重启验证是否成功。

发表评论