Centos6.5安装配置NTP时间服务器

来源:互联网 发布:js鼠标离开div 编辑:程序博客网 时间:2024/05/18 07:08

**

Centos6.5安装配置NTP时间服务器

**

  • 一、NTP服务端配置

1、查看亚洲大部分时区和国家城市的时间文件位置

ls -F  /usr/share/zoneinfo/Asia

2、查看当前某一时区的时间

[root@localhost ~]# zdump HongkongHongkong  Sat Sep 12 08:33:43 2015 HKT

3、设置系统时间的时区

[root@localhost ~]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime[root@localhost ~]# dateSat Sep 12 08:37:37 CST 2015

4、查看系统时间和硬件时间是否一致(RTC即系统停止还在计算时间一般写在BIOS里头)

#系统时间查询[root@localhost ~]# dateSat Sep 12 08:37:37 CST 2015#硬件时间查询[root@localhost ~]# hwclock -rSat 12 Sep 2015 08:43:26 AM CST  -0.863373 seconds

5、设置系统时间和硬件时间与当前实际时间保持一致

date -s "dd/mm/yyyy hh:mm:ss" #设置系统时间hwclock  -w   #将系统时间写入硬件时间

2、NTP-Server安装
1、查看操作系统是否安装ntp服务组件,执行命令

rpm -qa|grep ntp#显示下面2个包,代表已经安装ntp-server服务组件[root@localhost ~]# rpm -qa|grep ntpntp-4.2.6p5-1.el6.centos.x86_64fontpackages-filesystem-1.41-1.1.el6.noarchntpdate-4.2.6p5-1.el6.centos.x86_64

安装ntp服务组件包,执行命令

yum  install ntp

3、NTP-Server配置
1、编辑配置文件/etc/ntp.conf文件,

 vim /etc/ntp.conf第(1)种配置:允许任何IP的客户机都可以进行时间同步则将“restrict default kod nomodify notrap nopeer noquery”这行修改成:restrict default nomodify第(2)种配置:只允许192.168.200.*网段的客户机进行时间同步在“restrict default kod nomodify notrap nopeer noquery”(表示默认拒绝所有IP的时间同步)之后增加一行:restrict 192.168.200.0 mask 255.255.255.0 nomodify另外,配置文件默认通过网络同步时间:server 0.centos.pool.ntp.org iburstserver 1.centos.pool.ntp.org iburstserver 2.centos.pool.ntp.org iburstserver 3.centos.pool.ntp.org iburst(RedHat默认有类似上面4行内容,域名不一样而已)如果需要使用本地时间,则把上面4行删掉或者用“#”号注释掉,然后添加以下两行:server 127.127.1.0fudge 127.127.1.0 stratum 10(RedHat默认有上面两行,但被注释掉了)restrict 127.0.0.1#这是允许本级查询# 外部时间服务器不可用时,以本地时间作为时间服务server  127.127.1.0     # local clockfudge   127.127.1.0 stratum 10

防火墙设置

vim /etc/sysconfig/iptables-A INPUT -p udp -m udp --sport 123 -j ACCEPT    对外开放123端口

允许BIOS与系统时间同步,简单命令hwclock -w也可修改配置文件

vi /etc/sysconfig/ntpd  添加:SYNC_HWCLOCK=”yes”

启动ntp服务,并添加开机启动

server ntpd startchkconfig ntpd onchkconfig --list ntpdchkconfig --level 35 ntpd on

查看本机与上层NTP服务器通信情况

ntpq –p

查看123端口

lsof -i:123
ntpdate pool.ntp.rog

NTP-Client 客户端 部署-配置 Linux

 ntpdate 192.168.30.3

如果提示报错no server suitable for synchronization found
解决方法添加-u参数可以越过防火墙与主机同步
比如 ntpdate -u 192.168.30.3

客户端设置定时同步时间

[root@dlp ~]# vi /root/ntpupdate.sh       编辑定时脚本/usr/sbin/ntpdate 192.168.30.3[root@dlp ~]# cat /root/ntpupdate.sh   编辑完之后查看/usr/sbin/ntpdate 192.168.30.3[root@dlp ~]# crontab -e                       编辑定时任务,每分钟执行一次*/1 * * * * /root/ntpupdate.sh[root@dlp ~]# crontab -l*/1 * * * * /root/ntpupdate.sh                编辑后查看

附1:
1.查看当前时区

# dateThu Oct 31 09:37:09 EDT 2013

2.修改 /etc/sysconfig/clock
将原来的时区改为

vi /etc/sysconfig/clockZONE="America/New_York"#改为ZONE="Asia/Shanghai"覆盖 /etc/localtime cp -a /usr/share/zoneinfo/Asia/Shanghai /etc/localtime cp: overwrite `/etc/localtime"? y

4.查看修改后的时区

1.# date2.Thu Oct 31 21:42:33 CST 2013
原创粉丝点击