服务器对时间要求非常严格,linux服务器文件的生成,日志,以及数据库的连接都是根据时间的逻辑

进行任务处理,如果时间不同步,那么,处理的任务,以及出问题的分析日志,时间不对,很难分析

直接更改linux服务器时间,影响特别大,大家都知道,服务器群启动是有规律的,如果随便更改linux服务器时间

很有可能造成时间逻辑大站,造成其它模块报警,以及数据库报警等,所以建服务器之前,先配置ntp服务器,

部分服务器为了安全不能上网,所以不能同步网络时间,所以我们让它同步我局域网的ntp服务器,以下是设置相关命令

[root@centos01 ~]# cat /etc/sysconfig/clock       #查看服务器现在在哪个时区
# The time zone of the system is defined by the contents of /etc/localtime.
# This file is only for evaluation by system-config-date, do not rely on its
# contents elsewhere.
ZONE="Asia/Shanghai"

[root@centos01 ~]# ls /usr/share/zoneinfo/America/      #查看有哪些时区

[root@centos01 ~]# yum list ntp\*             #查看是否有ntp rpm包

[root@centos01 ~]# more /etc/ntp.conf                    # 查看ntp服务器配置文件,也可以修改网上ntp服务器教育网,很多

[root@centos01 ~]# chkconfig ntpd on        #启动ntp 服务

[root@centos01 ~]# netstat -ntulp |grep 123    #查看ntp服务端口号upd 123 是否启动
udp 0 0 192.168.1.7:123 0.0.0.0:* 1659/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 1659/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 1659/ntpd
udp 0 0 ::1:123 :::* 1659/ntpd
udp 0 0 fe80::20c:29ff:fe79:38bb:123 :::* 1659/ntpd
udp 0 0 :::123 :::* 1659/ntpd

[root@centos01 ~]# iptables -I INPUT 1 -p udp --dport 123 -j ACCEPT     #防火强打开upd123 端口,让其它服务器来同步时间
[root@centos01 ~]# service iptables save                    #保存防火墙配置
iptables:将防火墙规则保存到 /etc/sysconfig/iptables:[确定]

[root@centos01 ~]# ntpq -p                    #打印现在的ntp 连接信息                  
remote refid st t when poll reach delay offset jitter
==============================================================================
*dns1.synet.edu. 202.118.1.46 2 u 106 128 257 60.571 2.864 4.041
+gus.buptnet.edu 202.112.10.60 3 u 319 128 174 64.985 10.104 36.470
+dns2.synet.edu. 202.118.1.46 2 u 130 128 267 51.183 8.805 54.378

客户端设置同步ntp服务器命令如下

-bash-4.1# ntpdate 192.168.1.7               #同步自己建的192.168.1.7 这台ntp服务器,结果报错
26 Apr 13:28:21 ntpdate[27058]: the NTP socket is in use, exiting
-bash-4.1# service ntpd stop                   #关闭客户端ntpd服务器,让他不要以ntp服务器身份同步,让它以ntp客户端身份同步你192.168.1.7 ntp服务器
Shutting down ntpd: [ OK ]
-bash-4.1# ntpdate 192.168.1.7              #同步时间,ntp服务器为192.168.1.7 现在同步,返回值表示同步成功
26 Apr 13:29:02 ntpdate[27076]: adjust time server 192.168.1.7 offset 0.005925 sec

-bash-4.1# vi /etc/crontab                    #加入循环执行任务里面,每天2点15分自动同步时间

15 2 * * * root /usr/sbin/ntpdate 192.168.0.20 &&/sbin/hwclock -w

备注:国内最常见的NTP服务器:

国内常用NTP服务器地址及IP

 
210.72.145.44 (国家授时中心服务器IP地址)
133.100.11.8 日本 福冈大学
time-a.nist.gov 129.6.15.28 NIST, Gaithersburg, Maryland
time-b.nist.gov 129.6.15.29 NIST, Gaithersburg, Maryland
time-a.timefreq.bldrdoc.gov 132.163.4.101 NIST, Boulder, Colorado
time-b.timefreq.bldrdoc.gov 132.163.4.102 NIST, Boulder, Colorado
time-c.timefreq.bldrdoc.gov 132.163.4.103 NIST, Boulder, Colorado
utcnist.colorado.edu 128.138.140.44 University of Colorado, Boulder
time.nist.gov 192.43.244.18 NCAR, Boulder, Colorado
time-nw.nist.gov 131.107.1.10 Microsoft, Redmond, Washington
nist1.symmetricom.com 69.25.96.13 Symmetricom, San Jose, California
nist1-dc.glassey.com 216.200.93.8 Abovenet, Virginia
nist1-ny.glassey.com 208.184.49.9 Abovenet, New York City
nist1-sj.glassey.com 207.126.98.204 Abovenet, San Jose, California
nist1.aol-ca.truetime.com 207.200.81.113 TrueTime, AOL facility, Sunnyvale, California
nist1.aol-va.truetime.com 64.236.96.53 TrueTime, AOL facility, Virginia
————————————————————————————————————
ntp.sjtu.edu.cn 202.120.2.101 (上海交通大学网络中心NTP服务器地址)
s1a.time.edu.cn 北京邮电大学
s1b.time.edu.cn 清华大学
s1c.time.edu.cn 北京大学
s1d.time.edu.cn 东南大学
s1e.time.edu.cn 清华大学
s2a.time.edu.cn 清华大学
s2b.time.edu.cn 清华大学
s2c.time.edu.cn 北京邮电大学
s2d.time.edu.cn 西南地区网络中心
s2e.time.edu.cn 西北地区网络中心
s2f.time.edu.cn 东北地区网络中心
s2g.time.edu.cn 华东南地区网络中心
s2h.time.edu.cn 四川大学网络管理中心
s2j.time.edu.cn 大连理工大学网络中心
s2k.time.edu.cn CERNET桂林主节点
s2m.time.edu.cn 北京大学
—————————————————————

