Centos7 NTP服务
修改时区(改为中国标准时区)ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime(如果在安装centos时指定过了 这一步就不用了)
timedatectl set-ntp no # 关闭ntp timedatectl set-time "2018-07-05 15:06:00" # 设置时间 timedatectl set-timezone Asia/Shanghai # 设置时区 date # 查看配置是否正确
1、安装ntp
yum -y install ntp
[root@cdh02 ntp]# yum install -y ntp 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: ftp.sjtu.edu.cn * extras: ftp.sjtu.edu.cn * updates: centosv8.centos.org base | 3.6 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/4): extras/7/x86_64/primary_db | 205 kB 00:00:05 (2/4): base/7/x86_64/group_gz | 153 kB 00:00:05 (3/4): base/7/x86_64/primary_db | 6.1 MB 00:00:12 updates/7/x86_64/primary_db FAILED ] 734 B/s | 7.3 MB 01:07:38 ETA http://centosv8.centos.org/centos/7.8.2003/updates/x86_64/repodata/1c1cef9b9757d3f2013951752cad3bf93417ab30c1b8144b4d465df77510c502-primary.sqlite.bz2: [Errno 12] Timeout on http://centosv8.centos.org/centos/7.8.2003/updates/x86_64/repodata/1c1cef9b9757d3f2013951752cad3bf93417ab30c1b8144b4d465df77510c502-primary.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds') 正在尝试其它镜像。 updates/7/x86_64/primary_db FAILED ] 3.4 kB/s | 7.7 MB 00:12:09 ETA http://centosu8.centos.org/centos/7.8.2003/updates/x86_64/repodata/1c1cef9b9757d3f2013951752cad3bf93417ab30c1b8144b4d465df77510c502-primary.sqlite.bz2: [Errno 14] curl#18 - "transfer closed with 2541101 bytes remaining to read" 正在尝试其它镜像。 (4/4): updates/7/x86_64/primary_db | 3.8 MB 00:14:30 正在解决依赖关系 --> 正在检查事务 ---> 软件包 ntp.x86_64.0.4.2.6p5-29.el7.centos.2 将被 安装 --> 正在处理依赖关系 libopts.so.25()(64bit),它被软件包 ntp-4.2.6p5-29.el7.centos.2.x86_64 需要 --> 正在检查事务 ---> 软件包 autogen-libopts.x86_64.0.5.18-5.el7 将被 安装 --> 解决依赖关系完成 依赖关系解决 ======================================================================================================================= Package 架构 版本 源 大小 ======================================================================================================================= 正在安装: ntp x86_64 4.2.6p5-29.el7.centos.2 updates 549 k 为依赖而安装: autogen-libopts x86_64 5.18-5.el7 base 66 k 事务概要 ======================================================================================================================= 安装 1 软件包 (+1 依赖软件包) 总下载量:615 k 安装大小:1.5 M Downloading packages: 警告:/var/cache/yum/x86_64/7/base/packages/autogen-libopts-5.18-5.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY autogen-libopts-5.18-5.el7.x86_64.rpm 的公钥尚未安装 (1/2): autogen-libopts-5.18-5.el7.x86_64.rpm | 66 kB 00:00:03 ntp-4.2.6p5-29.el7.centos.2.x8 FAILED ] 1.6 B/s | 208 kB 74:11:17 ETA http://centost7.centos.org/centos/7.8.2003/updates/x86_64/Packages/ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm: [Errno 12] Timeout on http://centost7.centos.org/centos/7.8.2003/updates/x86_64/Packages/ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds') 正在尝试其它镜像。 ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm 的公钥尚未安装================================] 1.5 kB/s | 615 kB 00:00:00 ETA (2/2): ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm | 549 kB 00:02:38 ----------------------------------------------------------------------------------------------------------------------- 总计 2.3 kB/s | 615 kB 00:04:28 从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 检索密钥 导入 GPG key 0xF4A80EB5: 用户ID : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>" 指纹 : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5 软件包 : centos-release-7-8.2003.0.el7.centos.x86_64 (@anaconda) 来自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安装 : autogen-libopts-5.18-5.el7.x86_64 1/2 正在安装 : ntp-4.2.6p5-29.el7.centos.2.x86_64 2/2 验证中 : autogen-libopts-5.18-5.el7.x86_64 1/2 验证中 : ntp-4.2.6p5-29.el7.centos.2.x86_64 2/2 已安装: ntp.x86_64 0:4.2.6p5-29.el7.centos.2 作为依赖被安装: autogen-libopts.x86_64 0:5.18-5.el7 完毕! [1] 已杀死 yum install -y ntd
2、ntp主机配置 vi /etc/ntp.conf
主节点
其他节点
restrict 10.0.0.0 mask 255.255.255.0 #允许10.0.0.0 网段中的服务器访问本ntp服务器进行时间同步
3、重新启动 ntp 服务
service ntpd restart
4、设置开机自启
systemctl enable ntpd.service
ntpdc -c loopinfo #查看与时间同步服务器的时间偏差 ntpq -p #查看当前同步的时间服务器 ntpstat #查看状态 定时同步crontab crontab -e 10 * * * * /usr/sbin/ntpdate n47.aa-data.cn
5、查看服务器状态
systemctl status ntpd.service
6、同步时间
ntpstat
主节点
其他节点
完