Centos6.9 搭建NTP时间同步服务
1 前言
在内部局域网不能联网进行时间同步的时候我们就需要搭建NTP时间服务器使局域网的机器时间同步。此时局域网的机器只有一个或多个内网网卡而没有外部网卡,而搭建NTP服务的机器至少有一个外部网卡和一个与局域网同网段的内网网卡,外网网卡用于本机时间同步,内网网卡用于连通局域网。下边就可以搭建一下NTP服务
环境:
NTP(Server) hostname: m01 eth0: 10.0.0.61 eth1: 172.16.1.61 NTP(Client) eth0: 172.16.1.31
2 Server端的安装及配置
2.1 安装ntp服务组件
yum install ntp -y rpm -qa ntp
2.2 配置文件详解
# 默认配置文件 [root@m01 ~]# egrep -v "^$|#" /etc/ntp.conf # 过滤掉注释行 driftfile /var/lib/ntp/drift restrict default kod nomodify notrap nopeer noquery # 对默认的客户端拒绝所有操作 restrict -6 default kod nomodify notrap nopeer noquery # 针对ipv6地址的权限 restrict 127.0.0.1 # 允许本地地址的一切操作 restrict -6 ::1 # 允许ipv6地址的一切操作 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 includefile /etc/ntp/crypto/pw keys /etc/ntp/keys
2.3 restrict介绍
权限的设定主要是由restrict的参数决定的。
restrict语法
restrict IP地址 mask 子网掩码 参数
其中 IP 可以是IP地址,也可以是 default ,default 就是指所有的IP
参数有以下几个:
ignore:关闭所有的 NTP 联机服务
nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。
notrust:客户端除非通过认证,否则该客户端来源将被视为不信任子网
noquery:不提供客户端的时间查询
注意:如果参数没有设定,那就表示该 IP (或子网)没有任何限制!
设定局域网内部网段所有客户端可以连接到本地进行时间同步,但是拒绝他们修改服务器上的时间
restrict 172.16.1.0 mask 255.255.255.0 nomodify
2.4 修改配置文件如下
[root@m01 ~]# cat /etc/ntp.conf 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 restrict 172.16.1.0 mask 255.255.255.0 nomodify restrict -6 ::1 server ntp1.aliyun.com # 配置上层时间同步服务器 server 127.0.0.1 fudge 127.0.0.1 stratum 10 # 设置stratum级别为10 includefile /etc/ntp/crypto/pw keys /etc/ntp/keys
3 Client配置
1、先安装ntp,一般虚拟机默认都安装过了。
2、只需要在客户端的配置文件/etc/ntp.conf中添加我们刚才配置的时间服务器ip地址或主机名(需要客户端本地配置dns解析,修改/etc/hosts文件)
[root@client ~]# cat /etc/ntp.conf 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 restrict -6 ::1 server m01 #<==添加自己的时间服务器 includefile /etc/ntp/crypto/pw keys /etc/ntp/keys
4 服务端启动服务并测试
# Server Start Service [root@m01 ~]# /etc/init.d/ntpd start # Client Test [root@client ~]# ntpdate m01 11 Apr 10:49:37 ntpdate[3523]: step time server 172.16.1.61 offset 40976.883166 sec [root@client ~]# date Wed Apr 11 10:49:40 CST 2018
5 扩展知识
5.1 修改本地时区
[root@m01 ~]# date # 有可能我们看到的时区不是CST(中国的默认时区) Wed Apr 11 11:54:18 EDT 2018 # 修改本地时区,把/usr/share/zoneinfo/目录下我们想要的timezone拷贝到/etc/localtime文件即可(覆盖) [root@m01 ~]# \cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime [root@m01 ~]# date Wed Apr 11 11:55:21 CST 2018
5.2 配置文件中的driftfile是什么
我们每一个system clock的频率都有小小的误差,这个就是为什么机器运行一段时间后会不精确. NTP会自动来监测我们时钟的误差值并予以调整.但问题是这是一个冗长的过程,所以它会把记录下来的误差先写入driftfile.这样即使你重新开机以后之前的计算结果也就不会丢失了
5.3 同步硬件时钟
# 在/etc/sysconfig/ntpd配置文件中添加SYNC_HWCLOCK=yes即可 cat >>/etc/sysconfig/ntpd<<EOF SYNC_HWCLOCK=yes EOF # 或者使用hwclock -w命令
5.4 配置同步定时任务
# Client 每五分钟同步一下 cat >>/var/spool/cron/root<<EOF #time sync by rsq */5 * * * * /usr/sbin/ntpdate m01 > /dev/null 2>&1 EOF
5.5 设置开机自启动
[root@m01 ~]# chkconfig ntpd on [root@m01 ~]# chkconfig --list ntpd ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
参考博客:
https://blog.csdn.net/iloli/article/details/6431757
http://blog.51cto.com/13178102/2052175
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Linux各个版本修改root密码以及找回root密码
一、Linux下修改root密码方法 以root身份登陆,执行: passwd 用户名 然后根据提示,输入新密码,再次输入新密码,系统会提示成功修改密码。 具体示例如下: [root@www ~]# passwd root Changing password for user root. New UNIX password: BAD PASSWORD: it is based on a dictionary word Retype new UNIX password: passwd: all authentication tokens updated successfully. 二、Linux下添加新用户的命令 useradd 用户名 三、Linux下root密码找回方法 Linux的root享有至高无上的权力,一旦root密码忘记或者被盗,是一件非常头痛的事情,那么怎么样才能找回root的密码呢?本人把其总结如下: (一)Linux 系统密码破解 在grub选项菜单按e进入编辑模式 编辑kernel那行 /init 1 (或/single) 按B重启 进入后执行下列命令 root@#...
- 下一篇
CentOS服务器安装ab命令压力测试网站性能
网站性能压力测试是服务器网站性能调优过程中必不可缺少的一环。只有让服务器处在高压情况下,才能真正体现出软件、硬件等各种设置不当所暴露出的问题。 性能测试工具目前最常见的有以下几种:ab、http_load、webbench、siege。今天我们专门来介绍ab。 ab是apache自带的压力测试工具。ab非常实用,它不仅可以对apache服务器进行网站访问压力测试,也可以对或其它类型的服务器进行压力测试。比如nginx、tomcat、IIS等。 下面我们开始介绍有关ab命令的使用: 1、ab的原理 2、ab的安装 3、ab参数说明 4、ab性能指标 5、ab实际使用 一、ab的原理 ab是apachebench命令的缩写。 ab的原理:ab命令会创建多个并发访问线程,模拟多个访问者同时对某一URL地址进行访问。它的测试目标是基于URL的,因此,它既可以用来测试apache的负载压力,也可以测试nginx、lighthttp、tomcat、IIS等其它Web服务器的压力。 ab命令对发出负载的计算机要求很低,它既不会占用很高CPU,也不会占用很多内存。但却会给目标服务器造成巨大的负载,其原...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- SpringBoot2全家桶,快速入门学习开发网站教程
- Windows10,CentOS7,CentOS8安装MongoDB4.0.16
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- CentOS7,CentOS8安装Elasticsearch6.8.6
- CentOS6,CentOS7官方镜像安装Oracle11G
- Windows10,CentOS7,CentOS8安装Nodejs环境
- Linux系统CentOS6、CentOS7手动修改IP地址