2015.8.30

ntp服务器

NTP服务器(Network Time Protocol),是用来做局域网服务器时间同步的,保证局域网内的服务器与时间服务器的一致,某些应用对实时性要求比较的应用必须统一时间

互联网上也存在很多时间服务器, pool.ntp.org(官方NTP时间服务器)

ntp服务器需要开启123端口 (UDP), 查看Linux系统中的被打开的端口 :netstat -an

打开本地防火墙的123端口:

vi /etc/sysconfig/iptables中 添加一条规则 :-A INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT

安装ntp服务:

yum install ntp ntpdate -y   #  -y不用确认就能执行

修改ntp.conf配置文件

在修改前对配置文件进行备份:cp /etc/ntp.conf /etc/ntp.conf.bak

然后修改:vi /etc/ntp.conf

启动ntp服务:/etc/init.d/ntpd restart

查看ntp连接信息: ntpq -p

查看系统时间 : date

客户端与ntp服务器进行时间同步:ntpdate (ntp服务器IP)

停止ntp服务 :/etc/init.d/ntpd stop

crontab 计划任务

crontab -e 进入任务添加

#每天的6点30分与时间服务器(192.168.1.3)进行时间同步并生成日志

30 06 * * *  /usr/sbin/ntpdate 192.168.1.3 >>/usr/local/ntpdate.log

局域网ntp服务器配置文件:

driftfile /var/lib/ntp/drift

restrict default kod nomodify notrap nopeer noquery

restrict -6 default kod nomodify notrap nopeer noquery

restrict 127.0.0.1  #开启内部网络递归接口IO

restrict -6::1

server 127.127.1.0 #local clock

fudge 127.127.1.0 stratum 10

keys /etc/ntp/keys

ntp服务器搭建完毕.