spec detail

下面是spec定义的细节说明,同时,我们列举了两个spec文件,加深印象,它们分别是mysql rpm包制作的spec和php rpm包制作的spec:

Summary:rpm的内容概要Name:rpm的名称,后面可使用%{name}的方式引用Version:rpm的实际版本号,例如:1.2.5等,后面可使用%{version}引用Release:发布序列号,例如:1等,标明第几次打包,后面可使用%{release}引用License:软件授权方式,通常就是GPLGroup:软件分组Source:源代码包,可以带多个用Source1、Source2等源,后面也可以用%{source1}、%{source2}引用Build Arch:指编译的目标处理器架构,noarch标识不指定,但通常都是以/usr/lib/rpm/marcros中的内容为默认值BuildRoot:这个是安装或编译时使用的“虚拟目录”,考虑到多用户的环境,一般定义为:%{_tmppath}/%{name}-%{version}-%{release}-root或%{_tmppath}/%{name}-%{version}-%{release}-buildroot-%(%{__id_u} -n};该参数非常重要,因为在生成rpm的过程中,执行make install时就会把软件安装到上述的路径中,在打包的时候,同样依赖“虚拟目录”为“根目录”进行操作。后面可使用$RPM_BUILD_ROOT 方式引用。URL:软件的主页Packager:打包者的信息Requires:该rpm包所依赖的软件包名称,可以用>=或<=表示大于或小于某一特定版本,例如:libpng-devel >= 1.0.20 ,“>=”号两边需用空格隔开,而不同软件名称也用空格分开%description软件的详细说明%prep预处理脚本%setup通常是从/usr/src/redhat/SOURCES里的包解压到/usr/src/redhat/BUILD/%{name}-%{version}中。一般用%setup -c就可以了,但有两种情况:一就是同时编译多个源码包,二就是源码的tar包的名称与解压出来的目录不一致,此时,就需要使用-n参数指定一下了。%build开始构建包,在/usr/src/redhat/BUILD目录中%install开始把软件安装到虚拟的根目录中,这个很重要,因为如果这里的路径不对的话,则下面%files中寻找文件的时候就会失败。可以使用:make DESTDIR=$RPM_BUILD_ROOT install或者使用常规的系统命令 cp -rf filename $RPM_BUILD_ROOT/%clean清理临时文件,注意区分$RPM_BUILD_ROOT和$RPM_BUILD_DIR:$RPM_BUILD_ROOT是指开头定义的BuildRoot,而$RPM_BUILD_DIR通常就是指/usr/src/redhat/BUILD,其中,前面的才是%files需要的。%prerpm安装前执行的脚本%postrpm安装后执行的脚本%preunrpm卸载前执行的脚本%postunrpm卸载后执行的脚本%preun %postun 的区别是前者在升级rpm包的时候会执行,后者在升级rpm包的时候不会执行%files定义那些文件或目录会放入rpm中,下面的路径不是系统的绝对路径而是$RPM_BUILD_ROOT下的路径%defattr指定安装rpm包后的文件属性,分别是(mode,owner,group),-表示默认值,对文本文件是0644,可执行文件是0755

下面是mysql的spec:

