Centos7编译安装ntp-4.2.8p11

Centos7编译安装ntp-4.2.8p11

背景

因公司做等保评级,在进行安全漏洞检测时发现ntp需要升级到ntp-4.2.7p25以上版本,经过一番搜索,没有该版本及新版本ntp的yum安装包,所以只能编译安装了,网上搜到两篇文章,但是参考价值一般,所以自己摸索爬坑,在此记录一下。

环境

  • 系统环境:Centos 7.2
  • ntpd版本:4.2.8p11

安装

下载安装包

# 官方下载
$ wget http://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=/usr/local/ntp --bindir=/usr/local/ntp/sbin --sysconfdir=/etc --libexecdir=/usr/local/ntp/libexec --docdir=/usr/local/ntp/doc/ntp --enable-linuxcaps  --with-lineeditlibs=readline  --enable-all-clocks --enable-parse-clocks --enable-clockctl --enable-ntpdate-step --enable-libopts-install   # 配置(查看使用指南--help)

# 报错1
"/usr/bin/ld: cannot find -lcap"
# fix
$ find / -name "*libcap.so*""
$ ln -sv /usr/lib64/libcap.so.2 /usr/lib/libcap.so


# 报错2
“ntpd.c:120:29: 致命错误:sys/capability.h:没有那个文件或目录”
# fix
$ yum install -y libcap-devel

$ make && make install   # 编译 && 安装
$ echo $?   # 检测安装过程是否出错,0表示没错

注意: 因本机系统环境已完成初始化部署,所以一些依赖包的安装省略,如果遇到缺少某些lib*查到情况,直接yum安装即可。

配置

安装完成后并没有配置文件生成,需手动创建,官方指定其默认配置文件为:/etc/ntp.conf

$ vim /etc/ntp.conf

driftfile /var/lib/ntp/drift  # 指定时间漂移记录文件,作用:如果ntpd停止并重新启动,它将从该文件初始化频率,并避免可能的长时间间隔重新学习校正。

# 指定remote ntp服务器
server 202.120.2.101  prefer iburst minpoll 4 maxpoll 6  
## prefer:优先使用
## minpoll && maxpoll:
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server 3.pool.ntp.org

statistics loopstats peerstats clockstats

filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable


restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery
restrict 127.0.0.1
restrict 10.9.255.1
restrict 10.9.255.2
restrict ::1

启动ntpd

  • 将ntp相关命令加入系统环境变量:

    cp /usr/local/ntp/sbin/*  /usr/lcoal/sbin
    
  • 将ntpd服务加入系统管理:

    $ systemctl cat ntpd.service
    # /usr/lib/systemd/system/ntpd.service
    [Unit]
    Description=Network Time Service
    After=syslog.target
    
    [Service]
    Type=forking
    EnvironmentFile=-/etc/sysconfig/ntpd
    ExecStart=/usr/local/sbin/ntpd -u ntp:ntp $OPTIONS
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target
    
    
    $ systemctl enable ntpd  # 加入开机启动
    $ systemctl start/stop/status/restart ntpd
    

Finished(踩坑很多,本次最大的坑为--enable-ipv6相关,如果你在安装过程中也遇到了make无法通过的问题,直接pass该参数吧,具体原因还烦路过的大神多多指教)!!!

参考

转载于:https://my.oschina.net/adailinux/blog/1861001

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值