Linux 服务器上快速配置OPSX NTP服务(时间服务器)

    选择打赏方式

我们在使用Linux服务器的时候,服务器时间总是与现实对不上,导致某些服务用不了怎么办呢?

今天小傲世就教大家如何在Linux服务器中设置时间同步服务器(NTP),并且设置10分钟自动同步。

接下来我给大家介绍三种方法

一.可以从时间服务器ntp.aliyun.com同步,这个是阿里云免费提供的时间同步服务器。

ntpdate ntp1.aliyun.com

然后删除本地时间地区并设置为中国上海

rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

二.自己建个时间服务器并设置自动同步

1.从挂载中安装ntp服务并编辑文件

rpm -ivh ntp-4.2.2p1-7.el5.i386.rpm
vi /etc/ntp.conf

2.在该配置文件中注释这一行

restrict default ignore

2.在配置文件中加入这一行,保存并退出

restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

3.打开ntp服务的另一个配置文件

vi /etc/ntp/step-tickers

4.在配置文件中入这一行,保存并退出

pool.ntp.org

这样每次ntpd启动时,会自动连接该国际标准时间服务器;

5.启动ntp服务,确保该123端口以udp方式开放

service ntpd start
netstat -an |grep 123

6.时间客户配置(192.168.10.2)

ntpdate -s 192.168.10.2

应该显示同成功

crond -e

7.入自动计划,这串代码表示每隔10分钟同步一次时间

0-59/10 * * * * /usr/sbin/ntpdate 192.168.10.1

三.快速配置阿里云OPSX NTP服务

编辑文件 "/etc/ntp.conf",根据情况修改文件内容为下列内容:

1)互联网上的服务器:

driftfile  /var/lib/ntp/drift
pidfile   /var/run/ntpd.pid
logfile /var/log/ntp.log
restrict    default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
server 127.127.1.0
fudge  127.127.1.0 stratum 10
server ntp.aliyun.com iburst minpoll 4 maxpoll 10
restrict ntp.aliyun.com nomodify notrap nopeer noquery

2)阿里云 ECS 服务器:

driftfile  /var/lib/ntp/drift
pidfile   /var/run/ntpd.pid
logfile /var/log/ntp.log
restrict    default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
server 127.127.1.0
fudge  127.127.1.0 stratum 10
server ntp.aliyun.com iburst minpoll 4 maxpoll 10
restrict ntp.aliyun.com nomodify notrap nopeer noquery

server ntp1.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
restrict ntp1.cloud.aliyuncs.com nomodify notrap nopeer noquery
server ntp2.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
restrict ntp2.cloud.aliyuncs.com nomodify notrap nopeer noquery
server ntp3.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
restrict ntp3.cloud.aliyuncs.com nomodify notrap nopeer noquery
server ntp4.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
restrict ntp4.cloud.aliyuncs.com nomodify notrap nopeer noquery
server ntp5.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
restrict ntp5.cloud.aliyuncs.com nomodify notrap nopeer noquery
server ntp6.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
restrict ntp6.cloud.aliyuncs.com nomodify notrap nopeer noquery

对于使用 chrony 客户端的 linux 主机

配置 '/etc/chrony.conf' 文件的内容为:

server ntp.aliyun.com iburst
stratumweight 0
driftfile /var/lib/chrony/drift
rtcsync
makestep 10 3
bindcmdaddress 127.0.0.1
bindcmdaddress ::1
keyfile /etc/chrony.keys
commandkey 1
generatecommandkey
logchange 0.5
logdir /var/log/chrony
版权声明:若无特殊注明,本文为《傲世》原创,转载请保留文章出处。
本文链接:https://www.recho.cn/6.html
正文到此结束

热门推荐

发表吐槽

你肿么看?

你还可以输入 250 / 250 个字

呵呵 哈哈 吐舌 开心 笑眼 可怜 乖 啊 你懂得 不高兴 生气 汗 黑线 哭 真棒 阴险 鄙视 酷 滑稽 纳尼 疑问 委屈 惊讶 勉强

评论信息框
可使用QQ号实时获取头像自动填写

私密评论

吃奶的力气提交吐槽中...


竟然没有人吐槽,快赶紧抢沙发吧!