centos6 搭建ntp

在工作中,总能碰到服务器时间与本地时间不匹配的情况,先前总是手动进行设置,后来知道ntp服务后

才知道原来ntp才是同步时间方面的利器(linux)

1.  先总结下手动修改时间的方法:

  查询当前时间:

date -R
//Thu, 03 May 2018 16:50:06 +0800
查看bios时间
hwclock -r

 如果时区设置的有问题:

查看时区:
cat /etc/sysconfig/clock 
修改时区:
tzselect
选择时区后,如果需要将结果永久写入系统,需要在/etc/profile中写入:
TZ='America/Anguilla'; export TZ
其中'America/Anguilla'是选中的时区

 设置当前时间

写入系统时间:
date -s '03/05/2018 16:43:00'
写入bios
hwclock  -w

2. 使用ntp服务同步时间:

   设置定时任务:

   4 2 * * * /usr/sbin/ntpdate -u 192.168.1.1 > /dev/null 2>&1 && hwclock --systohc > /dev/null 2>&1

service crond restart

  防火墙配置:

iptables INPUT -p udp -m udp –dport 123 -j ACCEPT 
或者:
service iptables stop

具体安装ntp服务的方法参照: https://blog.csdn.net/Xw_Classmate/article/details/50611489









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是在 CentOS 7 上搭建 NTP 服务器的步骤: 1. 安装 NTP:运行以下命令安装 NTP: ``` sudo yum install ntp ``` 2. 配置 NTP:编辑 `/etc/ntp.conf` 文件,配置服务器地址和允许访问的客户端地址。例如,以下是一个示例配置: ``` server 0.centos.pool.ntp.org iburst server 1.centos.pool.ntp.org iburst server 2.centos.pool.ntp.org iburst restrict default nomodify notrap nopeer noquery restrict 127.0.0.1 restrict <客户端IP地址> mask <子网掩码> nomodify notrap ``` 其中,`server` 指定 NTP 服务器地址,`restrict` 用于限制访问控制。 3. 启动 NTP:运行以下命令启动 NTP 服务并设置为开机自启: ``` sudo systemctl start ntpd sudo systemctl enable ntpd ``` 4. 验证 NTP:使用 `ntpq` 命令验证 NTP 是否正常工作。例如,运行以下命令: ``` ntpq -p ``` 如果 NTP 正常工作,将显示类似以下内容的输出: ``` remote refid st t when poll reach delay offset jitter ============================================================================== *ntp1.example.c .GPS. 1 u 154 256 377 0.862 -30.200 1.835 +ntp2.example.c .PPS. 1 u 173 256 377 0.991 -30.230 1.309 -ntp3.example.c .GPS. 1 u 130 256 377 1.003 -29.990 1.935 ``` 其中,`*` 表示当前服务器为 NTP 主服务器,`+` 表示当前服务器为 NTP 辅助服务器,`-` 表示当前服务器为 NTP 被动服务器。 以上就是在 CentOS 7 上搭建 NTP 服务器的步骤。希望能对你有所帮助。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值