配置时间服务器
环境配置:
centos 7.3
10.0.0.4 server
10.0.0.5 client
一:修改时间,并设置成24小时的格式
a, 用date命令查看当前系统时间
(EDT:指美国东部夏令时间,波士顿、纽约市、华盛顿哥伦比亚特区,
这个时区跟北京时区(CST)有12小时的时差,晚12小时。)
b, 通过tzselect 设置北京时间
c,然后执行一下两条命令:
rm /etc/localtime
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
d:同步网络事间
1,安装ntpdate工具
yum -y install ntp ntpdate
2,设置系统时间与网络时间同步
ntpdate cn.pool.ntp.org
3,将系统时间写入硬件时间
hwclock --systohc
二 : 搭建ntp服务器
a, yum -y install ntp
b, 配置npt服务 /etc/ntp.conf
第15行添加:
restrict 10.0.0.0 mask 255.255.255.0
在第26行,设置服务器为自己:
server 127.127.1.0
fudge 127.127.1.0 stratum 11
c, 启动ntp服务并设置开机启动
A:systemctl restart ntpd
上边重启服务
B : systemctl enable ntpd
三: 同步时间的客户端
1, 安装chrony
yum -y install chrony
2, 配置/etc/chrony.conf
server 10.0.0.4
3, 启 动/开机启动chronyd
systemctl restart chronyd
4, 查看同步状态,显示NTPsynchrond:yes表示同步成功,时间同步可能需要一到两分钟。
timedatectl status
防火墙设置,打开udp123端口
firewall-cmd --permanent --add-port=123/udp
firewall-cmd --reload
查看防火墙已打开的端口:
iptables -L -n
查看状态: ntpq -p
四:另提供阿里的时间服务器
阿里云提供了7个NTP时间服务器也就是Internet时间同步服务器地址
ntp1.aliyun.com
ntp2.aliyun.com
ntp3.aliyun.com
ntp4.aliyun.com
ntp5.aliyun.com
ntp6.aliyun.com
ntp7.aliyun.com
五:集群的时间同步(连接外网)
yum -y install ntpdate
timedatectl set-timezone Asia/Shanghai
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
timedatectl set-local-rtc 0
crontab -e
$# 00 * * * * /usr/sbin/ntpdate ntp1.aliyun.com
$# 整时同步更新时间
由于centos 系统自带有chrond 服务,可以这样
echo "server ntp1.aliyun.com iburst iburst " >> /etc/chrony.conf
systemctl restart chronyd
chronyc -a makestep
chronyc sources -v
crontab -e
00 * * * * /usr/bin/chronyc -a makestep