搭建ntp时间服务器

为保证所有linux服务器(安装了centos6.5的操作系统)上的时间一致,做了一个ntp服务器,做个笔记。

假设有3台服务器,ip地址为192.168.1.2;192.168.1.3;192.168.1.4,现在把1.2的做为服务器。

1、设置好服务器的时间和时区:

时区设置:cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

时间设置:date -s '2014-10-28 00:00:00'

                    hwclock -w

2、查看是否安装了ntp

rpm -qa ntp,如果没有任何提示,就表示没有安装,必须先安装ntp

安装:rpm -ivh ntp.rpm

3、修改ntp.conf 文件

vi /etc/ntp.conf

a)注释掉“restrict default ignore”这一行

b)加入restrict 192.168.1.0 mask 255.255.255.0

c)去掉注释“server 127.127.1.0 #local clock”与“fudge 127.127.1.0 stratum 10”

退出并保存:Esc+:+wq+回车

4、重启ntp服务器

/etc/init.d/ntpd stop

/etc/init.d/ntpd start

5、设置开机启动

chkconfig ntpd on

6、客户端设置

设置时区:cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

重复服务器端的第2步骤

修改ntp.conf文件

a)加入server 192.168.1.2

b)注释“server 127.127.1.0 #local clock”与“fudge 127.127.1.0 stratum 10”

退出并保存:Esc+:+wq+回车

7、与服务器时间同步

ntpdate 192.168.1.2(如果在此步骤中出现“the ntp socket is in use,exiting”,这是因为服务器自身同步需要5-10分钟的时间,请等待一会就好了)

hwclock -w

8、定期执行

crontab -e

* 0 * * * /usr/sbin/ntpdate 192.168.1.2;/sbin/hwclock -w;


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是在CentOS 7上搭建NTP时间服务器的步骤: 1.安装NTP软件包 ```shell yum install ntp -y ``` 2.配置NTP服务器 编辑`/etc/ntp.conf`文件,添加如下内容: ```shell # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). 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 # Allow LAN traffic. restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap ``` 其中,`server`行指定了NTP服务器使用的公共时间服务器,`restrict`行指定了允许访问NTP服务器的IP地址范围。 3.启动NTP服务 ```shell systemctl start ntpd ``` 4.设置NTP服务开机自启动 ```shell systemctl enable ntpd ``` 5.检查NTP服务状态 ```shell systemctl status ntpd ``` 如果NTP服务正在运行,则输出类似以下内容: ```shell ● ntpd.service - Network Time Service Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2021-08-10 14:20:20 CST; 1h 5min ago Main PID: 1234 (ntpd) CGroup: /system.slice/ntpd.service └─1234 /usr/sbin/ntpd -u ntp:ntp -g ``` 6.检查NTP服务器是否正常工作 ```shell ntpq -p ``` 如果NTP服务器正常工作,则输出类似以下内容: ```shell remote refid st t when poll reach delay offset jitter ============================================================================== *0.centos.pool. .POOL. 16 p - 64 0 0.000 0.000 0.000 +1.centos.pool. .POOL. 16 p - 64 0 0.000 0.000 0.000 +2.centos.pool. .POOL. 16 p - 64 0 0.000 0.000 0.000 +3.centos.pool. .POOL. 16 p - 64 0 0.000 0.000 0.000 ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值