%define mysql_user      mysql%define mysql_group     %{mysql_user}%define mysql_root      /data/mysql%define mysql_datadir   /data/mysql/varName:           Percona-Server-5.5.34Version:        rel32.0Release:        1%{?dist}Summary:        MySQL (Structured Query Language) database serverGroup:          Community/stableLicense:        rel6URL:            http://www.percona.comSource0:        Percona-Server-5.5.34-rel32.0.tar.gzSource1:        my.cnfSource2:        mysql.serverBuildRoot:      %{_topdir}/BUILDROOTBuildRequires:  ncurses-devel,openssl-devel,tcp_wrappers-devel,bison,libaio-develRequires:       gcc,gcc-c++,perl-Time-HiRes,perl-DBI,perl,cmake,ncurses-devel,openssl-devel,tcp_wrappers-devel,bison,libaio-develAutoReqProv:    no%descriptionThe MySQL software delivers a very fast, multi-threaded, multi-user, and robust SQL (Structured Query Language) database server.%prep%setup -qgroupadd %{mysql_group}useradd  -g %{mysql_group} -s /sbin/nologin %{mysql_user}%buildcmake .         -DCMAKE_BUILD_TYPE=RelWithDebInfo         -DBUILD_CONFIG=mysql_release         -DFEATURE_SET=community         -DWITH_EMBEDDED_SERVER=OFF         -DDEFAULT_CHARSET=utf8         -DDEFAULT_COLLATION=utf8_general_ci         -DWITH_EXTRA_CHARSETS=all         -DWITH_READLINE=1         -DWITH_SSL=bundled         -DWITH_ZLIB=system         -DWITH_LIBWRAP=1          -DCMAKE_INSTALL_PREFIX=%{mysql_root}         -DMYSQL_UNIX_ADDR=%{mysql_root}/mysql.sockmake%install#rm -rf $RPM_BUILD_ROOT#make install DESTDIR=$RPM_BUILD_ROOTmake install DESTDIR=%{buildroot}%{__install} -p -D %{SOURCE1} -m 0644 %{buildroot}/etc/my.cnf%{__install} -p -D %{SOURCE2} -m 0700 %{buildroot}/etc/init.d/mysqld%{__install} -d %{buildroot}%{mysql_datadir}%{__install} -d %{buildroot}/data/mysqllog%{__install} -d %{buildroot}/data/mysqllog/binlog%cleanrm -rf $RPM_BUILD_ROOT%post/data/mysql/scripts/mysql_install_db --user=%{mysql_user} --basedir=%{mysql_root} --datadir=%{mysql_datadir}chkconfig --add mysqldchkconfig --level  345  mysqld  onecho "PATH=$PATH:/data/mysql/bin" >> /etc/profileecho "export PATH" >> /etc/profileecho "/data/mysql/lib" >> /etc/ld.so.conf/sbin/ldconfigsource /etc/profile%files%defattr(-,mysql,mysql,-)%doc%dir /etc/init.d/mysqld%dir /etc/my.cnf/data/mysql/data/mysqllog%changelog

其实在上面的mysql spec有一个问题:应该将添加用户mysql和用户组加入%pre

下面我们再看一下php安装的sepc文件:

Name:           phpVersion:        5.3.29Release:        jack%{?dist}Summary:        PHP is a popular general-purpose scripting language that is especially suited to web developmentGroup:          System Environment/stableLicense:        el6URL:            http://php.netSource0:        php-5.3.29.tar.gzSource1:        php-fpmSource2:        php.ini-productionSource3:        php-fpm.conf#BuildRoot:      %{_topdir}/BUILDROOTBuildRoot:      %{_topdir}/BUILDROOTBuildRequires:  jpeg,libmcrypt,libmcrypt-devel,fontconfig,freetypeRequires:       jpeg,libmcrypt,libmcrypt-devel,fontconfig,freetype%descriptionPHP is a popular general-purpose scripting language that is especially suited to web development%prep%setup -q%build./configure         --prefix=/usr/local/webserver/php         --with-zlib         --with-mysql=mysqlnd         --with-mysqli=mysqlnd         --with-pdo-mysql=mysqlnd          --with-jpeg-dir=/usr/local/jpeg         --with-png-dir=/usr/local/libpng         --with-freetype-dir=/usr/local/freetype         --with-libexpat-dir         --with-libxml-dir         --with-gd=/usr/local/gd         --with-openssl         --with-iconv         --with-gettext         --with-curl         --with-curlwrappers         --with-mhash         --enable-pcntl         --with-mcrypt         --with-bz2         --with-ldap         --enable-ftp         --with-ldap-sasl         --enable-gd-native-ttf         --enable-mbstring=all         --enable-xml         --enable-pdo         --enable-exif         --enable-mbregex         --enable-zip         --enable-soap         --enable-sockets         --enable-bcmath         --enable-shmop         --enable-sysvsem         --enable-sysvshm         --enable-sysvmsg         --enable-inline-optimization         --disable-xmlreader         --disable-debug         --disable-rpath         --without-pear         --enable-fpm         --with-fpm-user=nobody         --with-fpm-group=nobodymake%installmake install INSTALL_ROOT=%{buildroot}%{__install} -p -D %{SOURCE1} -m 0711 %{buildroot}/etc/init.d/php-fpm%{__install} -p -D %{SOURCE2} -m 0644 %{buildroot}/usr/local/webserver/php/lib/php.ini%{__install} -p -D %{SOURCE3} -m 0644 %{buildroot}/usr/local/webserver/php/etc/php-fpm.conf%cleanrm -rf $RPM_BUILD_ROOT%files%defattr(-,root,root,-)%doc%dir /etc/init.d/php-fpm/usr/local/webserver/php%changelog

spec detail,首发于运维者。

只要笑一笑,没什么事请过不了

spec detail

相关文章:

你感兴趣的文章:

标签云: