[[email protected] ~]# ls -lh /var/lib/rpm/ total 35M -rw-r--r-- 1 root root 4.8M Jan 15 14:09 Basenames -rw-r--r-- 1 root root 12K Jan 15 14:08 Conflictname -rw-r--r-- 1 root root 0 Jan 15 14:02 __db.000 -rw-r--r-- 1 root root 24K Jan 15 14:00 __db.001 -rw-r--r-- 1 root root 1.3M Jan 15 14:00 __db.002 -rw-r--r-- 1 root root 440K Jan 15 14:00 __db.003 -rw-r--r-- 1 root root 1.1M Jan 15 14:09 Dirnames -rw-r--r-- 1 root root 5.1M Jan 15 14:09 Filemd5s -rw-r--r-- 1 root root 12K Jan 15 14:09 Group -rw-r--r-- 1 root root 16K Jan 15 14:09 Installtid -rw-r--r-- 1 root root 40K Jan 15 14:09 Name -rw-r--r-- 1 root root 24M Jan 15 14:09 Packages -rw-r--r-- 1 root root 168K Jan 15 14:09 Providename -rw-r--r-- 1 root root 76K Jan 15 14:09 Provideversion -rw-r--r-- 1 root root 12K Feb 2 2012 Pubkeys -rw-r--r-- 1 root root 232K Jan 15 14:09 Requirename -rw-r--r-- 1 root root 156K Jan 15 14:09 Requireversion -rw-r--r-- 1 root root 84K Jan 15 14:09 Sha1header -rw-r--r-- 1 root root 44K Jan 15 14:09 Sigmd5 -rw-r--r-- 1 root root 12K Jan 15 14:02 Triggername其中,__db.001类的文件是RPM用于软件包管理时的锁文件,余下的其它文件通常为Berkeley DB格式的文件,其中最重要的是Packages,其包含了当前系统已经安装的所有RPM包的首部标签信息。其它文件如Name,Providename和Group等通常是为提高访问效率的,一旦损坏,它们都可以使用rpm命令的--rebuild进行重建。
# rpm2cpio ngnix-1.0.14-1.el5.i386.rpm | cpio -t # rpm2cpio ngnix-1.0.14-1.el5.i386.rpm | cpio -id
[[email protected] ~]# rpm -q --requires httpd /bin/bash /bin/mktemp /bin/mv /bin/rm /bin/sh /bin/sh /bin/sh /bin/sh /bin/sh /etc/mime.types /sbin/chkconfig /usr/bin/find /usr/sbin/useradd /usr/share/magic.mime config(httpd) = 2.2.3-31.el5 gawk initscripts >= 8.36 ... ... ... ...
[[email protected] ~]# rpm -q --provides httpd config(httpd) = 2.2.3-31.el5 httpd-mmn = 20051115 mod_actions.so mod_alias.so mod_asis.so mod_auth_basic.so mod_auth_digest.so ... ... ... ...
[[email protected] ~]# rpm -q --whatrequires initscripts portmap-4.0-65.2.2.1 foomatic-3.0.2-38.3.el5 kbd-1.12-21.el5 dhclient-3.0.5-21.el5 ... ... ... ...
五、创建RPM包快速实现步骤
[[email protected] ~]# rpm2cpio nginx-1.0.14-1.i386.rpm | cpio -t ./etc/logrotate.d/nginx ./etc/nginx ./etc/nginx/fastcgi.conf ./etc/nginx/fastcgi.conf.default ./etc/nginx/fastcgi_params ./etc/nginx/fastcgi_params.default ./etc/nginx/koi-utf ./etc/nginx/koi-win ./etc/nginx/mime.types ./etc/nginx/mime.types.default ./etc/nginx/nginx.conf ./etc/nginx/nginx.conf.default ./etc/nginx/scgi_params ./etc/nginx/scgi_params.default ./etc/nginx/uwsgi_params ./etc/nginx/uwsgi_params.default ./etc/nginx/win-utf ./etc/rc.d/init.d/nginx ./usr/html/50x.html ./usr/html/index.html ./usr/sbin/nginx ./usr/share/doc/nginx-1.0.14 ./usr/share/doc/nginx-1.0.14/CHANGES ./usr/share/doc/nginx-1.0.14/LICENSE ./usr/share/doc/nginx-1.0.14/README
[[email protected] ~]$ rpmbuild --showrc |grep _usr -14: _defaultdocdir %{_usr}/share/doc -14: _topdir %{_usrsrc}/redhat -14: _usr /usr -14: _usrsrc %{_usr}/src
[[email protected] ~]$ rpmbuild --showrc |grep _topdir -14: _builddir %{_topdir}/BUILD -14: _rpmdir %{_topdir}/RPMS -14: _sourcedir %{_topdir}/SOURCES -14: _specdir %{_topdir}/SPECS -14: _srcrpmdir %{_topdir}/SRPMS -14: _topdir %{_usrsrc}/redhat
[[email protected] ~]$ rpmbuild --showrc | grep "_topdir" -14: _builddir %{_topdir}/BUILD -14: _rpmdir %{_topdir}/RPMS -14: _sourcedir %{_topdir}/SOURCES -14: _specdir %{_topdir}/SPECS -14: _srcrpmdir %{_topdir}/SRPMS -14: _topdir /home/mage/rpmworkshop 或者: [[email protected] ~]$ rpm --eval '%_topdir' /home/mage/rpmworkshop
Name: Version: Release: 1%{?dist} Summary: Group: License: URL: pagkager: magedu.com <[email protected]> Vendor: http://www.magedu.com/ Source0: BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX BuildRequires: Requires: %description %prep %setup -q %build %configure make %{?_smp_mflags} %install rm -rf $RPM_BUILD_ROOT make install DESTDIR=$RPM_BUILD_ROOT %clean rm -rf $RPM_BUILD_ROOT #%pre #%post #%preun #%postun %files %defattr(-,root,root,-) %doc %changelog
#!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config: /etc/nginx/nginx.conf # config: /etc/sysconfig/nginx # pidfile: /var/run/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/etc/nginx/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx make_dirs() { # make required directories user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -` options=`$nginx -V 2>&1 | grep 'configure arguments:'` for opt in $options; do if [ `echo $opt | grep '.*-temp-path'` ]; then value=`echo $opt | cut -d "=" -f 2` if [ ! -d "$value" ]; then # echo "creating" $value mkdir -p $value && chown -R $user $value fi fi done } start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 make_dirs echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { configtest || return $? stop sleep 1 start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac #END Of nginx.init接下来在%{_topdir}/SPECS目录中创建nginx.spec文件,其内容如下:
Name: nginx Version: 1.0.14 Release: 1%{?dist} Summary: A free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. Group: System Environment/Daemons Vendor: http://www.magedu.com Packager: mage <[email protected]> License: BSD URL: http://www.nginx.org/ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root BuildRequires: pcre-devel,zlib-devel,openssl-devel BuildRequires: libxslt-devel,gd-devel Requires: pcre,openssl,gd # for /usr/sbin/useradd Requires(pre): shadow-utils Requires(post): chkconfig # for /sbin/service Requires(preun): chkconfig, initscripts Requires(postun): initscripts Provides: webserver Source0: http://sysoev.ru/nginx/nginx-%{version}.tar.gz Source1: nginx.init %description Nginx is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. Igor Sysoev started development of Nginx in 2002, with the first public release in 2004. Nginx now hosts nearly 12.18% (22.2M) of active sites across all domains. Nginx is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption. %prep %setup -q %build export DESTDIR=%{buildroot} ./configure \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_flv_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/tmp/nginx/client/ \ --http-proxy-temp-path=/var/tmp/nginx/proxy/ \ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \ --with-pcre make %{?_smp_mflags} %install rm -rf %{buildroot} make install DESTDIR=%{buildroot} %{__install} -p -D -m 0755 %{SOURCE1} %{buildroot}%{_initrddir}/%{name} %{__install} -p -d -m 0755 %{buildroot}/var/run/nginx %{__install} -p -d -m 0755 %{buildroot}/log/run/nginx %clean rm -rf %{buildroot} %pre if [ $1 == 1 ]; then /usr/sbin/useradd -s /bin/false -r nginx 2>/dev/null || : fi %post if [ $1 == 1 ]; then /sbin/chkconfig --add %{name} fi %preun if [ $1 = 0 ]; then /sbin/service %{name} stop >/dev/null 2>&1 /sbin/chkconfig --del %{name} fi %files %defattr(-,root,root,-) %doc LICENSE CHANGES README %{_sbindir}/%{name} %dir /var/run/nginx %dir /var/log/nginx %dir /etc/nginx %config(noreplace) /etc/nginx/win-utf %config(noreplace) /etc/nginx/mime.types.default %config(noreplace) /etc/nginx/fastcgi.conf %config(noreplace) /etc/nginx/fastcgi.conf.default %config(noreplace) /etc/nginx/fastcgi_params %config(noreplace) /etc/nginx/fastcgi_params.default %config(noreplace) /etc/nginx/%{name}.conf %config(noreplace) /etc/nginx/mime.types %config(noreplace) /etc/nginx/scgi_params %config(noreplace) /etc/nginx/scgi_params.default %config(noreplace) /etc/nginx/uwsgi_params %config(noreplace) /etc/nginx/uwsgi_params.default %config(noreplace) /etc/nginx/koi-win %config(noreplace) /etc/nginx/koi-utf %config(noreplace) /etc/nginx/%{name}.conf.default /usr/local/nginx/html/50x.html /usr/local/nginx/html/index.html %attr(0755, root, root) %{_initrddir}/%{name} %changelog * Wed Apr 11 2012 magedu.com <[email protected]> - 1.0.14-1 - Initial version # End Of nginx.spec
[[email protected] SPECS]$ rpmbuild --nobuild nginx.spec error: Failed build dependencies: pcre-devel is needed by nginx-1.0.14-1.i386 gd-devel is needed by nginx-1.0.14-1.i386
[[email protected] SPECS]$ rpmbuild -bp nginx.spec Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.72469 + umask 022 + cd /home/mage/rpmworkshop/BUILD + LANG=C + export LANG + unset DISPLAY + cd /home/mage/rpmworkshop/BUILD + rm -rf nginx-1.0.14 + /usr/bin/gzip -dc /home/mage/rpmworkshop/SOURCES/nginx-1.0.14.tar.gz + tar -xf - + STATUS=0 + '[' 0 -ne 0 ']' + cd nginx-1.0.14 ++ /usr/bin/id -u + '[' 502 = 0 ']' ++ /usr/bin/id -u + '[' 502 = 0 ']' + /bin/chmod -Rf a+rX,u+w,g-w,o-w . + exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.46906 + umask 022 + cd /home/mage/rpmworkshop/BUILD + cd nginx-1.0.14 + LANG=C + export LANG + unset DISPLAY + export DESTDIR=/var/tmp/nginx-1.0.14-1-root + DESTDIR=/var/tmp/nginx-1.0.14-1-root + ./configure --sbin-path=/usr/sbin/nginx '--conf-path=%{nginx_confdir}/nginx.conf' --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --with-pcre checking for OS ... ... ... ...# (省略输出内容若干行)
Wrote: /home/mage/rpmworkshop/SRPMS/nginx-1.0.14-1.src.rpm Wrote: /home/mage/rpmworkshop/RPMS/i386/nginx-1.0.14-1.i386.rpm Wrote: /home/mage/rpmworkshop/RPMS/i386/nginx-debuginfo-1.0.14-1.i386.rpm Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.33201 + umask 022 + cd /home/mage/rpmworkshop/BUILD + cd nginx-1.0.14 + rm -rf /var/tmp/nginx-1.0.14-1-root + exit 0
[[email protected] ~]$ rpm -qpi ~/rpmworkshop/RPMS/i386/nginx-1.0.14-1.i386.rpm Name : nginx Relocations: (not relocatable) Version : 1.0.14 Vendor: http://www.magedu.com Release : 1 Build Date: Wed 11 Apr 2012 05:01:14 PM CST Install Date: (not installed) Build Host: mail.magedu.com Group : System Environment/Daemons Source RPM: nginx-1.0.14-1.src.rpm Size : 705987 License: BSD Signature : (none) Packager : mage <[email protected]> URL : http://www.nginx.org/ Summary : A free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. Description : Nginx is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. Igor Sysoev started development of Nginx in 2002, with the first public release in 2004. Nginx now hosts nearly 12.18% (22.2M) of active sites across all domains. Nginx is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption.