简单搭建ntp服务

1.检查ntp服务是否已经安装

sudo rpm -qa | grep ntp
显示已经安装ntp程序。如果安装过,应该有两个进程:
ntpdate… 用来和某台服务器同步
ntp… 用来提供时间同步服务

如果没有,就通过yarn install -y ntp安装下

2.修改配置文件ntp.conf

vi /etc/ntp.conf

2.1 启用restrice

取消注释 restrict 192.168.100.0 mask 255.255.255.0 nomodify notrap
并将网段改为集群的网段
restrict 172.16.30.2 mask 255.255.255.0 nomodify notrap

2.2 修改server域名配置

把默认的server域名配置注释掉,再增加几行

#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
server 127.127.1.0
fudge 127.127.1.0 stratum 10

3 修改配置文件ntpd

vi /etc/sysconfig/ntpd
添加一行:SYNC_CLOCK=yes

# Drop root to id 'ntp:ntp' by default.
SYNC_HWCLOCK=yes
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"

4.启动ntpd服务

service ntpd start

5.开机启动

sudo chkconfig ntpd on

6.其他服务器同步

ntpdate hostname
也可创建一个定时任务
crontab -e
*/10 * * * * /usr/sbin/ntpdate ntpdserver

7.查看时间

date "+%Y-%m-%d %H:%M:%S"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值