【Linux时间服务器搭建】

简介:

安装环境:CentOS 5.3企业环境

一、    搭建时间同步服务器
a、前言:NTP服务器【Network Time Protocol(NTP)】是用来使计算机时间同步化的一种协议,它可以使计算机对其服务器或时钟源(如石英钟,GPS等等)做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒,WAN上几十毫秒)。
b、安装背景* 随着公司的业务不断扩大,服务器数量增加,为了方便统一各服务器时间,适合拥有自己的时间服务器。下面我们就开始ntp之旅。
 
下载的源码包放在/usr/src下面,安装好的应用程序放在/usr/local/下。
1、 编译安装ntp server (服务器端配置)
首先下载ntp稳定版本到/usr/src
cd /usr/src
tar zxvf ntp -4.2.6.tar.gz
cd ntp-4.2.6/
./configure --prefix=/usr/local/ntp-4.2.6 --enable-all-clocks --enable-parse-clocks
make clean && make check && make && make install
请从ntp官方下载网页(http://www.ntp.org/downloads.html)寻找稳定版本下载。
2、 修改ntp.conf配置文件
cp  /etp/ntp.conf /etc/ntp.conf.bak
vi /etc/ntp.conf
a、第一种配置:允许任何IP的客户机都可以进行时间同步
将“restrict default nomodify notrap noquery”这行修改成:
restrict default nomodify
b、第二种配置:只允许192.168.1.***网段的客户机进行时间同步
在restrict default nomodify notrap noquery(表示默认拒绝所有IP的时间同步)之后增加一行:
restrict 192.168.1.0 mask 255.255.255.0 nomodify
c、修改:上级时间服务器
server   202.162.32.12 prefer (优先选择,根据你附近的网络选择。)
restrict  202.162.32.12
server   210.72.145.44 prefer (中国国家授时中心的时间服务器IP地址)
restrict   210.72.145.44
server   pool.ntp.org
restrict   pool.ntp.org
3、 以守护进程启动ntpd
/usr/local/ntp-4.2.6/bin/ntpd -c /etc/ntp.conf -p /tmp/ntpd.pid –l /var/log/ntp.log
(注意*: ntpd启动后,客户机要等几分钟再与其进行时间同步,否则会提示“no server suitable for synchronization found”错误。)
4、配置时间同步客户机
crontab -e
增加一行,在每天的6点10分与时间同步服务器进行同步
10 06 * * * /usr/sbin/ntpdate ntp-server的ip >>/usr/local/logs/crontab/ntpdate.log
备注:如果客户机没有ntpdate,可以yum –y install ntp 即可!
5、以下是ntp服务器配置文件内容:(仅供参考)
一、cat /etc/ntp.conf文件如下配置:
# permit the source to query or modify the service on this system.
# restrict default nomodify notrap noquery
 
#######allow all host access
restrict default nomodify   //(默认允许所有,可以只允许某个网段,或者在iptables里面做限制。)
 
# --- OUR TIMESERVERS -----
server   202.162.32.12 prefer 
restrict  202.162.32.12
 
server    210.72.145.44 prefer 
restrict   210.72.145.44
 
server    pool.ntp.org
restrict   pool.ntp.org
 
server  127.127.1.0     # local clock
fudge   127.127.1.0    stratum 5
 
driftfile /var/lib/ntp/drift
broadcastdelay 0.008
 
# PLEASE DO NOT USE THE DEFAULT VALUES HERE. Pick your own, or remote
# systems might be able to reset your clock at will. Note also that
# ntpd is started with a -A flag, disabling authentication, that
# will have to be removed as well.
#
keys         /etc/ntp/keys
 
#ntp logs path
logfile  /var/log/ntp.log      

完!欢迎指正!


本文转自 wgkgood 51CTO博客,原文链接:http://blog.51cto.com/wgkgood/433894


相关文章
|
9天前
|
Java Linux
Springboot 解决linux服务器下获取不到项目Resources下资源
Springboot 解决linux服务器下获取不到项目Resources下资源
|
12天前
|
Linux
linux下搭建tftp服务器教程
在Linux中搭建TFTP服务器,需安装`tftp-server`(如`tftpd-hpa`)。步骤包括:更新软件包列表,安装`tftpd-hpa`,启动并设置开机自启,配置服务器(编辑`/etc/default/tftpd-hpa`),添加选项,然后重启服务。完成后,可用`tftp`命令进行文件传输。例如,从IP`192.168.1.100`下载`file.txt`: ``` tftp 192.168.1.100 <<EOF binary put file.txt quit EOF ```
27 4
|
1月前
|
存储 网络协议 Ubuntu
Linux环境下的SVN服务器搭建并结合内网穿透实现远程连接
Linux环境下的SVN服务器搭建并结合内网穿透实现远程连接
|
27天前
|
Linux Shell 网络安全
【Shell 命令集合 网络通讯 】Linux 与SMB服务器进行交互 smbclient命令 使用指南
【Shell 命令集合 网络通讯 】Linux 与SMB服务器进行交互 smbclient命令 使用指南
40 1
|
29天前
|
域名解析 存储 网络协议
Linux中搭建主从DNS服务器
搭建主从DNS架构以提升DNS服务的高可用性、负载均衡和数据冗余。主服务器配置涉及编辑`/etc/named.conf`,设置监听IP和允许查询的范围,并定义主区域及允许的数据传输。从服务器配置需指定为奴隶类型,并指明主服务器的IP。测试表明正反向查询解析均正常。注意配置文件的语法正确性和权限设置。
|
5天前
|
Linux 数据安全/隐私保护
Linux基础与服务器架构综合小实践
【4月更文挑战第9天】Linux基础与服务器架构综合小实践
1013 6
|
17天前
|
Ubuntu Linux 虚拟化
【Linux】ubuntu安装samba服务器
【Linux】ubuntu安装samba服务器
|
17天前
|
Linux
Linux安装bind9搭建自己的域名服务器
Linux安装bind9搭建自己的域名服务器
11 0
|
20天前
|
网络协议 Linux 网络安全
Linux服务器DNS服务器配置实现bind的正向解释和反向解释
Linux服务器DNS服务器配置实现bind的正向解释和反向解释
17 0
|
27天前
|
网络协议 安全 Shell
【Shell 命令集合 系统设置 】Linux 从远程时间服务器获取当前日期和时间 rdate命令 使用指南
【Shell 命令集合 系统设置 】Linux 从远程时间服务器获取当前日期和时间 rdate命令 使用指南
31 0