使用rpmbuild制作squid rpm包
时间:2017-02-01 23:07 来源:linux.it.net.cn 作者:IT
制作RPM包有很多好处,可以较快安装部署喜欢的配置,参数;对于大批量安装省时省力,是一件事半功倍的事。
制作RPM需要准备好源码包和spec文件,安装好依赖和编译工具,熟悉制作RPM包的几个目录。
制作rpm包目录说明:
BUILD解压的目录
BUILDROOT假定的安装目录(变量为$RPM_BUILD_ROOT或%{buildroot})
RPMS存放制作好的rpm包
SOURCES存放源码包
SPECS存放spec文件
SRPMS存放srpm包
这里制作squid的rpm包只需要将源码包放置到SOURCES中,再切换到SPEC目录中,运行
rpmbuild -ba squid.2.7.spec
在制作过程中需要注意的:
制作RPM包不能使用root用户,因为权限过大,操作错误会造成较大影响。
使用普通用户制作时,rpmbuild的宏定义可以在~/.rpmmacros中定义
在spec中使用自定义宏的方法 %define macro_name value
在spec中使用宏的方法是 %{macro_name}
在spec中注释用#,注释信息中不可用%
制作squid RPM包build过程时,出现的错误及解决
出现../include/squid_md5.h:27:2: error: #error Cannot find OpenSSL MD5 headers
解决:需要安装好openssl相关组件
yum install -y openssl*
出现rpmbuild: error: Installed (but unpackaged) file(s) found Solution
解决:需要在段files写全目录
%files%defattr(-,root,root,-)/path/to/dir//path/to/file/
squid源码包下载地址:http://www.squid-cache.org/Versions/v2/2.7/squid-2.7.STABLE5.tar.bz2
squid.2.7.spec内容
%define squid_user squid
#---RPM包信息
#描述信息
Summary: hupu web proxy and content serving.
#软件包名
Name: squid
#软件包版本
Version: 2.7.STABLE5
#rpm包的发行版本,RPM包制作者自己定义,第几次制作找个包就写几次。
Release: 3%{?dist}
#rpm包的下载地址,如果没有下载地址可以写成源码包的官方地址
URL: http://www.squid-cache.org/Versions/v2/2.7/squid-2.7.STABLE5.tar.bz2
#RPM包的密钥,可以去源码包找对应的密钥,涉及到版权信息。
License: Creative Commons Attribution Sharealike 2.5 License
#rpm包的所属组
Group: System Environment/Daemons
#指定rpm包的源文件,地址在_topdir/SOURCES
Source0: squid-2.7.STABLE5.tar.bz2
#Source1: squid.conf
#指定rpm包的虚拟目录,类似DNS的chroot
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
#取消自动添加依赖关系
AutoReq: no
#描述信息
%description
Squid is a fully-featured HTTP/1.0 proxy which is almost (but not quite - we're getting ther
e!) a fully-featured HTTP/1.1 proxy. Squid offers a rich access control, authorization and l
ogging environment to develop web proxy and content serving applications. Squid offers a ric
h set of traffic optimization options, most of which are enabled by default for simpler inst
81 lines yanked 1,1 Top
#rpm包的所属组
Group: System Environment/Daemons
#指定rpm包的源文件,地址在_topdir/SOURCES
Source0: squid-2.7.STABLE5.tar.bz2
#Source1: squid.conf
#指定rpm包的虚拟目录,类似DNS的chroot
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
#取消自动添加依赖关系
AutoReq: no
#描述信息
%description
Squid is a fully-featured HTTP/1.0 proxy which is almost (but not quite - we're getting ther
e!) a fully-featured HTTP/1.1 proxy. Squid offers a rich access control, authorization and l
ogging environment to develop web proxy and content serving applications. Squid offers a ric
h set of traffic optimization options, most of which are enabled by default for simpler inst
allation and high performance.
#准备安装,解压 cd等都这这里进行
#rpmbuild -bp
%prep
%setup -q
#编译信息
#rpmbuild -bc
%build
export DESTDIR=%{buildroot}
./configure --prefix=/usr/local/webserver/squid --enable-arp-acl --enable-snmp --enable-dlmalloc --with-pthreads --enable-epoll --enable-poll --disable-internal-dns --enable-stacktrace --enable-removal-policies=heap,lru --enable-delay-po
ols --enable-storeio=ufs,aufs,diskd,coss,null --enable-external-acl --with-large-files --enable-large-files --enable-async-io --enable-dl-malloc --enable-ssl --enable-auth=basic,digest,negotiate,ntlm --enable-icmp --enable-large-cache-fi
les
make %{?_smp_mflags}
#安装信息
%install
%{__rm} -rf %{buildroot}
make install DESTDIR=%{buildroot}
#%{__install} -p -D -m 0755 %{SOURCE1} %{buildroot}/usr/local/webserver/squid/etc/
#可以写一下脚本,安装前,安装后,卸载前,卸载后等脚本
%pre
if [ $1 == 1 ]; then
/usr/sbin/useradd -s /bin/false -r %{squid_user} 2>/dev/null || :
fi
%preun
%post
%postun
#清除buildroot目录下的信息,以便不影响下次制作
%clean
%{__rm} -rf %{buildroot}
#指定安装后的文件
%files
%defattr(-,%{squid_user},%{squid_user},0755)
/usr/local/webserver/squid/bin/
/usr/local/webserver/squid/libexec/
/usr/local/webserver/squid/sbin/
/usr/local/webserver/squid/share/
%config(noreplace) /usr/local/webserver/squid/etc/*
#日志信息
%changelog
* Mon Jun 03 2013 -
- second build
* Fri May 31 2013 - Yangyang <yangyang89@hupu.com>
- first build
参考:
http://wiki.centos.org/zh/HowTos/SetupRpmBuildEnvironment
http://mageedu.blog.51cto.com/4265610/1205205
(责任编辑:IT)
制作RPM包有很多好处,可以较快安装部署喜欢的配置,参数;对于大批量安装省时省力,是一件事半功倍的事。
制作RPM需要准备好源码包和spec文件,安装好依赖和编译工具,熟悉制作RPM包的几个目录。 这里制作squid的rpm包只需要将源码包放置到SOURCES中,再切换到SPEC目录中,运行 rpmbuild -ba squid.2.7.spec 在制作过程中需要注意的: 制作RPM包不能使用root用户,因为权限过大,操作错误会造成较大影响。 使用普通用户制作时,rpmbuild的宏定义可以在~/.rpmmacros中定义 在spec中使用自定义宏的方法 %define macro_name value 在spec中使用宏的方法是 %{macro_name} 在spec中注释用#,注释信息中不可用% 制作squid RPM包build过程时,出现的错误及解决
出现../include/squid_md5.h:27:2: error: #error Cannot find OpenSSL MD5 headers yum install -y openssl*
出现rpmbuild: error: Installed (but unpackaged) file(s) found Solution %files%defattr(-,root,root,-)/path/to/dir//path/to/file/ squid源码包下载地址:http://www.squid-cache.org/Versions/v2/2.7/squid-2.7.STABLE5.tar.bz2 squid.2.7.spec内容 %define squid_user squid #---RPM包信息 #描述信息 Summary: hupu web proxy and content serving. #软件包名 Name: squid #软件包版本 Version: 2.7.STABLE5 #rpm包的发行版本,RPM包制作者自己定义,第几次制作找个包就写几次。 Release: 3%{?dist} #rpm包的下载地址,如果没有下载地址可以写成源码包的官方地址 URL: http://www.squid-cache.org/Versions/v2/2.7/squid-2.7.STABLE5.tar.bz2 #RPM包的密钥,可以去源码包找对应的密钥,涉及到版权信息。 License: Creative Commons Attribution Sharealike 2.5 License #rpm包的所属组 Group: System Environment/Daemons #指定rpm包的源文件,地址在_topdir/SOURCES Source0: squid-2.7.STABLE5.tar.bz2 #Source1: squid.conf #指定rpm包的虚拟目录,类似DNS的chroot BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) #取消自动添加依赖关系 AutoReq: no #描述信息 %description Squid is a fully-featured HTTP/1.0 proxy which is almost (but not quite - we're getting ther e!) a fully-featured HTTP/1.1 proxy. Squid offers a rich access control, authorization and l ogging environment to develop web proxy and content serving applications. Squid offers a ric h set of traffic optimization options, most of which are enabled by default for simpler inst 81 lines yanked 1,1 Top #rpm包的所属组 Group: System Environment/Daemons #指定rpm包的源文件,地址在_topdir/SOURCES Source0: squid-2.7.STABLE5.tar.bz2 #Source1: squid.conf #指定rpm包的虚拟目录,类似DNS的chroot BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) #取消自动添加依赖关系 AutoReq: no #描述信息 %description Squid is a fully-featured HTTP/1.0 proxy which is almost (but not quite - we're getting ther e!) a fully-featured HTTP/1.1 proxy. Squid offers a rich access control, authorization and l ogging environment to develop web proxy and content serving applications. Squid offers a ric h set of traffic optimization options, most of which are enabled by default for simpler inst allation and high performance. #准备安装,解压 cd等都这这里进行 #rpmbuild -bp %prep %setup -q #编译信息 #rpmbuild -bc %build export DESTDIR=%{buildroot} ./configure --prefix=/usr/local/webserver/squid --enable-arp-acl --enable-snmp --enable-dlmalloc --with-pthreads --enable-epoll --enable-poll --disable-internal-dns --enable-stacktrace --enable-removal-policies=heap,lru --enable-delay-po ols --enable-storeio=ufs,aufs,diskd,coss,null --enable-external-acl --with-large-files --enable-large-files --enable-async-io --enable-dl-malloc --enable-ssl --enable-auth=basic,digest,negotiate,ntlm --enable-icmp --enable-large-cache-fi les make %{?_smp_mflags} #安装信息 %install %{__rm} -rf %{buildroot} make install DESTDIR=%{buildroot} #%{__install} -p -D -m 0755 %{SOURCE1} %{buildroot}/usr/local/webserver/squid/etc/ #可以写一下脚本,安装前,安装后,卸载前,卸载后等脚本 %pre if [ $1 == 1 ]; then /usr/sbin/useradd -s /bin/false -r %{squid_user} 2>/dev/null || : fi %preun %post %postun #清除buildroot目录下的信息,以便不影响下次制作 %clean %{__rm} -rf %{buildroot} #指定安装后的文件 %files %defattr(-,%{squid_user},%{squid_user},0755) /usr/local/webserver/squid/bin/ /usr/local/webserver/squid/libexec/ /usr/local/webserver/squid/sbin/ /usr/local/webserver/squid/share/ %config(noreplace) /usr/local/webserver/squid/etc/* #日志信息 %changelog * Mon Jun 03 2013 - - second build * Fri May 31 2013 - Yangyang <yangyang89@hupu.com> - first build 参考: http://wiki.centos.org/zh/HowTos/SetupRpmBuildEnvironment http://mageedu.blog.51cto.com/4265610/1205205 (责任编辑:IT) |