linux 同步北京时间_Linux自动同步网络时间,并创建本地Ntp服务器【NTP时间同步服务器】...

NTP (Network Time Protocol)

作用:将网络中的各个主机的时间进行同步,局域网中的误差<0.1ms

架构:C/S

实验环境:两台有网络的Centos,其中134为服务端,135为客户端。134同步网络时间,其他服务器同步134时间。

1、查看134的系统信息、时间和时区

cat /etc/redhat-release

date

timedatectl | grep "Time zone"

此时可以看到134时区为上海、时间和网络时间不同步

2、查看135的系统信息、时间和时区

cat /etc/redhat-release

date

timedatectl | grep "Time zone"

此时可以看到135时区为上海、时间和网络时间不同步

3、在服务端134编写计划任务设置服务器自动同步阿里云时间服务器,并把本地时间同步到硬件时间。

/usr/sbin/ntpdate -u ntp1.aliyun.com &>/dev/null

/usr/sbin/hwclock -w &>/dev/null

4、此时查看服务器134的时间,已经和网络时间同步

5、在服务端134安装ntp服务,需要有yum源。(配置yum源 http://blog.51cto.com/14015577/2414577)

yum install ntp -y

6、配置服务器端134

NTP配置文件介绍

/etc/ntp.conf

内容:

(1)、restrict:指定授权哪些主机可以使用ntp进行时间同步

格式:restrict IP地址 mask 子网掩码 参数

参数:ignore:关闭ntp服务器

nomodify:指定客户端可以进行时间同步,但是不能修改服务器端时间

例子:

restrict 192.168.6.123

restrict 192.168.6.0 mask 255.255.255.0

restrict 0.0.0.0 mask 0 0 0 0 nomodify

( 2)、server:指定从哪个外部时间服务器来获取时间

例子:

server 0.centos.pool.ntp.org iburst

server 1.centos.pool.ntp.org iburst

server 2.centos.pool.ntp.org iburst

server 3.centos.pool.ntp.org iburst

此时134配置如下:

server 127.127.1.0

restrict 127.0.0.1

restrict 192.168.0.0 mask 255.255.255.0

启动ntp服务并查看状态

systemctl restart ntpd

systemctl status ntpd

ntpstat

7、客户端135安装ntpdate服务

yum install ntpdate -y

8、客户端134编写计划任务自动同步135服务器上的时间,并把时间同步到硬件时间

crontab -l

/usr/sbin/ntpdate -u 192.168.70.134 &>/dev/null

/usr/sbin/hwclock -w &>/dev/null

此时,可以看到135时间和网络时间同步。内网中的服务器只需同步134即可。减少资源占用。

免责声明:文章《Linux自动同步网络时间,并创建本地Ntp服务器【NTP时间同步服务器】》来至网络,文章表达观点不代表本站观点,文章版权属于原作者所有,若有侵权,请联系本站站长处理!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值