ntp 源码编译

参考:https://www.huaweicloud.com/articles/f1b65a818968bf258d015a9923655a29.html

  1. 卸载原包
rpm -qa | grep ntp
> ntp-xxx
yum erase ntp-xxx
  1. 下载源码包并解压
wget https://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.8p15.tar.gz
tar zxvf ntp-4.2.8p15.tar.gz
  1. 然后编译、安装
./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

cd ntp-4.2.8p15
make && make install
  1. 设置配置信息
cp /usr/local/ntp/sbin/* /usr/local/sbin/
  1. 设置服务
cd /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
  1. 启动
systemctl start ntpd
systemctl enable ntpd
  1. 请求命令

netstat -anpt // 服务查询
ntpdate server_ip // 更新时间
nc -vuz server_ip 123 // udp 端口
telnet server_ip 123 // tcp 端口

你可能感兴趣的:(ntp 源码编译)