1.1查看centos版本
1.2查看ntpd软件版本
ntpd --version
2. 安装前提
2.1 安装依赖包
[root@ntpserver ~]# yum install gcc gcc-c++ openssl-devel libstdc++* libcap* |
如果服务器已经安装 则不需要执行。
2.2 备份旧版本的配置文件
cp -ar /etc/ntp /etc/ntp.bak
cp /etc/ntp.conf /etc/ntp.conf.bak
cp /etc/init.d/ntpd /etc/init.d/ntpd.bak
cp /etc/sysconfig/ntpd /etc/sysconfig/ntpd.bak
cp /etc/sysconfig/ntpdate /etc/sysconfig/ntpdate.bak
2.3 卸载yum安装的ntpd服务
yum erase ntp ntpdate
3.上传安装包 解压编译安装
3.1解压后在文件中执行 编译ntpd
./configure --prefix=/usr --bindir=/usr/sbin --sysconfdir=/etc --enable-linuxcaps --with-lineeditlibs=readline --docdir=$(pwd)/ntp-4.2.8p9 --enable-all-clocks --enable-parse-clocks --enable-clockctl
make && make install
安装可能会缺失部分依赖 需查找下载
4. 创建配置文件
[root@ntpserver ~]# cp /etc/init.d/ntpd.bak /etc/init.d/ntpd [root@ntpserver ~]# cp /etc/sysconfig/ntpd.bak /etc/sysconfig/ntpd [root@ntpserver ~]# cp /etc/sysconfig/ntpdate.bak /etc/sysconfig/ntpdate [root@ntpserver ~]# mv /etc/ntp.bak /etc/ntp [root@ntpserver ~]# cp /etc/ntp.conf.bak /etc/ntp.conf |
执行service ntpd status
如果ntpd.service找不到 可在/usr/lib/systemd/system/下创建
创建成功后 执行
chmod +x xx.service
systemctl daemon-reload
授权服务和重载服务