ntp与chrony时间同步部署
### 一、ntp
1.安装ntp服务(服务端,需要在防火墙开启服务的123端口,协议为UDP)
先检测系统是否已安装,如下图有这两个rpm包则说明已安装,无需在安装
rpm -qa | grep ntp

如果未安装则执行以下命令
yum install ntp
2.修改配置文件
vim /etc/ntp.conf

3.重启服务
systemctl restart ntpd
二、配置ntp客户端
1.同上需要安装相同的ntp服务
yum install ntp
2.修改配置文件
vim /etc/ntp.conf

3.重启服务端,再关闭此服务依次执行如下命令
systemctl restart ntpd
systemctl stop ntpd
4.同步时间命令
ntpdate 124.220.48.40(ip为服务端ip)
显示如下则与服务器同步时间成功

### 二、chrony (推荐)
1. 安装(一般系统都会自带,如果没有则安装。服务端,需要在防火墙开启服务的123端口,协议为UDP)
```
yum install chrony -y
systemctl enable chronyd.service
systemctl restart chronyd.service
systemctl status chronyd.service
```
2. 修改服务端配置文件(server一般填国内时间同步服务器即可,我填写的是腾讯)
```
vim /etc/chrony.conf
```

systemctl restart chronyd.service
systemctl enable chronyd
3. 客户端
```
vim /etc/chrony.conf
```

4. 重启chrony
systemctl restart chronyd.service
systemctl enable chronyd
同步时间
chronyc sources
强制同步下系统时钟:
chronyc -a makestep
查看时间同步源状态:
chronyc sourcestats
查看时间同步源:
chronyc sources -v
查看日期时间、时区及NTP状态
timedatectl
查看时区列表
timedatectl list-timezones
修改时
timedatectl set-timezone Asia/Shanghai
修改日期时间
timedatectl set-time "2015-01-21 11:50:00"
设置完时区后,强制同步下系统时钟
chronyc -a makestep