Centos6
- rpm -q ntp 查看是否安装ntp
- yum install ntp 安装ntp,已安装则跳过此步骤
- chkconfig --list ntpd 查看
- chkconfig ntpd on 设置开机自启动,chkconfig --list ntpd 查看
- vi /etc/ntp.conf 配置同步ntp-server时间,贴出变动内容如下,10.82.71.73为对时服务器
#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
#对时服务器,配置成ntp-server的机器
server 10.82.71.73
restrict 10.82.71.73 nomodify notrap noquery
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
- vi /etc/sysconfig/ntpd 设置时钟同步,文件内容如下
# Drop root to id 'ntp:ntp' by default.
SYNC_HWCLOCK=yes
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"
- service ntpd start 启动ntp服务
- ntpdate -u 10.82.71.73 手动同步一次时间
Centos7
与Centos6大致相同,执行结果参考上面,如下
- rpm -qa | grep ntp 查看是否安装ntp
- yum install ntp ntpdate -y 安装ntp,已安装则跳过此步骤
- systemctl status ntpd 查看ntp服务器状态
- vi /etc/ntp.conf 配置同步ntp-server时间,文件内容如下
- systemctl start ntpd 启动ntp服务
- systemctl enable ntpd 设置开机启动
- ntpdate -u 10.82.71.73手动同步一次时间