说明
- 在集群相关服务搭建的时候都会要求服务器之间的时间同步,但是一般私有云的服务器是没有外部网络连接的,可通过在一台服务器上搭建ntpd服务(局域网机器,且有外网,就可保证时间通过网络同步),其他服务器与该服务器进行时间同步达到服务器之间时间同步的效果;
- 虽然没有外网,但是依赖的安装还是通过yum比较方便,可以参考httpd挂载iso文件搭建centos本地yum库,进行本地yum库的搭建;
- 如果不想麻烦搭建本地yum库,也可前往Download CentOS Linux ISO images进行rpm包下载,通过rpm命令安装;
ntp服务安装
-
下载ntp:
yum -y install ntp -
配置修改(
/etc/ntp.conf:# restrict 127.0.0.1 # 将原有的restrict注释掉,修改为服务器网段,注意子网掩码 restrict 192.168.0.0 mask 255.255.255.0 nomodifiy notrap # 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注释掉,添加以下server server 127.127.1.0 -
启动服务并设置开机启动:
service ntpd start chkconfig ntpd on
ntpdate服务安装
-
在需要进行时间同步的机器上安装ntpdate:
yum -y install ntpdate -
进行时间同步(ip修改为安装ntp服务的机器):
ntpdate 192.168.0.81 -
配置定时任务,
crontab -e填入以下内容:*/15 * * * * ntpdate 192.168.0.81