搭建NTP服务器 发表于 2025-01-03 | 分类于 搭建 | | 热度: ℃ 字数统计: 334 | 阅读时长 ≈ 2 时间相关准备12345678910#设置时区(东八区)cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime -R#设置时间date -s "20190601 16:51:50"#查看格式化时间date "+%Y-%m-%d %H:%M:%S"#查看硬件时间hwclock -r#将当前时间回写到硬件上hwclock -w 安装NTP离线安装包以及其依赖包下载NTP离线安装包 服务器端-192.168.0.13212345678#安装相关离线包和NTP服务器rpm -ivh autogen-libopts-5.18-5.el7.x86_64.rpmrpm -ivh ntp-4.2.6p5-18.el7.centos.x86_64.rpmrpm -ivh ntpdate-4.2.6p5-18.el7.centos.x86_64.rpm#启动ntp服务并设置开机启动,若有防火墙需要将防火墙关闭,或者允许123端口systemctl start ntpdsystemctl enable ntpd 客户端配置1234567891011121314151617181920#安装相关离线包rpm -ivh ntpdate-4.2.6p5-18.el7.centos.x86_64.rpm#同步服务器时间ntpdate -u 192.168.0.132#设置自动同步服务器时间crontab -e#追加定时任务同步时间(0 0 0 * * ? * 每天凌晨同步一次)#每30分钟同步一次*/30 * * * * /usr/sbin/ntpdate 192.168.0.132#查看crond的状态service crond statuscrond -l#crond的启动重启停止service crond startservice crond stopservice crond reloadservice crond restart