[root@desk ~]# vim /etc/ntp.conf

# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

driftfile /var/lib/ntp/drift

# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
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.1.0 mask 255.255.255.0 nomodify notrap   #设置哪些网段可以使用这台ntp服务器

# 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
server 202.120.2.101
server s2f.time.edu.cn
server s2g.time.edu.cn
server s2k.time.edu.cn
server s2m.time.edu.cn

#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 autokey # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 autokey # manycast client

ntp服务器搭建与客户端设置的更多相关文章

  1. NTP服务器搭建

    NTP服务器搭建 :http://www.jbxue.com/LINUXjishu/22352.html 客户端配置: vim /etc/ntp.conf #server 0.centos.pool. ...

  2. CAS5.3服务器搭建与客户端整合SpringBoot以及踩坑笔记

    CAS5.3服务器搭建与客户端整合SpringBoot以及踩坑笔记 cas服务器的搭建 导出证书(1和2步骤是找了课程,随便写了一下存记录,不过对于自己测试不投入使用应该不影响) C:\Users\D ...

  3. SVN服务器搭建及客户端配置

    为什么要使用SVN? 在程序的编写过程中,每个程序员都会负责开发一个或多个模块,且开发中会生成很多不同的版本, 这就需要程序员有效的管理代码,在需要的时候可以迅速,准确取出相应的版本. Subvers ...

  4. linux下ntp服务器搭建方法

    环境 软件:fedora14,装在virtualbox虚拟机上 硬件:x86 具体步骤 检查是否安装了ntp 运行如下命令: rpm -qa | grep ntp 如果有如下输出,表示有安装ntp 服 ...

  5. [源码管理] ubuntu中svn简明用法:服务器搭建+客户端使用

    本文是对网络上前人的优秀文章加以实践验证后所整理(修正或补充) 第一部分:svn服务器搭建(主要是四步走) 参考:http://www.son1c.cn/show/920.html 一,安装Subve ...

  6. Linux Centos6.5 SVN服务器搭建 以及客户端安装

    转载:http://www.cnblogs.com/mymelon/p/5483215.html /******开始*********/ 系统环境:Centos 6.5 第一步:通过yum命令安装sv ...

  7. NTP 服务器搭建

    FROM:http://blog.sina.com.cn/s/blog_511b46d10100agzf.html 配置环境: 1. 假设在 192.168.0.0 网段内,要以IP为 10.233. ...

  8. SIP协议&开源SIP服务器搭建和客户端安装

    1. SIP SIP 是一个应用层的控制协议,可以用来建立,修改,和终止多媒体会话,例如Internet电话 SIP在建立和维持终止多媒体会话协议上,支持五个方面: 1)   用户定位: 检查终端用户 ...

  9. Window下SVN服务器搭建以及客户端使用

    一.下载 上一篇博客是关于Jenkins的内容,在Jenkins自动化编译时可能会自动获取版本更新进行build,那就需要用到版本更新的工具.这里使用VisualSVN Server来作为搭建svn的 ...

随机推荐

  1. Java微信公众号开发-外网映射工具配置

    一.开发环境准备 1.一个微信公众号 2.外网映射工具(开发调试)如花生壳.ngrok工具 注:与微信对接的URL要具备以下条件a:在公网上能够访问 b:端口只支持80端口 这里使用ngrok.cc: ...

  2. Ubuntu14.04下MySQL的安装

    1.输入 sudo apt-get install mysql-server 2.继续执行后,需要设定MySQL密码. 3.再次输入密码. 4.之后就安装成功了,输入mysql -u root -p进 ...

  3. openvpn的部署

    http://www.gaohuirong.cn/openvpn/2016/04/12/linux-install-openvpn.html

  4. JS跳出框架返回上一页

    链接部分 <a class="link" href="javascript:;" target="_top" onclick=&quo ...

  5. js学习笔记2---HTML属性操作

    1.HTML属性操作:读.写 属性名 属性值   2.属性读操作:获取.找到 a) 语法:元素.属性名 如:document.getElementById(“btn”).value; b) 字符串的连 ...

  6. 【USACO 2.1】The Castle

    /* TASK: castle LANG: C++ SOLVE: 深搜,注意每个方向对应值.枚举去掉的墙,然后再dfs,注意墙要复原,并且dfs里要判断是否超出边界. */ #include<c ...

  7. 【2016多校训练4】Multi-University Training Contest 4

    1001  Another Meaning 题意:字符串A中包含的字符串B可以翻译或不翻译,总共有多少方案. 题解:动规,dp[i]表示A的第i位为止有多少方案. 转移方程: dp[i]=dp[i-1 ...

  8. mybatis下报错:元素类型为 "mapper" 的内容必须匹配 "(cache-ref|cache|resultMap*|parameterMap

    今天使用别人的代码报错,但是有时又不报错原来是配置文件的顺序要遵守 注意 "必须匹配" 四个字, 其意味着顺序很重要, 必须要一致, 试试将 resultMap 中各元素的顺序修改 ...

  9. BZOJ4423 [AMPPZ2013]Bytehattan

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转 ...

  10. git命令的使用 【备用】

    *下面为对本地仓库进行操作 [将文件提交到本地仓库] git add 文件名                     将文件添加到暂存区 git status                      ...