More Related Content Similar to 使用Rpm&yum进行基础软件管理 Similar to 使用Rpm&yum进行基础软件管理 (20) 使用Rpm&yum进行基础软件管理4. HOW: 打包工具rpmbuild 1. 构建二进制rpm包 rpmbuild –bb x.spec 2. 构建源码rpm包 rpmbuild –bsx.spec 3. 同时构建二进制和源rpm包 rpmbuild –bax.spec 4.从源码包构建二进制包 rpmbuild –rebuild x.src.rpm 6. 自定义打包工作路径 vi ~/.rpmmacros %_topdir /home/ningoo/rpm %_prefix /u01/mysql mkdir /home/ningoo/rpm cd /home/ningoo/rpm mkdir RPMS SRPMS SOURCES BUILD BUILDROOT SPECS 7. SPEC的精髓:宏 默 认:/usr/lib/rpm/macros or /etc/rpm/macros 自定义:~/.rpmmacros 查看所有宏 rpmbuild --showrc 8. 常见宏 %_topdir工作根目录 %_tmpdir工作临时目录 %_prefix 前导目录 %optflags编译优化参数 %prep 准备阶段 %setup 解压.tar.gz包 %build 编译阶段configure/make %install 安装阶段make install %clean 清楚临时文件 %files 打包阶段,列举所有需要打进RPM的文件 %pre 安装RPM前执行的动作 %post 安装RPM后执行的动作 %preun卸载RPM前执行的动作 %postun卸载RPM后执行的动作 9. SPEC文件 第一部分:包的详细信息描述 Name: helloworld Summary: Hello World! Version: 0.1 Release: 1 License: GPL URL: http://www.ningoo.net/ Group: applications/system BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root Source: %{name}-%{version}.tar.gz Prefix: %{_prefix} Requires: libaio-devel Packager: NinGoo Autoreq: no %description: xxx 10. SPEC文件 第一部分:包的详细信息描述 $ rpm -qpi myddl-0.1-1.i386.rpm Name : myddl Relocations: /u01/mysql Version : 0.1 Vendor: (none) Release : 1 Build Date: 2011年05月21日 星期六 01时01分07秒 Install Date: (not installed) Build Host: ning Group : applications/system Source RPM: myddl-0.1-1.src.rpm Size : 92615 License: GPL Signature : (none) Packager : NinGoo URL : http://www.ningoo.net/ Summary : xxx Description : xxx 11. SPEC文件 第二部分:打包过程控制 %prep 准备阶段 解压SOURCES下的.tar.gz包 %setup -q 如果源.tar.gz包没有目录,则需要创建目录 %setup -q -c -n %{name}-%{version} 12. 编写SPEC文件 第二部分:打包过程控制 %build 编译阶段 %configure宏或者自己 ./configure –prefix=%{_prefix} 编译 make -j `cat /proc/cpuinfo | grep processor | wc -l` 13. 编写SPEC文件 第二部分:打包过程控制 %install 安装阶段 %make_install宏或者自己 make DESTDIR=$RPM_BUILD_ROOT install or make prefix=$RPM_BUILD_ROOT install or install -D xxx ${RPM_BUILD_ROOT}/%{_prefix}/ 14. 编写SPEC文件 第二部分:打包过程控制 %files RPM文件生成 设置文件默认权限和属主 %defattr(755,mysql,dba) %attr(755,mysql,dba) %{_prefix}/bin/* %doc %attr(644,mysql,dba) %{_prefix}/docs/* %config %attr(644,mysql,dba) %{_prefix}/conf/* 21. YUM(YellowDog Updater, Modified) 上传RPM到YUM仓库 上传工具 sudo yum install yumtools -b current *-b 分支,包括stable, current, test 配置yum … 上传 yum-upload --osver=5 --arch=x86_64 --group=dba mysql-5.1.48-1.x86_64.rpm -b test