时间服务器ntp和chrony

来源:互联网 发布:matlab2014b mac 编辑:程序博客网 时间:2024/05/19 11:47

时间同步方法:
1)和互联网时间服务器同步
2)自己搭建局域网时间服务器

环境准备:关闭火墙&&服务端设置静态ip
ntp:Network Time Protocol 网络时间协议
服务端:ip 192.168.122.11
1)安装软件包
yum install -y ntp
2)查看配置文件及命令 rpm -ql ntp
/etc/ntp.conf 配置文件
/etc/sysconfig/ntpd 参数文件
/usr/sbin/ntpq 查询
/usr/lib/systemd/system/ntpd.service 服务
ntpdate –客户端同步命令,需要安装ntpdate
示例:搭建局域网ntp服务器
1)备份配置文件
cp /etc/ntp.conf{,.date +"%F-%T"}
2)修改配置文件
#例如:只允许客户端192.168.122.0/24网段客户机进行时间校对
vim /etc/ntp.conf
restrict 192.168.122.0 mask 255.255.255.0 nomodify notrap
server ntp-sz.chl.la iburst (ali)
server ntp.gwadar.cn iburst
#注释系统默认配置的server(上游时间服务器)
vim /etc/ntp/step-tickers
#0.centos.pool.ntp.org
ntp-sz.chl.la
3)重启服务测试
systemctl restart ntpd
客户端测试:
date -s “19980905”
ntpdate 192.168.122.11
#####################################################
如果要使用本地时间,将上面的server注释,添加下面两行
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
ntp: udp 123端口
查询服务端口:
1)获取pid
pgrep ntpd
或pidof ntpd
2)使用netstat
netstat -putnl | grep pidof ntpd
修改系统时间:date -s “date +'%F %T' -d '-1 year'
chrony:
1)安装
yum install -y chrony
2)配置文件及命令
/etc/chrony.conf
/usr/bin/chronyc
/usr/sbin/chronyd
/usr/lib/systemd/system/chronyd.service
/var/log/chrony
服务端:
server ntp.gwadar.cn iburst
allow 192.168.122/24
客户端:
server 192.168.122.11 iburst
allow 192.168.122/24
local stratum 10
服务器和客户端启动服务:systemctl start chronyd
systemctl enable chronyd
命令行测试:
chronyc sources -v

注:
时间未同步成功的原因:两个时间同步服务不能同时使用
防火墙状态
网络是否能够连通

原创粉丝点击