(7)centos7 同步服务器时间
一、服务器配置
1、查看服务器、客户端操作系统版本
[root@hadoop101 ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
2、查看服务器是否安装ntp,系统默认安装ntpdate;
[root@hadoop101 ~]# rpm -qa | grep ntp
fontpackages-filesystem-1.44-8.el7.noarch
ntpdate-4.2.6p5-28.el7.centos.x86_64
python-ntplib-0.3.2-1.el7.noarch
ntp-4.2.6p5-28.el7.centos.x86_64
3、安装ntp ntpdate,其中ntpdate默认安装,可以只安装ntp;
yum install ntp ntpdate -y
4、查看是否已安装完成,与第2步对比
[root@hadoop101 mysql-libs]# rpm -qa | grep ntp
fontpackages-filesystem-1.44-8.el7.noarch
ntpdate-4.2.6p5-28.el7.centos.x86_64
ntp-4.2.6p5-28.el7.centos.x86_64
python-ntplib-0.3.2-1.el7.noarch
5、查看ntp服务器状态,两条命令效果一样
[root@hadoop101 ~]# systemctl status ntpd
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)
或
[root@hadoop101 ~]# service ntpd status
Redirecting to /bin/systemctl status ntpd.service
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)
6、修改配置文件,使该NTP服务器在不联网的情况下,使用本服务器的时间作为同步时间
vim /etc/ntp.conf
把如下四行代码注释掉
#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 127.127.1.0
fudge 127.127.1.0 stratum 0
配置后:
[root@hadoop101 ~]# 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 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 ::1# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap# 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 127.127.1.0
fudge 127.127.1.0 stratum 0#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# Enable public key cryptography.
#cryptoincludefile /etc/ntp/crypto/pw# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys# Specify the key identifiers which are trusted.
#trustedkey 4 8 42# Specify the key identifier to use with the ntpdc utility.
#requestkey 8# Specify the key identifier to use with the ntpq utility.
#controlkey 8# Enable writing of statistics records.
7、启动ntp服务
systemctl start ntpd
或
service ntpd start
8、再次查看服务器状态是否配置成功
[root@hadoop101 mysql-libs]# systemctl status ntpd
● ntpd.service - Network Time ServiceLoaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)Active: active (running) since Fri 2019-08-16 18:33:01 CST; 13s agoProcess: 8792 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)Main PID: 8794 (ntpd)Tasks: 1CGroup: /system.slice/ntpd.service└─8794 /usr/sbin/ntpd -u ntp:ntp -gAug 16 18:33:01 hadoop101.com ntpd[8794]: Listen normally on 3 ...
Aug 16 18:33:01 hadoop101.com ntpd[8794]: Listen normally on 4 ...
Aug 16 18:33:01 hadoop101.com ntpd[8794]: Listen normally on 5 ...
Aug 16 18:33:01 hadoop101.com ntpd[8794]: Listen normally on 6 ...
Aug 16 18:33:01 hadoop101.com ntpd[8794]: Listening on routing ...
Aug 16 18:33:01 hadoop101.com ntpd[8794]: 0.0.0.0 c016 06 restart
Aug 16 18:33:01 hadoop101.com ntpd[8794]: 0.0.0.0 c012 02 freq_...
Aug 16 18:33:01 hadoop101.com ntpd[8794]: 0.0.0.0 c011 01 freq_...
Aug 16 18:33:01 hadoop101.com systemd[1]: Started Network Time ...
Aug 16 18:33:02 hadoop101.com ntpd[8794]: 0.0.0.0 c514 04 freq_...
Hint: Some lines were ellipsized, use -l to show in full.
或
[root@hadoop101 ~]# service ntpd status
9、查看是否同步
[root@hadoop101 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*LOCAL(0) .LOCL. 5 l 20 64 7 0.000 0.000 0.000
10、设置开机启动
[root@hadoop101 ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
11、设置防火墙,打开udp123端口(如果防火墙关了就不用设置了)
[root@hadoop101 ~]# firewall-cmd --permanent --add-port=123/udp
success
[root@hadoop101 ~]# firewall-cmd --reload
success
12、查看防火墙已打开端口
iptables -L -n
二、客户端配置(其他节点)
前5步与服务器一致
6、修改配置文件,将刚刚搭建好的NTP服务器作为客户端上游时间服务器
vim /etc/ntp.conf
#注释掉其他上游时间服务器
#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
#配置上游时间服务器为本地的ntpd Server服务器
server hadoop101.com
fudge hadoop101.com stratum 0#配置允许上游时间服务器主动修改本机的时间
restrict hadoop101.com nomodify notrap noquery
配置后:
[root@hadoop103 ~]# vi /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 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 ::1# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notraprestrict hadoop101.com nomodify notrap noquery# 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 iburstserver hadoop101.com
fudge hadoop101.com stratum 0#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# Enable public key cryptography.
#cryptoincludefile /etc/ntp/crypto/pw# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys# Specify the key identifiers which are trusted.
#trustedkey 4 8 42# Specify the key identifier to use with the ntpdc utility.
#requestkey 8# Specify the key identifier to use with the ntpq utility.
7、与本地ntpd Server同步一下
[root@hadoop102 ~]# ntpdate -u hadoop101.com
15 Aug 11:33:35 ntpdate[8768]: adjust time server 192.168.1.101 offset 0.004621 sec
8、启动ntp服务
systemctl start ntpd
或
service ntpd start
9、设置开机启动
[root@hadoop102 ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
10、查看状态
[root@hadoop103 ~]# ntpq -premote refid st t when poll reach delay offset jitter
==============================================================================hadoop101.com .LOCL. 1 u 13 64 1 8.148 -2.581 0.000
(7)centos7 同步服务器时间相关推荐
- 客户端如何修改服务器时间设置在哪里看,客户端同步服务器时间设置在哪里
客户端同步服务器时间设置在哪里 内容精选 换一换 在创建数据库连接之后,才能使用它来执行SQL语句操作数据.JDBC提供了三个方法,用于创建数据库连接.DriverManager.getConnect ...
- 自动售卖软件服务器,连锁收银系统中销售商品时自动同步服务器时间
在使用连锁版收银软件时,大家可能都会遇到一个头疼的问题:多台收银机电脑时间不一致,造成数据统计时出现偏差.一个较常见的现象是由于某种原因(中毒,主板电池没电,人为误操作等)导致电脑时间错误,比如目前时 ...
- 同步服务器时间 yum -y install ntpdate ntpdate -u cn.pool.ntp.org
同步服务器时间 yum -y install ntpdate ntpdate -u cn.pool.ntp.org
- 网页同步服务器时间长,javascript同步服务器时间和同步倒计时小技巧
之前在网上看到有人提问,如何在页面上同步显示服务器的时间,其实实现方法有几种,可能 一般人立马就想到可以使用Ajax每隔一秒去请求服务器,然后将服务器获取到时间显示在页面上,这样虽然能够实现,但存在一 ...
- Linux同步服务器时间
Linux同步服务器时间 CentOS安装ntp时间同步服务 方式一 crontab 同步时间命令:执行同步命令,服务端先需要启动ntpd服务,客户端不需要 ntpdate 192.168.1.100 ...
- 修改Centos7.6服务器时间
1.手动修改服务器时间 优点:修改简单易操作 缺点:时区重置 date -s '2021-12-22 14:44:20' 修改时间为: [root@bigdata101 ~]# date 2021年 ...
- centos同步服务器时间
集群同步,不同步互联网 查看所有节点ntpd服务状态 sudo systemctl status ntpd sudo systemctl start ntpd sudo systemctl is-en ...
- centos7 同步网络时间
安装ntpdate sudo yum install -y ntpdate 然后使用命令同步网络时间 sudo ntpdate pool.ntp.org 重新查看时间如下: 此处还不能完全解决掉这个问 ...
- 网络在线校时服务器ip,网络校时服务器如何同步服务器时间?
gzbowie 如果出错,就证明该电脑/PC没有开启Windowstime功能/ntp客户端功能,开启方法如下: Windows ntp服务客户端配置 1. 打开"开始",点击运行 ...
最新文章
- AI大觉醒:图灵奖得主Bengio称AI将产生意识,未来机器学习核心是注意力机制
- 思科路由器MTU及ip tcp adjust-mss测试
- HTTP API响应数据规范整理
- 自学python清单-python学习清单
- HDU 1284 钱币兑换问题 (完全背包)
- HDU-1251 统计难题 map写法
- 【java】Windows7 下环境变量设置
- shell 管道命令 、、||、>、>>(精)
- 使用微信支付购买《微信公众平台最佳实践》
- mongoDB对没有字段的记录新增字段
- 手推RNN BPTT(back propagation through time)反向传播
- .lrc 格式的歌词乱码,如何修改后正常显示
- 华为通用软件工程师面经
- 802.11 Backoff Timer,bugFix_timer_
- Laravel5.5 项目开发文档,精简版,不适合新手使用。
- RestTemplate使用实战-exchange方法讲解-HTTP请求
- android yuv旋转,针对移动端摄像头yuv旋转、裁剪、镜像、格式转换算法的实现
- (私人收藏)2019WER积木教育机器人赛(普及赛)解决方案-(全套)获取能源核心
- 1400协议是什么和28181区别_28181平台对接接口详解
- 攫取黄金一斗--从旅游业入手
热门文章
- 【Linux入门学习之】Ubuntu常用软件 速配指南之软件参考
- java poi 填充单元格_POI操作excel表格(建立工作薄、创建工作表、将数据填充到单元格中)...
- 本轮大宗商品涨价:(背后原因分析)2021-09
- Lisp语言中的if语句
- 校招(含实习生春招)指南
- 怎样在html中显示IP地址,如何通过ip查经纬度
- LSB顺序+随机隐写和提取(matlab)
- php程序员的出路,php程序员有前途吗
- 64个 360 评估的提问样例
- java 获取天气_获取免费天气(Java抓取百度天气)