Note/环境/基本命令/常用linux命令.md

116 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 时间同步
查看日期时间、时区、以及NTP状态
```shell
timedatectl
```
展示如下
```shell
[root@localhost ~]# timedatectl
Local time: 四 2024-01-25 21:30:41 EST
Universal time: 五 2024-01-26 02:30:41 UTC
RTC time: 五 2024-01-26 02:30:40
Time zone: America/New_York (EST, -0500)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
```
### Centos 7
打开终端以root用户身份登录。
安装NTPNetwork Time Protocol软件包。运行以下命令
```
yum install ntp
```
安装完成后编辑NTP配置文件。运行以下命令
```
vi /etc/ntp.conf
```
在打开的文件中找到或添加以下行将其注释解除并设置NTP服务器
```
server pool.ntp.org
```
或者你可以使用其他可靠的NTP服务器例如
```
server ntp1.aliyun.com
server ntp2.aliyun.com
server ntp3.aliyun.com
```
保存并关闭文件。
启动NTP服务并设置为开机自启。运行以下命令
```
systemctl start ntpd
systemctl enable ntpd
```
等待一段时间系统将与NTP服务器同步时间。
完成上述步骤后CentOS 8的时间将会与NTP服务器同步。你可以使用以下命令检查系统时间是否已经同步
```
date
```
### Centos 8 Stream
查看同步源
```shell
chronyc sources -v
```
打开终端以root用户身份登录。
安装chrony软件包。运行以下命令
```
yum install chrony
```
安装完成后编辑chrony配置文件。运行以下命令
```
vi /etc/chrony.conf
```
在打开的文件中找到或添加以下行将其注释解除并设置NTP服务器
```
server pool.ntp.org
```
或者你可以使用其他可靠的NTP服务器例如
```
server ntp1.aliyun.com
server ntp2.aliyun.com
server ntp3.aliyun.com
```
保存并关闭文件。
启动chronyd服务并设置为开机自启。运行以下命令
```
systemctl start chronyd
systemctl enable chronyd
```
等待一段时间系统将与NTP服务器同步时间。
完成上述步骤后CentOS 8的时间将会与NTP服务器同步。你可以使用以下命令检查系统时间是否已经同步