提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
redhat enterprise 6.9 服务器需要和时钟系统进行通过时钟时,可以采取的方法。
第一种:采用ntpdate命令获取时钟系统时钟,同时采用crontab来设置定时时钟同步。
第二种:通过ntp服务来设定和主节点同步时钟。
一、采用ntpdate命令
1.1 安装ntpdate
yum install ntpdate
1.2 测试同步命令是否可用
ntpdate ntp.aliyun.com # 同步时钟的网站或者IP地址
1.3 定时任务添加
crontab -e #编辑crontab
#输入定时执行命令:每小时执行一次
0 * * * * /usr/sbin/ntpdate -s ntp.aliyun.com > /dev/null #同步时钟的网站或者IP地址
#输入 :wq! 写入后退出编辑状态
crontab -l #可以查看任务列表
二、采用NTP服务
2.1. 服务器端设置
vi /etc/ntp.conf #编辑配置ntp
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict 172.16.242.0 mask 255.255.254.0 nomodify #设定局域网内部网段所有客户端可以连接到本地进行时间同步,但是拒绝他们修改服务器上的时间
restrict -6 ::1
server 172.16.243.203 # 配置上层时间同步服务器
server 127.0.0.1
fudge 127.0.0.1 stratum 10 # 设置stratum级别为10
includefile /etc/ntp/crypto/pw # 这条命令可选
keys /etc/ntp/keys # 这条命令可选
SYNC_HWCLOCK=yes #同步硬件时钟,新增
# 输入:wq!进行保存退出
/etc/init.d/ntpd start # 启动NTP服务
chkconfig ntpd on #设置开机自启动
2.2. 客户端设置
vi /etc/ntp.conf #编辑配置NTP
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
server 172.16.243.201 #本系统的时钟服务器
includefile /etc/ntp/crypto/pw # 这条命令可选
keys /etc/ntp/keys # 这条命令可选
SYNC_HWCLOCK=yes #同步硬件时钟,新增
# 输入:wq!进行保存退出
/etc/init.d/ntpd start # 启动NTP服务
chkconfig ntpd on #设置开机自启动
总结
如果仅支持本台服务器与外部时钟同步更新,采用第一种方法比较简单。如果本台服务器还要给客户端提供同步更新,需要采用第二种方法。