CentOS7编译安装ntp

搭建时间同步服务器

系统版本:CentOS Linux release 7.4.1708 (Core)

ntp版本:ntpd 4.2.8p11


一:服务器端配置
先创建安装目录:mkdir -p /data/server/ntp


1、下载、解压安装包,然后编译安装
# wget https://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.8p11.tar.gz
# tar -zxvf ntp-4.2.8p11.tar.gz
# cd ntp-4.2.8p11
# ./configure --prefix=/data/server/ntp --enable-all-clocks --enable-parse-clocks
# make && make install


2、修改配置文件(如果默认没有该文件,则需手动创建)
# vim /etc/ntp.conf
interface listen 0.0.0.0
server 127.127.1.0
fudge 127.127.1.0 stratum 10
restrict 192.168.199.0 mask 255.255.255.0 nomodify notrap


3、把ntp设置为服务
# cp /data/server/ntp/bin/ntpd /etc/init.d/ntpd


4、启动ntp并查看进程是否启动
# service ntpd start
# netstat -anptu | grep ntp
# iptable -I INPUT -p tcp --dport 123 -j ACCEPT

 


二:客户端配置 

1、yum安装ntpdate

# yum -y install ntpdate


2、设置任务计划自动与时间服务器同步时间(如设置每天凌晨3点连接时间服务器同步时间)
# crontab -e
00 03 * * * /usr/sbin/ntpdate 192.168.199.156; /sbin/hwclock -w

 

3、重启crond服务
# systemctl restart crond


4、测试
先随意设置一个时间
# timedatectl set-time 12:00:00 && date
立即连接ntp服务器同步时间
# ntpdate 192.168.199.156 && date

 

 

########完成##########

 

 

posted @ 2018-06-28 15:03  relax.1949  阅读(4553)  评论(0编辑  收藏  举报