linux命令修改系统时间方法 linux设置系统时间函数( 二 )

4.1.3 设置开机自启动服务(初始化)使服务端服务ntp的守护进程ntpd生效
[[email protected] ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
使客户端工具ntpdate工具生效(选做)
[[email protected] ~]# systemctl enable ntpdate
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpdate.service to /usr/lib/systemd/system/ntpdate.service.
检查
[[email protected] ~]# systemctl is-enabled ntpd
显示: enabled
4.1.4 启用ntp服务[[email protected] ~]# systemctl start ntpd
查看ntpd进程
[[email protected] ~]# ps -ef | grep ntpd
ntp 1185 1 0 03:50 ? 00:00:00 /usr/sbin/ntpd -u ntp:ntp -groot 1663 1136 0 04:35 pts/2 00:00:00 grep –color=auto ntp
进程存在,说明服务已经正常启动
4.1.5 设置防火墙,放行ntp协议请求提前将防火墙关闭即可
4.1.6 设置硬件时间4.1.6.1 对时间的解释linux的时间分为系统时间和硬件时间 。?系统时间:通常在开机时复制硬件时间,之后独立运行并保存了时间、时区和夏令时设置 。通过date命令设置 。?硬件时间:(RTC、Real-Time Clock),CMOS时间,在主板上靠电池供电,仅保存时期时间数值 。通过hwclock命令设置,在这里,我们用系统时间同步硬件时间:hwclock -w?同步前需要测试ntp上层服务器的连通性4.1.6.2 查看ntp的情况[[email protected] ~]# ntpq -p
remoterefidst t when poll reachdelayoffsetjitter?==============================================================================+electrode.felix 89.231.96.832 u56641286.2359.1330.971*undefined.hostn 127.67.113.922 u56641202.865-7.22413.201-de-user.deepini 195.13.23.53 u58641273.95316.6892.172+ntp5.flashdance 192.36.143.1532 u55641321.71110.6394.733LOCAL(0).LOCL.10 l646420.0000.0000.000解释:
remote:即NTP主机的IP或主机名称.注意最左边是+表示目前正在起作用的上层NTP,如果是*表示这个也连接上了,不过是作为次要联机的NTP主机refid:参考的上一层NTP主机的地址st:即stratum阶层t:是连接类型.u代表单播(unicast)l代表本地(local) ,其他的还有多播(multicast),广播(broadcast)when:这个时间之前刚刚做过时间同步poll:下次更新在几秒之后reach:已经向上层NTP服务器要求更新的次数delay:网络传输过程中的延迟时间offset:时间补偿的结果jitter:Linux系统时间和Bios硬件时间的差异时间4.1.6.3 执行同步[[email protected] ~]# hwclock -w
4.1.6.4 测试[[email protected] conf]# ntpstatsynchronised to NTP server (78.46.102.180) at stratum 3 财路哥 correct to within 189 ms polling server every 64 s
说明本地已经与时间服务器实现了同步
4.2 客户端4.2.1 安装ntp服务和ntpdate工具[[email protected] ~]# yum -y install ntp ntpdate
4.2.2 方法一1 配置用于同步的服务器
先执行hwclock -w 让系统时间和bios时间同步.
[[email protected] ~]# hwclock -w
再执行下面的命令
[[email protected] ~]# echo “server 192.168.10.200” >/etc/ntp.conf
2 重启服务以使配置生效,之后大概要等10分钟左右,才会同步成功
[[email protected] ~]# systemctl enable ntpd
[[email protected] ~]# systemctl restart ntpd
3 这样做的好处:
a 客户端的ntpd服务始终运行着,定期同步时间,不用我们每次都手动同步或者写定时器b ntpd服务是慢慢改变时间直至标准时间4 注意点:
最好先执行hwclock -w,否则如果bios时间和系统时间差异超过了30分钟,就会报错
FAQ:系统报错-Sep 25 12:23:33 localhost kerne: set_rtc_mmss: can’t update from 3 to 22


以上关于本文的内容,仅作参考!温馨提示:如遇健康、疾病相关的问题,请您及时就医或请专业人士给予相关指导!

「四川龙网」www.sichuanlong.com小编还为您精选了以下内容,希望对您有所帮助: