星空网 > 软件开发 > 操作系统

构建本地yum源之rpmbuild

组内准备搭建内部yum源,在这之前需要规范软件的安装目录,并把现有的应用打包。

 

目前接触两种rpm打包工具,rpmbuild和fpm。

- rpmbuild

    rpmbuild关键是spec文件编写。

    环境搭建

    yum -y install rpm-build rpmdevtools

    useradd rpm; su rpm

    注: rpm打包需要特定目录下,在近期版本下rpmbuild可以在非root账号家目录下创建打包目录:

    rpmdev-setuptree

    [rpm@vm-1-lz rpmbuild]$ ll

    total 20

    drwxrwxr-x. 2 rpm rpm 4096 Dec 22 14:46 BUILD

    drwxrwxr-x. 2 rpm rpm 4096 Dec 22 14:46 RPMS

    drwxrwxr-x. 2 rpm rpm 4096 Dec 22 15:06 SOURCES

    drwxrwxr-x. 2 rpm rpm 4096 Dec 22 16:07 SPECS

    drwxrwxr-x. 2 rpm rpm 4096 Dec 22 14:46 SRPMS

    [rpm@vm-1-lz rpmbuild]$ 

    注:这里是/home/rpm/rpmbuild, 这个默认目录可以修改,可以修改宏定义:

    /usr/lib/rpm/macros: 

       _topdir                %{getenv:HOME}/rpmbuild

    然后在rpmbuild/SPECS 目录下创建spec文件:

    cd ~/rpmbuild/SPECS

    rpmdev-newspec -o example.spec

    

    SPEC文件

     打包过程是

     1. %prep 解压source部分定义的压缩包到 %build目录下

     注:Source需要是tar格式压缩文件,这样setup才能调用 (source 跟setup可以多条记录,并依序对应)

     2  %build 可以调用%configure宏变量或是直接调用configure命令直接配置

     3  %install 安装文件到%buildroot下 (rpmbuild/BUILDROOT), 在这部分,需要确保目录已经存在不然会报错,比如拷贝配置文件到/etc/下,需要建立%buildroot/etc 目录

     注:%install 部分是用绝对路径的,所以最好引用%buildroot

     4 %file 部分定义那些文件将被打包进rpm包里

     注:%file部分是用相对路径,我们可以用宏变量 比如%_prefix 代表/usr  其绝对路径就是%buildroot/usr

     参考 http://fedoraproject.org/wiki/Packaging:RPMMacros

 

- fpm 打包

    这是一个开源的项目 https://github.com/jordansissel/fpm 

    环境搭建:

    yum -y ruby ruby-devel rubygems rpm-build

    gem install fpm

    注: 这里有个坑。如果正常按照gem去安装 我们是没办法调用 fpm成功的,因为 cabin的版本有问题:

    [root@vm-1-lz RPMS]# fpm

    /usr/lib/ruby/gems/1.8/gems/cabin-0.8.0/lib/cabin/mixins/logger.rb:12:in `included': undefined method               `options' for #<Cabin::Subscriber:0x7fad75e31b90> (NoMethodError)

     from /usr/lib/ruby/gems/1.8/gems/cabin-0.8.0/lib/cabin/channel.rb:105:in `call'

    ....

    因此, 卸载当前cabin版本:

    gem uninstall cabin

    ....

    gem install cabin -v 0.7.2

    用前一个版本的cabin才能正确启动fpm

 

    构建rpm包

    把之前编译好的nginx打包:

    nginx 目录: /usr/local/nginx

    fpm命令:

    fpm -e -s dir -t rpm -n nginx -v 1.8.0 -C /usr/local/nginx --prefix=/opt/nginx

    注: -e 可以让我们看到具体的spec文件,  如果没问题,保存退出就能在当前目录创建一个rpm包

    

    但是fpm不能友好的按照规范路径打包

 

 

- SPEC例子

Name:      tengineVersion:    1.5.2Release:    1%{?dist} Summary:    tengine-1.5.2Group:     Application/System License:    GPL URL:      http://tengine.taobao.org/Source0:    tengine-1.5.2.tar.gzSource1:    LuaJIT-2.0.4.tar.gzSource2:    pcre-8.34.tar.gzSource3:    openssl-1.0.2e.tar.gzSource4:    zlib-1.2.8.tar.gzSource5:    ngx_devel_kit-0.2.18.tar.gzSource6:     jemalloc-3.4.0.tar.bz2Source7:    nginx-bb-1.8.0.tar.gzRequires: zlib,pcre,openssl,LuaJIT %descriptiontengine-1.5.2%prep%setup -b 0%setup -b 1%setup -b 2%setup -b 3%setup -b 4%setup -b 5%setup -b 6%setup -b 7%build CFLAGS="${CFLAGS:--O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic}" ; export CFLAGS ; CXXFLAGS="${CXXFLAGS:--O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic}" ; export CXXFLAGS ; FFLAGS="${FFLAGS:--O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -I/usr/lib64/gfortran/modules}" ; export FFLAGS ; ./configure \ --with-http_ssl_module \ --prefix=/opt/nginx \ --error-log-path=/opt/nginx/logs/ \ --http-log-path=/opt/nginx/logs/ \ --pid-path=/opt/nginx/run/ \ --lock-path=/opt/nginx/lock/ \ --user=www \ --group=www \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --with-http_lua_module \ --with-luajit-inc=/usr/local/include/luajit-2.0 \ --with-luajit-lib=/usr/local/lib \ --with-pcre=%{_builddir}/pcre-8.34 \ --with-openssl=%{_builddir}/openssl-1.0.2e \ --with-zlib=%{_builddir}/zlib-1.2.8 \ --with-http_concat_module \ --with-http_sysguard_module \ --with-http_realip_module \ --without-syslog \ --with-jemalloc \ --add-module=%{_builddir}/ngx_devel_kit-0.2.18 make %{?_smp_mflags} %install rm -rf $RPM_BUILD_ROOT make install DESTDIR=$RPM_BUILD_ROOTmv %{buildroot}/opt/nginx/conf %{buildroot}/opt/nginx/conf.defaultinstall -d %{buildroot}/opt/nginx/confcp -r %{_builddir}/nginx-bb-1.8.0/conf/* %{buildroot}/opt/nginx/conf%clean rm -rf $RPM_BUILD_ROOT %files %defattr(-,root,root,-) %doc /opt/nginx/*%changelog

 

 

 




原标题:构建本地yum源之rpmbuild

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

中通快递:https://www.goluckyvip.com/tag/11334.html
2022电商趋势:https://www.goluckyvip.com/tag/11335.html
Flipkart大促:https://www.goluckyvip.com/tag/11336.html
日用品:https://www.goluckyvip.com/tag/11337.html
FDI新规:https://www.goluckyvip.com/tag/11338.html
特蕾莎·梅:https://www.goluckyvip.com/tag/11339.html
海南琼海市有什么旅游景点 琼海市的旅游景点:https://www.vstour.cn/a/362187.html
快手本地生活上线“吃喝免费试”活动 强化低价供给心智 :https://www.kjdsnews.com/a/1836309.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流