背景
低版本的ntp会有漏洞,需要升级到最新版本4.2.8p17
检查ntpd版本
/usr/sbin/ntpd --version
下载部署包
https://archive.ntp.org/ntp4/ntp-4.2/ntp-4.2.8p17.tar.gz
安装依赖包
每个文档的都不一样,这里索性都安装
yum install gcc gcc-c++ openssl-devel libstdc++* libcap* m4 autoconf libtool gcc gcc-c++ ncurses-devel cmake make gcc libcap libcap-devel glic-devel automake libevent*
备份原有配置文件
scp -r /etc/ntp /etc/ntp.bak
scp -r /etc/ntp.conf /etc/ntp.conf.bak
scp -r /etc/init.d/ntpd /etc/init.d/ntpd.bak
scp -r /etc/sysconfig/ntpd /etc/sysconfig/ntpd.bak
scp -r /etc/sysconfig/ntpdate /etc/sysconfig/ntpdate.bak
scp -r /usr/sbin/ntpd /usr/sbin/ntpd.bak
移除ntp
yum remove ntp ntpdate -y
解压安装包
tar -zxvf ntp-4.2.8p17.tar.gz
cd ntp-4.2.8p17/
install -v -m710 -o ntp -g ntp -d /var/lib/ntp
./configure --prefix=/usr --bindir=/usr/sbin --enable-all-clocks --enable-parse-clocks --docdir=/usr/share/doc/ntp-4.2.8p17 --enable-all-clocks --enable-parse-clocks --enable-clockctl CFLAGS="-fPIC"
make && make install
#注意此处CFLAGS=“-fPIC”,p15不需要这个参数,但是p17要有
否则会报下面错误
/usr/bin/ld: ./libevent/.libs/libevent_core.a(evutil.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: ./libevent/.libs/libevent_core.a(evutil_rand.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: ./libevent/.libs/libevent_core.a(log.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: ./libevent/.libs/libevent_core.a(select.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: ./libevent/.libs/libevent_core.a(poll.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: ./libevent/.libs/libevent_core.a(epoll.o): relocation R_X86_64_32S against `.rodata.epollops_changelist' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: ./libevent/.libs/libevent_core.a(signal.o): relocation R_X86_64_32 against `.bss.signals.6714' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: ./libevent/.libs/libevent_pthreads.a(evthread_pthread.o): relocation R_X86_64_PC32 against symbol `pthread_self@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
make[4]: *** [sntp] Error 1
make[4]: Leaving directory `/root/ntp-4.2.8p17/sntp'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/root/ntp-4.2.8p17/sntp'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/root/ntp-4.2.8p17/sntp'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/ntp-4.2.8p17'
生成systemd管理配置文件
cat > /usr/lib/systemd/system/ntpd.service << EOF
[Unit]
Description=Network Time Service
After=syslog.target ntpdate.service sntp.service
[Service]
Type=forking
EnvironmentFile=-/etc/sysconfig/ntpd
ExecStart=/usr/sbin/ntpd -u root:root \$OPTIONS
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
还原配置文件
scp -r /etc/sysconfig/ntpd.bak /etc/sysconfig/ntpd
scp -r /etc/sysconfig/ntpdate.bak /etc/sysconfig/ntpdate
scp -r /etc/ntp.bak /etc/ntp
scp -r /etc/ntp.conf.bak /etc/ntp.conf
启动服务
systemctl daemon-reload
systemctl restart ntpd
systemctl status ntpd
检查ntpd版本
/usr/sbin/ntpd --version
date