升级ntpd到4.2.8p17,ntp编译报recompile with -fPIC错误解决

背景

低版本的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
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
海思移植ntpd的步骤大致如下: 1. 获取ntpd源代码:可以从ntp.org下载ntpd源代码,并解压缩到本地目录。 2. 配置交叉编译环境:使用海思提供的交叉编译工具链,配置交叉编译环境。 3. 修改Makefile文件:进入ntpd源代码目录,修改Makefile文件,将交叉编译工具链及其路径配置好。 4. 编译ntpd:执行make命令编译ntpd程序。 5. 将ntpd程序移植到目标设备:将编译好的ntpd程序通过网络或其他方式拷贝到目标设备中。 6. 配置ntpd服务:在目标设备上运行ntpd程序,并配置好ntpd服务,可以使用ntp.conf文件进行配置。 7. 启动ntpd服务:在目标设备上启动ntpd服务,可以使用systemctl命令或其他方式启动。 至于ntp步骤,可以参考下面的步骤: 1. 获取ntp源代码:可以从ntp.org下载ntp源代码,并解压缩到本地目录。 2. 配置交叉编译环境:使用海思提供的交叉编译工具链,配置交叉编译环境。 3. 修改Makefile文件:进入ntp源代码目录,修改Makefile文件,将交叉编译工具链及其路径配置好。 4. 编译ntp:执行make命令编译ntp程序。 5. 将ntp程序移植到目标设备:将编译好的ntp程序通过网络或其他方式拷贝到目标设备中。 6. 配置ntp服务:在目标设备上运行ntp程序,并配置好ntp服务,可以使用ntp.conf文件进行配置。 7. 启动ntp服务:在目标设备上启动ntp服务,可以使用systemctl命令或其他方式启动。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值