Centos7#基础服务之NTP时间服务

NTP时间服务功能(ntpd)

NTP服务器,Network Time Protoc作用:为网络中的主机授时,同步的时间在2min-10min,需要看主板上面的硬件的性能

一、时间服务器 ntp 123/udp

ntp-server和ntp-client完成初始化
  两台机器:完成初始化
  clinet:跟服务器进行时间同步,临时修改主机名ntp-clinet,重启生效
  关掉终端重新打开一个终端就可以立刻生效
  server:时间服务器,临时修改主机名为ntp-server
 
  1、所有机器关闭防火墙和selinux
  systemctl stop firewalld
  systemctl disable firewalld
  setenforce 0 (临时关闭selinux)  
  [root@qf-xingdian ~]# getenforce (查看selinux)
  Disabled
  扩展:永久关闭selinux
  vim /etc/selinux/config
  SELINUX=disabled
  第二种方法永久关闭selinux
  sed -i ‘/^SELINUX=/c SELINUX=disabled’ /etc/selinux/config

二、配置NTP-Server服务器

修改时间服务器主机名
  [root@htp-server ~]# hostnamectl set-hostname ntp-client
  查询ntp是否安装
  [root@htp-server ~]# rpm -qa |grep ntp
  查询到继续操作 ntp-4.2.4p8-3.el6.x86_64
  查询不到就安装一下
  [root@htp-server ~]# yum -y install ntp
  NTP Server配置示例:
  server 127.127.1.0代表的是本地时间服务器
  [root@htp-server ~]# vim /etc/ntp.conf //配置文件全部删掉,只要下面三行

restrict default nomodify   //不允许客户端登录,也不允许客户端修改
server 127.127.1.0           //使用本地的bios时间,自己跟自己同步
fudge 127.127.1.0 stratum 10 //定义级别,范围0-16,越小越精准

配置文件保存退出,NTP服务重启
  [root@htp-server ~]# systemctl start ntpd
  [root@htp-server ~]# systemctl enable ntpd
  restrict 英 [rɪˈstrɪkt] 美 [rɪˈstrɪkt] v.限制
  fudge 英 [fʌdʒ] 美 [fʌdʒ] v.含糊其辞;回避
  stratum 英 [ˈstrɑːtəm] 美 [ˈstreɪtəm] n.层
  date -s 9:00 服务器修改时间,客户机不能同步时间(手动修改时间,会造成和本地bios时间不同步),可以先将服务器与网络上NTP服务器同步时间,这时需要把服务器的ntp服务stop,时间同步后再start。客户机即可以同步时间

三、配置NTP-Client客户端

客户端需要ntpdate命令
  [root@ntp-client ~]# hostnamectl set-hostname ntp-client
  [root@ntp-client ~]# yum -y install ntpdate
  [root@ntp-client ~]# ntpdate -b 10.11.67.31  //手动时间同步 -b加速初始化同步
  26 Oct 13:05:03 ntpdate[11959]: step time server 10.11.67.31 offset 4291084.254062 sec
  可以制定计划任务定时执行时间同步
  crontab -e 创建一个计划任务
  00 00 * * * ntpdate -b 172.16.110.1 每隔一天自动时间同步
  客户机和服务器也可以和网络上的NTP服务器同步时间

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值