linux ntp服务端命令,Linux NTP服务器端和NTP客户端的搭建

NTP服务器端安装和配置

系统:CentOS 5.6 x64位

ntp服务器端的IP地址:192.168.33.5

ntp服务器名;rac1

步骤1:NTP安装

[root@rac1 etc]#yum install ntp

如果已经有装过版本了,可以先卸载

[root@rac1 etc]#yum remove ntp

步骤2:配置ntp服务器

1)修改/etc/ntp.conf文件

[root@rac1 etc]# vi /etc/ntp.conf

# Permit time synchronization with our time source, but do not

# permit the source to query or modify the service on this system.

#缺省的访问权限不允许修改也不允许查询

# 用restrict控管权限 nomodify - 用户端不能更改ntp服务器的时间参数 noquery - 用户端不能使用ntpq,ntpc等命令来查询ntp服务器 notrap - 不提供trap远端登陆

restrict default kod nomodify notrap nopeer noquery

restrict -6 default kod nomodify notrap nopeer noquery

# Permit all access over the loopback interface.  This could

# be tightened as well, but to do so would effect some of

# the administrative functions.

#开放本机内部环路接口

restrict 127.0.0.1

restrict -6 ::1

# Hosts on local network are less restricted.

#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

#开放本实验局域网访问权限

restrict 192.168.33.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.

# Please consider joining the pool (http://www.pool.ntp.org/join.html).

#设置上层NTP服务器,通过这个http://www.pool.ntp.org/zone/cn地址可以到使用频率最高的服务器

server 0.cn.pool.ntp.org

server 1.asia.pool.ntp.org

server 3.asia.pool.ntp.org

#设置本地时钟源及层数位置

server 127.127.1.0

fudge 127.127.1.0 stratum 10

#用于补偿系统时钟自然漂移的一个文件

driftfile /var/lib/ntp/drift

keys /etc/ntp/keys

2)修改NTP配置文件/etc/sysconfig/ntpd

[root@rac1 etc]## vi  /etc/sysconfig/ntpd

# Drop root to id 'ntp:ntp' by default.

OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid"

# Set to 'yes' to sync hw clock after successful ntpdate

#通过外部时钟源校正时间后,自动更新BIOS时间

SYNC_HWCLOCK=yes

# Additional options for ntpdate

NTPDATE_OPTIONS=""

3)修改NTP配置文件/etc/ntp/step-tickers

[root@rac1 ntp]# vi /etc/ntp/step-tickers

0.cn.pool.ntp.org

保存退出

步骤3:NTP防火墙设置允许123端口访问

[root@rac1 etc]#iptables -A INPUT -p udp --dport 123 --sport 123 -j ACCEPT

[root@rac1 etc]#iptables -A OUTPUT -p udp --sport 123 --dport 123 -j ACCEPT

Ntp客户端的同步:

手动执行同步命令:

[root@nfsnode1 ~]# ntpdate 192.168.33.5

22 Oct 16:52:05 ntpdate[7503]: step time server 197.133.133.10 offset -20.497776 sec

[root@nfsnode1 ~]# date

再写入bios:

[root@nfsnode1 ~]# hwclock –w

要定时自动同步,可以把命令及执行时间和周期等加入crontab

[root@rac2 ~]# crontab -e

* * * * *  /usr/sbin/ntpdate 192.168.33.5 && hwclokc -w

保存退出:x

crontab: installing new crontab0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值