多台linux服务器时间同步
时间服务器作用:
若计算机时间不同步,如E-MAIL信息、文件创建和访问时间、数据库处理时间等这些应用或操作或将无法正常进行。
时间同步是业务能够得到正确处理的基础保障。
互联网时代,整个处理计算系统内的数据通信都是通过网络进行。
时间同步即是利用互联网络传送标准时间信息,实现大数据系统内时间同步。
网络时间同步协议(NTP)是时间同步的技术基础。
(一)确认ntp的安装
1)确认是否已安装ntp
$ rpm –qa | grep ntp
若只有ntpdate而未见ntp,则需删除原有ntpdate。如:
ntpdate-4.2.6p5-22.el7_0.x86_64
fontpackages-filesystem-1.44-8.el7.noarch
python-ntplib-0.3.2-1.el7.noarch
2)删除已安装ntp
$ yum –y remove ntpdate-4.2.6p5-22.el7.x86_64
3)重新安装ntp
$ yum –y install ntp
离线安装ntp:
需要准备的依赖包:
ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm
ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm
libedit-3.0-12.20121213cvs.el7.x86_64.rpm
rpm查找网址:
Search the RPM
rpm -ivh libedit-3.0-12.20121213cvs.el7.x86_64.rpm
rpm -ivh ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm
rpm -ivh ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm
(二)配置ntp服务
1)修改所有节点的/etc/ntp.conf
$ vi /etc/ntp.conf
【内容】
restrict 192.168.6.3 nomodify notrap nopeer noquery #当前节点IP地址
restrict 192.168.6.2 mask 255.255.255.0 nomodify notrap #集群所在网段的网关(Gateway),子网掩码(Genmask)
查看网关:
1、route -n
2、ip route show
3、traceroute www.baidu.com -s 100 【第一行就是自己的网关】
4、netstat -r
5、more /etc/network/interfaces 【Debian/Ubuntu Linux】
6、more /etc/sysconfig/network-scripts/ifcfg-eth0 【Red Hat Linux】
2)选择一个主节点,修改其/etc/ntp.conf
$ vi /etc/ntp.conf
【内容】在server部分添加以下部分,并注释掉server 0 ~ n
server 127.127.1.0
Fudge 127.127.1.0 stratum 10
定时任务:
$ crontab -e
【内容】
30 * * * * /usr/sbin/ntpdate -u cn.ntp.org.cn
0 0 * * * /usr/sbin/ntpdate -u ntp.api.bz
3)主节点以外,继续修改/etc/ntp.conf
$ vi /etc/ntp.conf
【内容】在server部分添加如下语句,将server指向主节点。
server 192.168.6.3
Fudge 192.168.6.3 stratum 10
定时任务:
$ crontab -e
【内容】
30 0 * * * /usr/sbin/ntpdate -u 192.168.6.3
=修改前=
=修改后=
节点1(192.168.6.3):
节点2(192.168.6.4):
节点3(192.168.6.5):
查看ntp启动结果:
watch ntpq -p
查看ntp服务器有无和上层ntp连通:
ntpstat
启动并设置开机启动:
systemctl start ntpd.service && systemctl enable ntpd.service
systemctl enable ntpdate.service
查询ntp是否设置开机自启:
systemctl is-enabled ntpd
enabled 说明已经设置成了开机自启
也可以使用如下命令查看开机启动服务:
systemctl list-unit-files | grep ntp
如果ntp已经设置开机自启,但是开机启动并未成功。一般引起这个问题的最为常见的原因是系统上安装了一个与NTP相冲突的工具:chrony。
解决办法就是将此工具停止开机启动:
systemctl disable chronyd
查看开机启动的服务:
systemctl list-unit-files | grep enable
内容转载于:多台linux服务器时间同步