有勇气的牛排博客
☰

ntp服务 时间节点配置

有勇气的牛排 1346 linux 2023-02-28 16:29:04

知止自律打卡-微信小程序APP
一款微信自律打卡小程序,支持自定义打卡项目、习惯记录、项目日记、专注计时与数据统计。自律打卡、学习打卡、读书打卡、健身打卡、运动打卡、减肥打卡、戒色打卡、养生打卡、戒烟、戒酒、戒熬夜等多种场景。万能打卡模板自由创建。可自定义每日打卡目标,记录习惯连续天数,可视化追踪成长进度。
了解产品详情 →
微信搜索「知止自律打卡」
知止自律打卡微信小程序

Centos时间修改及ntp服务节点配置

1 时间查看

系统时间

timedatectl
[root@master home]# timedatectl
      Local time: Wed 2023-03-01 20:00:05 CST
  Universal time: Wed 2023-03-01 12:00:05 UTC
        RTC time: Wed 2023-03-01 05:03:19
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

硬件时间

hwclock -r

2 系统时间修改

语法:date -s 时间字符串

1、只改系统的日期,不改时间

date -s 2012-08-02

2、只改时间不改日期

date -s 10:08:00

3、同时修改日期和时间

date -s "2012-05-18 04:53:00"

3 时区查看与修改

这里有两种方案,分别通过timedatectl 与软连接的方法修改。

3.1 timedatectl 修

查看时区

timedatectl list-timezones | grep -i shang

修改当前系统时区

timedatectl set-timezone Asia/Shanghai

3.2 软链接 修改

查看当前时区

ls -al /etc/localtime

修改时区

ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

4 ntp服务搭建

4.1 安装

操作系统版本为centos 7.6,安装前无ntp服务,/etc目录下也没有相关ntp文件,也没有ntpdate命令

4.1.1 yum安装

yum -y install ntp

4.1.2 rpm离线安装

cat /etc/redhat-release

查看是否安装ntp

rpm -qa | grep ntp

下载:https://pkgs.org/download/ntp

安装命令

rpm -ivh fontpackages-filesystem-1.44-8.el7.noarch.rpm
rpm -ivh ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm --nodeps --force
rpm -ivh ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm

rpm -ivh autogen-libopts-5.18-5.el7.x86_64.rpm

4.1.3 源码安装

https://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/

4.2 服务端 配置

配置服务器节点ntp.conf

vim /etc/ntp.conf
# restrict default nomodify notrap nopeer noquery

# 授权 192.168.56.* 网段机器可以访问
restrict 192.168.56.0 mask 255.255.255.0 nomodify notrap

# 禁止使用互联网时间
#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.0.0.1	# 无网络修改为本地
fudge 127.0.0.1 stratum 10	# 无网络配置增加项

配置服务器节点ntpd

vim /etc/sysconfig/ntpd
# 开启硬件时间与系统时间同步
SYNC_HWCLOCK=yes

重启ntpd服务

systemctl start ntpd

开机启动

systemctl enable ntpd

同步

ntpdate -u times.aliyun.com

4.3 客户端 配置

关闭ntp服务与自启动

systemctl stop ntpd
systemctl disable ntpd

配置定时同步时间服务器 (2min/次)

0 2 * * * /usr/sbin/ntpdate master

4.4 查看服务

查看所有节点 ntpd 服务状态和开机自启动状态

systemctl status ntpd
systemctl stop ntpd
systemctl start ntpd
systemctl is-enabled ntpd

5 报错解决

5.1 报错 Failed to start ntpd.service: Unit not found

查看服务列表是否有该服务

systemctl list-unit-files --type=service

image20230301121706582.png

安装

yum -y install ntp

5.2 报错 libopts.so.25

查看

ldd /usr/sbin/ntpd
libopts.so.25.x86_64.rpm

rpm -qa | grep libopts

标签:

×
×