自动同步系统时间

Linux

Posted by YiMiTuMi on September 7, 2023

自动同步系统时间

安装ntp服务

sudo apt-get install ntp

CentOs 没有 apt-get命令

sudo yum install ntp

在安装完后,在/etc/ntp.conf文件以配置ntp服务,添加:

server ntp.aliyun.com

启动ntp服务

sudo /etc/init.d/ntp start

CentOs用

systemctl start ntpd.service

ntp服务将会启动并自动同步本地计算机的时间。

可以用命令查看 ntpd.service 服务器是否起来

systemctl list-units --type=service --state=running

运行:

PID TTY          TIME CMD
19239 pts/0    00:00:00 bash
35768 pts/0    00:00:00 ps
[root@localhost etc]# systemctl list-units --type=service --state=running
UNIT                     LOAD   ACTIVE SUB     DESCRIPTION
auditd.service           loaded active running Security Auditing Service
crond.service            loaded active running Command Scheduler
dbus.service             loaded active running D-Bus System Message Bus
emqx.service             loaded active running emqx daemon
getty@tty1.service       loaded active running Getty on tty1
irqbalance.service       loaded active running irqbalance daemon
mysqld.service           loaded active running MySQL Server
NetworkManager.service   loaded active running Network Manager
ntpd.service             loaded active running Network Time Service ----------------------在这里
polkit.service           loaded active running Authorization Manager
rc-local.service         loaded active running /etc/rc.d/rc.local Compatibility
redis.service            loaded active running Redis persistent key-value databasersyslog.service          loaded active running System Logging Service
smb.service              loaded active running Samba SMB Daemon
sshd.service             loaded active running OpenSSH server daemon
systemd-journald.service loaded active running Journal Service
systemd-logind.service   loaded active running Login Service
systemd-udevd.service    loaded active running udev Kernel Device Manager
tuned.service            loaded active running Dynamic System Tuning Daemon
vgauthd.service          loaded active running VGAuth Service for open-vm-tools
vmtoolsd.service         loaded active running Service for virtual machines hosted
LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.
21 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.