FAIRYFAR-INTERNAL
 
  FAIRYFAR-INTERNAL  |  SITEMAP  |  ABOUT-ME  |  HOME  
Linux二进制程序及资源打包成rpm包

本文在 CentOS 7 上验证通过。

准备

安装rpmbuildrpmdevtools

yum install rpmbuild
yum install rpmdevtools

打包

用户的home目录下创建rpmbuild目录:

[root@localhost ~]# mkdir rpmbuild

rpmbuild目录下创建BUILDBUILDROOTSPECSRPMSSRPMS等目录,也可以rpmdev-setuptree工具创建:

[root@localhost ~]# rpmdev-setuptree

rpmbuild/SPECS目录中创建并编写一个libcgroup-tools-cgred-0.41-21.el7.x86_64.spec文件,名字无所谓,格式如下:

Name:   libcgroup-tools-cgred
Version:        0.41
Release:        21.el7
Summary:        libcgroup-tools-cgred package.

Group:          Applications/System
License:        GPL
URL:            www.200yi.com

%description
bcgroup-tools-cgred rpm package.

%prep
%build
%install
mkdir -p $RPM_BUILD_ROOT/usr/sbin
mkdir -p $RPM_BUILD_ROOT/usr/lib/systemd/system
mkdir -p $RPM_BUILD_ROOT/etc/sysconfig
mkdir -p $RPM_BUILD_ROOT/etc/cgconfig.d
mkdir -p $RPM_BUILD_ROOT/etc/cgrules.d

cp ../BUILD/etc/cgrules.conf $RPM_BUILD_ROOT/etc/
cp ../BUILD/etc/sysconfig/cgred $RPM_BUILD_ROOT/etc/sysconfig/
cp ../BUILD/usr/sbin/cgrulesengd $RPM_BUILD_ROOT/usr/sbin/
cp ../BUILD/usr/lib/systemd/system/cgred.service $RPM_BUILD_ROOT/usr/lib/systemd/system/

%files
/etc/cgrules.conf
/etc/sysconfig/cgred
/etc/cgconfig.d/
/etc/cgrules.d/
/usr/sbin/cgrulesengd
/usr/lib/systemd/system/cgred.service

把需要打包的文件按照目录结构放到rpmbuild/BUILD目录下。

现在可以执行打包命令了:

[root@localhost SPECS]# rpmbuild -bb libcgroup-tools-cgred-0.41-21.el7.x86_64.spec

打包成功后,rpm包将生成在rpmbuild/RPMS目录下。

打包遇到的问题

contains an invalid rpath

错误内容如下:

ERROR 0002: file 'xxx.so' contains an invalid rpath 'xxx' in [xxx]

解决方法:

修改~/.rpmmacros文件,注释掉以下行:

%__arch_install_post \
    ... /usr/lib/rpm/check-rpaths /usr/lib/rpm/check-buildroot

/etc/ld.so.conf: No such file or directory

警告内容如下:

/sbin/ldconfig: Warning: ignoring configuration file that cannot be opened: /etc/ld.so.conf: No such file or directory

安装rpm

[root@localhost x86_64]# rpm -ivh ./libcgroup-tools-cgred-0.41-21.el7.x86_64.rpm

参考



打赏作者以资鼓励: