Chinaunix首页 | 论坛 | 博客
  • 博客访问: 221748
  • 博文数量: 16
  • 博客积分: 366
  • 博客等级: 一等列兵
  • 技术积分: 268
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-07 11:53
文章分类

全部博文(16)

文章存档

2016年(1)

2015年(2)

2014年(4)

2013年(1)

2012年(5)

2011年(3)

我的朋友

分类: LINUX

2016-12-19 13:29:59


一、安装工具包

安装rpmbuild包,rpmdev-toolsgcc

挂载安装镜像,进入Packages目录

rpm -ivh rpm-build-4.8.0-32.el6.x86_64.rpm

rpm -ivh rpmdevtools-7.5-2.el6.noarch.rpm


二、建立相关目录和模板文件

mkdir -p /root/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}

cd /root/rpmbuild/SPECS/

rpmdev-newspec ntp //该命令会生成一个ntp.spec的最小模板,然后我们根据这个模板进行修改


为了方便每次重新编译前清理目录,我做了个小脚本

#cat clean.sh

rm -rf /root/rpmbuild/BUILD/ntp-4.2.8p9

rm -rf /root/rpmbuild/BUILDROOT/ntp-4.2.8p9-1.el6.x86_64/usr

rm -f /root/rpmbuild/BUILDROOT/RPMS/x86_64/ntp-4.2.8p9-1.el6.x86_64.rpm

rm -f root/rpmbuild/BUILDROOT/SRPMS/ntp-4.2.8p9-1.el6.src.rpm



三、编辑ntp.spec文件

关于该文件的具体参数解释请查看该参考址:

-------------------------------------------------------------------------------------------------

Name: ntp

Version: 4.2.8p9

Release: 1%{?dist}

Summary: compiled from 4.2.8p9 by yunhw


Group: System Environment/Daemons

License: GPL

Source0: ntp-4.2.8p9.tar.gz

BuildRoot: %_topdir/BUILDROOT


BuildRequires: gcc

Requires: rpm


%description



%prep

%setup -q


%build

%configure

./configure --prefix=/usr

make %{?_smp_mflags}



%install

#rm -rf %{buildroot} 这里之所以注释是为了在/root/rpmbuild/BUILDROOT/ntp-4.2.8p9-1.el6.x86_64目录下能放一些自己的文件,这就需要每次重新编译之前,手动删除这个目录的不用的文件

make install DESTDIR=%{buildroot}


%clean

#rm -rf %{buildroot} 这里之所以注释是为了在/root/rpmbuild/BUILDROOT/ntp-4.2.8p9-1.el6.x86_64目录下能放一些自己的文件,这就需要每次重新编译之前,手动删除这个目录的不用的文件



%files

%defattr(-,root,root,-)

/usr/

/etc/

/var

%exclude /usr/sbin/ntpdate


%changelog


%pre

#/bin/bash

if [ -f /etc/ntp.conf ]

then

cp /etc/ntp.conf /etc/ntp.conf.bak

fi



%post

chkconfig --add ntpd

chkconfig ntpd on


%preun

if [ -f /etc/ntp.conf ]

then

cp /etc/ntp.conf /etc/ntp.conf.bak

fi

---------------------------------------------------------------------------------------------------

四、编译前文件准备

在安装镜像中找到该本的ntp包,拷贝至一个目录,然后使用rpm2cpio ntp*|cpio -idmv命令把其中的文件解压出来,将其中的/var/etc目录拷贝至/root/rpmbuild/BUILDROOT/ntp-4.2.8p9-1.el6.x86_64/ 中,这样/etc//var/就会被打包进去了,因为我发现使用源码编译只会在/usr中生成安装文件,至于/etc下的相关配置文件和脚本则没有。


五、编译生成

rpmbuild -bb ntp.spec

生成的rpm文件在/root/rpmbuild/RPMS/x86_64



六、注意事项

1、这是在redhat6.4 x86_64上编译的,如果你要在更高的系统版本上用,请先做个测试,然后再装

2、如果系统里已经安装了ntp的包,那么安装方法是rpm -Uvh ntp***,没有安装的话,安装方法是rpm -ivh ntp***

3、以前用源码直接编译升级过ntp的请注意先把源码安装的文件删除了,再安装。

4、如果在执行service ntpd restart时报如下错误:

---------------------------------------------------------------------------------------------------

[root@hxgz01 sbin]# service ntpd start

Starting ntpd: /usr/sbin/ntpd: The 'user' option has been disabled. -- built without --enable-clockctl or --enable-linuxcaps or --enable-solarisprivs

ntpd - NTP daemon program - Ver. 4.2.8p8

Usage: ntpd [ - [] | --[{=| }] ]... \

[ ... ]

Try 'ntpd --help' for more information.

[FAILED]

-------------------------------------------------------------------------------------------

请将安装/etc/sysconfig/ntpd文件OPTIIONS行中的-u ntp:ntp 删掉再试试,最终解决办法是安装linuxcaps,并在重新编译时增加--enable-linuxcaps选项。

-----------------------------------------------------------------------------------

-----------------------------------------------------------------------------------
cd ~/install/ntp-dev-4.2.7p475 # or wherever you have the source unpacked make clean # clean out the previous build sudo apt-get install libcap-dev # this library is required by linuxcaps ./configure --enable-linuxcaps # this is the critical switch make sudo make install sudo /etc/init.d/ntp restart # restart ntp ntpq -c "rv 0 version" # make sure you are running the right version
---------------------------------------------------------------------------------------

5、执行ntpq -p时提示如下:

[root@Linux-App-Templet dhclient.d]# ntpq -p

No association ID's returned

这时因为原来的配置文件被备份为/etc/ntp.conf.bak,而新的配置文件里则没有配置ntp同步的server,配置后即可。


6、rpm包含的文件列表

./etc

./etc/dhcp

./etc/dhcp/dhclient.d

./etc/dhcp/dhclient.d/ntp.sh

./etc/ntp

./etc/ntp.conf

./etc/ntp/crypto

./etc/ntp/crypto/pw

./etc/rc.d

./etc/rc.d/init.d

./etc/rc.d/init.d/ntpd

./etc/sysconfig

./etc/sysconfig/ntpd

./usr

./usr/bin

./usr/libexec

./usr/sbin

./usr/sbin/calc_tickadj

./usr/sbin/ntp-keygen

./usr/sbin/ntp-wait

./usr/sbin/ntpd

./usr/sbin/ntpdc

./usr/sbin/ntpq

./usr/sbin/ntptime

./usr/sbin/ntptrace

./usr/sbin/sntp

./usr/sbin/tickadj

./usr/share

./usr/share/doc

./usr/share/doc/ntp

./usr/share/doc/ntp/html

./usr/share/doc/ntp/html/access.html

./usr/share/doc/ntp/html/accopt.html

./usr/share/doc/ntp/html/assoc.html

./usr/share/doc/ntp/html/audio.html

./usr/share/doc/ntp/html/authentic.html

./usr/share/doc/ntp/html/authopt.html

./usr/share/doc/ntp/html/autokey.html

./usr/share/doc/ntp/html/bugs.html

./usr/share/doc/ntp/html/build.html

./usr/share/doc/ntp/html/clock.html

./usr/share/doc/ntp/html/clockopt.html

./usr/share/doc/ntp/html/cluster.html

./usr/share/doc/ntp/html/comdex.html

./usr/share/doc/ntp/html/config.html

./usr/share/doc/ntp/html/confopt.html

./usr/share/doc/ntp/html/copyright.html

./usr/share/doc/ntp/html/debug.html

./usr/share/doc/ntp/html/decode.html

./usr/share/doc/ntp/html/discipline.html

./usr/share/doc/ntp/html/discover.html

./usr/share/doc/ntp/html/drivers

./usr/share/doc/ntp/html/drivers/driver1.html

./usr/share/doc/ntp/html/drivers/driver10.html

./usr/share/doc/ntp/html/drivers/driver11.html

./usr/share/doc/ntp/html/drivers/driver12.html

./usr/share/doc/ntp/html/drivers/driver16.html

./usr/share/doc/ntp/html/drivers/driver18.html

./usr/share/doc/ntp/html/drivers/driver19.html

./usr/share/doc/ntp/html/drivers/driver20.html

./usr/share/doc/ntp/html/drivers/driver22.html

./usr/share/doc/ntp/html/drivers/driver26.html

./usr/share/doc/ntp/html/drivers/driver27.html

./usr/share/doc/ntp/html/drivers/driver28.html

./usr/share/doc/ntp/html/drivers/driver29.html

./usr/share/doc/ntp/html/drivers/driver3.html

./usr/share/doc/ntp/html/drivers/driver30.html

./usr/share/doc/ntp/html/drivers/driver31.html

./usr/share/doc/ntp/html/drivers/driver32.html

./usr/share/doc/ntp/html/drivers/driver33.html

./usr/share/doc/ntp/html/drivers/driver34.html

./usr/share/doc/ntp/html/drivers/driver35.html

./usr/share/doc/ntp/html/drivers/driver36.html

./usr/share/doc/ntp/html/drivers/driver37.html

./usr/share/doc/ntp/html/drivers/driver38.html

./usr/share/doc/ntp/html/drivers/driver39.html

./usr/share/doc/ntp/html/drivers/driver4.html

./usr/share/doc/ntp/html/drivers/driver40-ja.html

./usr/share/doc/ntp/html/drivers/driver40.html

./usr/share/doc/ntp/html/drivers/driver42.html

./usr/share/doc/ntp/html/drivers/driver43.html

./usr/share/doc/ntp/html/drivers/driver44.html

./usr/share/doc/ntp/html/drivers/driver45.html

./usr/share/doc/ntp/html/drivers/driver46.html

./usr/share/doc/ntp/html/drivers/driver5.html

./usr/share/doc/ntp/html/drivers/driver6.html

./usr/share/doc/ntp/html/drivers/driver7.html

./usr/share/doc/ntp/html/drivers/driver8.html

./usr/share/doc/ntp/html/drivers/driver9.html

./usr/share/doc/ntp/html/drivers/icons

./usr/share/doc/ntp/html/drivers/icons/home.gif

./usr/share/doc/ntp/html/drivers/icons/mail2.gif

./usr/share/doc/ntp/html/drivers/mx4200data.html

./usr/share/doc/ntp/html/drivers/oncore-shmem.html

./usr/share/doc/ntp/html/drivers/scripts

./usr/share/doc/ntp/html/drivers/scripts/footer.txt

./usr/share/doc/ntp/html/drivers/scripts/style.css

./usr/share/doc/ntp/html/drivers/tf582_4.html

./usr/share/doc/ntp/html/extern.html

./usr/share/doc/ntp/html/filter.html

./usr/share/doc/ntp/html/hints

./usr/share/doc/ntp/html/hints.html

./usr/share/doc/ntp/html/hints/a-ux

./usr/share/doc/ntp/html/hints/aix

./usr/share/doc/ntp/html/hints/bsdi

./usr/share/doc/ntp/html/hints/changes

./usr/share/doc/ntp/html/hints/decosf1

./usr/share/doc/ntp/html/hints/decosf2

./usr/share/doc/ntp/html/hints/freebsd

./usr/share/doc/ntp/html/hints/hpux

./usr/share/doc/ntp/html/hints/linux

./usr/share/doc/ntp/html/hints/mpeix

./usr/share/doc/ntp/html/hints/notes-xntp-v3

./usr/share/doc/ntp/html/hints/parse

./usr/share/doc/ntp/html/hints/refclocks

./usr/share/doc/ntp/html/hints/rs6000

./usr/share/doc/ntp/html/hints/sco.html

./usr/share/doc/ntp/html/hints/sgi

./usr/share/doc/ntp/html/hints/solaris-dosynctodr.html

./usr/share/doc/ntp/html/hints/solaris.html

./usr/share/doc/ntp/html/hints/solaris.xtra.4023118

./usr/share/doc/ntp/html/hints/solaris.xtra.4095849

./usr/share/doc/ntp/html/hints/solaris.xtra.S99ntpd

./usr/share/doc/ntp/html/hints/solaris.xtra.patchfreq

./usr/share/doc/ntp/html/hints/sun4

./usr/share/doc/ntp/html/hints/svr4-dell

./usr/share/doc/ntp/html/hints/svr4_package

./usr/share/doc/ntp/html/hints/todo

./usr/share/doc/ntp/html/hints/vxworks.html

./usr/share/doc/ntp/html/hints/winnt.html

./usr/share/doc/ntp/html/history.html

./usr/share/doc/ntp/html/howto.html

./usr/share/doc/ntp/html/huffpuff.html

./usr/share/doc/ntp/html/icons

./usr/share/doc/ntp/html/icons/home.gif

./usr/share/doc/ntp/html/icons/mail2.gif

./usr/share/doc/ntp/html/icons/sitemap.png

./usr/share/doc/ntp/html/index.html

./usr/share/doc/ntp/html/kern.html

./usr/share/doc/ntp/html/kernpps.html

./usr/share/doc/ntp/html/keygen.html

./usr/share/doc/ntp/html/leap.html

./usr/share/doc/ntp/html/miscopt.html

./usr/share/doc/ntp/html/monopt.html

./usr/share/doc/ntp/html/msyslog.html

./usr/share/doc/ntp/html/ntp-wait.html

./usr/share/doc/ntp/html/ntp_conf.html

./usr/share/doc/ntp/html/ntpd.html

./usr/share/doc/ntp/html/ntpdate.html

./usr/share/doc/ntp/html/ntpdc.html

./usr/share/doc/ntp/html/ntpdsim.html

./usr/share/doc/ntp/html/ntpdsim_new.html

./usr/share/doc/ntp/html/ntpq.html

./usr/share/doc/ntp/html/ntptime.html

./usr/share/doc/ntp/html/ntptrace.html

./usr/share/doc/ntp/html/orphan.html

./usr/share/doc/ntp/html/parsedata.html

./usr/share/doc/ntp/html/parsenew.html

./usr/share/doc/ntp/html/pic

./usr/share/doc/ntp/html/pic/9400n.jpg

./usr/share/doc/ntp/html/pic/alice11.gif

./usr/share/doc/ntp/html/pic/alice13.gif

./usr/share/doc/ntp/html/pic/alice15.gif

./usr/share/doc/ntp/html/pic/alice23.gif

./usr/share/doc/ntp/html/pic/alice31.gif

./usr/share/doc/ntp/html/pic/alice32.gif

./usr/share/doc/ntp/html/pic/alice35.gif

./usr/share/doc/ntp/html/pic/alice38.gif

./usr/share/doc/ntp/html/pic/alice44.gif

./usr/share/doc/ntp/html/pic/alice47.gif

./usr/share/doc/ntp/html/pic/alice51.gif

./usr/share/doc/ntp/html/pic/alice61.gif

./usr/share/doc/ntp/html/pic/barnstable.gif

./usr/share/doc/ntp/html/pic/beaver.gif

./usr/share/doc/ntp/html/pic/boom3.gif

./usr/share/doc/ntp/html/pic/boom3a.gif

./usr/share/doc/ntp/html/pic/boom4.gif

./usr/share/doc/ntp/html/pic/broad.gif

./usr/share/doc/ntp/html/pic/bustardfly.gif

