1、时间修改:date -s "2019-05-01 19:10:30"
2、clock -w
3、data
时间同步大概需要5-10分钟的时间等待
启动ntp:systemctl start ntpd
查看ntp状态:systemctl status ntpd
ntp服务设为开机自启:systemctl enable ntpd
查看状态:ntpstat
配置时间同步器:ntpdate -u ntp2.aliyun.com
可选时间服务器
选择master作为ntp服务器端,vi /etc/ntp.conf。
网段设置:restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
日志存放位置:logfile /var/log/ntpd.log
时间服务器设置:
ntp配置项目,时间服务器要是出问题时,就转掉本机服务器时间
5台虚拟主机
1.安装ntp:
yum install -y ntp
2.修改ntp的配置文件(ntp服务端配置)
vi /etc/ntp.conf
```
# 配置日志
logfile /var/log/ntpd.log
#restrict 192.168.1.0 mask 255.255.255.0 nomodify nostrap
# 在3个网段下的所有机器都可以连接我的ntp服务器
restrict 192.168.3.0 mask 255.255.255.0 nomodify nostrap
# 注释默认的ntp服务器
# server 0.centos.pool.ntp.org iburst
service ntp1.aliyun.com
service ntp2.aliyun.com
service ntp3.aliyun.com
# 当服务器不可用,本机作为ntp服务器
server 127.0.0.1
fudge 127.0.0.1 stratum 10
```
3. 手动同步ntp服务器时间
ntpdate -u ntp1.aliyun.com
失败原因:防火墙 网络
4.启动
systemctl start ntpd
systemctl status ntpd
# 开机自启
systemctl enable ntpd
PS:同步需要5-10分钟
ntpstat
5.ntp客户端配置
vi /etc/ntp.conf
```
# 注释默认的时间服务器
# 同步master的时间(master的ip或主机名)
server 192.168.3.100
```
6.测试
修改时间
date -s "2019-05-01 19:10:30"
clock -w
date
# 查看同步状态
ntpstat