./usr/share/doc/ntp/html/pic/c51.jpg

./usr/share/doc/ntp/html/pic/description.jpg

./usr/share/doc/ntp/html/pic/discipline.gif

./usr/share/doc/ntp/html/pic/dogsnake.gif

./usr/share/doc/ntp/html/pic/driver29.gif

./usr/share/doc/ntp/html/pic/driver43_1.gif

./usr/share/doc/ntp/html/pic/driver43_2.jpg

./usr/share/doc/ntp/html/pic/fg6021.gif

./usr/share/doc/ntp/html/pic/fg6039.jpg

./usr/share/doc/ntp/html/pic/fig_3_1.gif

./usr/share/doc/ntp/html/pic/flatheads.gif

./usr/share/doc/ntp/html/pic/flt1.gif

./usr/share/doc/ntp/html/pic/flt2.gif

./usr/share/doc/ntp/html/pic/flt3.gif

./usr/share/doc/ntp/html/pic/flt4.gif

./usr/share/doc/ntp/html/pic/flt5.gif

./usr/share/doc/ntp/html/pic/flt6.gif

./usr/share/doc/ntp/html/pic/flt7.gif

./usr/share/doc/ntp/html/pic/flt8.gif

./usr/share/doc/ntp/html/pic/flt9.gif

./usr/share/doc/ntp/html/pic/freq1211.gif

./usr/share/doc/ntp/html/pic/gadget.jpg

./usr/share/doc/ntp/html/pic/gps167.jpg

./usr/share/doc/ntp/html/pic/group.gif

./usr/share/doc/ntp/html/pic/hornraba.gif

./usr/share/doc/ntp/html/pic/igclock.gif

./usr/share/doc/ntp/html/pic/neoclock4x.gif

./usr/share/doc/ntp/html/pic/offset1211.gif

./usr/share/doc/ntp/html/pic/oncore_evalbig.gif

./usr/share/doc/ntp/html/pic/oncore_remoteant.jpg

./usr/share/doc/ntp/html/pic/oncore_utplusbig.gif

./usr/share/doc/ntp/html/pic/oz2.gif

./usr/share/doc/ntp/html/pic/panda.gif

./usr/share/doc/ntp/html/pic/pd_om006.gif

./usr/share/doc/ntp/html/pic/pd_om011.gif

./usr/share/doc/ntp/html/pic/peer.gif

./usr/share/doc/ntp/html/pic/pogo.gif

./usr/share/doc/ntp/html/pic/pogo1a.gif

./usr/share/doc/ntp/html/pic/pogo3a.gif

./usr/share/doc/ntp/html/pic/pogo4.gif

./usr/share/doc/ntp/html/pic/pogo5.gif

./usr/share/doc/ntp/html/pic/pogo6.gif

./usr/share/doc/ntp/html/pic/pogo7.gif

./usr/share/doc/ntp/html/pic/pogo8.gif

./usr/share/doc/ntp/html/pic/pzf509.jpg

./usr/share/doc/ntp/html/pic/pzf511.jpg

./usr/share/doc/ntp/html/pic/rabbit.gif

./usr/share/doc/ntp/html/pic/radio2.jpg

./usr/share/doc/ntp/html/pic/sheepb.jpg

./usr/share/doc/ntp/html/pic/stack1a.jpg

./usr/share/doc/ntp/html/pic/stats.gif

./usr/share/doc/ntp/html/pic/sx5.gif

./usr/share/doc/ntp/html/pic/thunderbolt.jpg

./usr/share/doc/ntp/html/pic/time1.gif

./usr/share/doc/ntp/html/pic/tonea.gif

./usr/share/doc/ntp/html/pic/tribeb.gif

./usr/share/doc/ntp/html/pic/wingdorothy.gif

./usr/share/doc/ntp/html/poll.html

./usr/share/doc/ntp/html/pps.html

./usr/share/doc/ntp/html/prefer.html

./usr/share/doc/ntp/html/quick.html

./usr/share/doc/ntp/html/rate.html

./usr/share/doc/ntp/html/rdebug.html

./usr/share/doc/ntp/html/refclock.html

./usr/share/doc/ntp/html/release.html

./usr/share/doc/ntp/html/scripts

./usr/share/doc/ntp/html/scripts/accopt.txt

./usr/share/doc/ntp/html/scripts/audio.txt

./usr/share/doc/ntp/html/scripts/authopt.txt

./usr/share/doc/ntp/html/scripts/clockopt.txt

./usr/share/doc/ntp/html/scripts/command.txt

./usr/share/doc/ntp/html/scripts/config.txt

./usr/share/doc/ntp/html/scripts/confopt.txt

./usr/share/doc/ntp/html/scripts/external.txt

./usr/share/doc/ntp/html/scripts/footer.txt

./usr/share/doc/ntp/html/scripts/hand.txt

./usr/share/doc/ntp/html/scripts/install.txt

./usr/share/doc/ntp/html/scripts/manual.txt

./usr/share/doc/ntp/html/scripts/misc.txt

./usr/share/doc/ntp/html/scripts/miscopt.txt

./usr/share/doc/ntp/html/scripts/monopt.txt

./usr/share/doc/ntp/html/scripts/refclock.txt

./usr/share/doc/ntp/html/scripts/special.txt

./usr/share/doc/ntp/html/scripts/style.css

./usr/share/doc/ntp/html/select.html

./usr/share/doc/ntp/html/sitemap.html

./usr/share/doc/ntp/html/sntp.html

./usr/share/doc/ntp/html/stats.html

./usr/share/doc/ntp/html/tickadj.html

./usr/share/doc/ntp/html/warp.html

./usr/share/doc/ntp/html/xleave.html

./usr/share/doc/ntp/ntp-keygen.html

./usr/share/doc/ntp/ntp-wait.html

./usr/share/doc/ntp/ntp.conf.html

./usr/share/doc/ntp/ntp.keys.html

./usr/share/doc/ntp/ntpd.html

./usr/share/doc/ntp/ntpdc.html

./usr/share/doc/ntp/ntpq.html

./usr/share/doc/ntp/ntpsnmpd.html

./usr/share/doc/ntp/ntpsweep.html

./usr/share/doc/ntp/ntptrace.html

./usr/share/doc/ntp/update-leap.html

./usr/share/doc/sntp

./usr/share/doc/sntp/sntp.html

./usr/share/man

./usr/share/man/man1

./usr/share/man/man5

./usr/share/man/man5/ntp.conf.5.gz

./usr/share/man/man5/ntp.keys.5.gz

./usr/share/man/man8

./usr/share/man/man8/calc_tickadj.8.gz

./usr/share/man/man8/ntp-keygen.8.gz

./usr/share/man/man8/ntp-wait.8.gz

./usr/share/man/man8/ntpd.8.gz

./usr/share/man/man8/ntpdc.8.gz

./usr/share/man/man8/ntpq.8.gz

./usr/share/man/man8/ntptrace.8.gz

./usr/share/man/man8/sntp.8.gz

./usr/share/ntp

./usr/share/ntp/lib

./usr/share/ntp/lib/NTP

./usr/share/ntp/lib/NTP/Util.pm

./var

./var/lib

./var/lib/ntp

./var/log

./var/log/ntpstats

七、相关参考链接

http://nmshuishui.blog.51cto.com/1850554/1583117



 

阅读(4203) | 评论(1) | 转发(0) |
0

上一篇:AIX6.1版本升级时提示 BUILDDATE requisite failure

下一篇:没有了

给主人留下些什么吧!~~

jpcgo2017-08-03 16:49:40

你好,我用您的方法打包的时候一直提示没有 etc var 目录。拷贝过的,但是发现在rpmbuild 过程中 两个目录都被删了,只有 usr 目录留下来