rpmbuild与私有repo

[转载请注明出处]

建立私有repo

mkdir /data/myrepo/7/x86_64
createrepo /data/myrepo/7/x86_64

这样一个简单的私人repo就建立了,“7”对应的是os版本号,“x86_64”即为os架构。path可以自由来,但要和yum配置对应上。

注意:要做个http服务,要能访问到http://host/myrepo/*

使用私有repo

# 编辑/etc/yum.repos.d/CentOS-Base.repo
# 在文件末尾插入下面配置
# my private repo
[myrepo]
name=myrepo
baseurl=http://host/myrepo/$releasever/$basearch/
enabled=1
gpgcheck=0

$releasever即为os版本号,$basearch即为os架构

编辑完后,运行下面命令,即可

yum --enablerepo=myrepo clean metadata

用rpmbuild打自己的包

源有了,就差rpm了

基本信息

首先贡献权威教程:https://fedoraproject.org/wiki/How_to_create_an_RPM_package/zh-cn

注意了:rpmbuild最好使用普通帐号运行,不然打包过程中真的会把软件装上的

在普通用户家目录下建立这几个目录

cd ~
mkdir rpmbuild
cd rpmbuild;mkdir BUILD BUILDROOT RPMS SRPMS SOURCES SPECS

目录作用慢慢看

大概说一下几个关键的东东

以下变量都可以用 rpmbuild –showrc 看到

_topdir    %{getenv:HOME}/rpmbuild    # /home/user/rpmbuild 项目主目录

_buildrootdir      %{_topdir}/BUILDROOT    # /home/user/rpmbuild/BUILDROOT 打包的软件

_sourcedir %{_topdir}/SOURCES    # /home/user/rpmbuild/SOURCES 源目录,要打包的源码、文件放在这里

_rpmdir    %{_topdir}/RPMS    # /home/user/rpmbuild/RPMS 生成的RPM包存放在这

_specdir   %{_topdir}/SPECS    # /home/user/rpmbuild/SPECS .spec文件目录

大致流程

一、准备肥料:编写SPEC文件(打包配置)

二、准备种子:要安装的 源码 or 文件

三、播种:rpmbuild打包

四、收割:到RPMS目录下收货

SPECS编写

基本上看fedora的教程已经可以7788,下面举个例子

# 定义一些基本信息
# 我喜欢重新改个名,可以方便区分哪些是自己的包。因为在启用私有repo时,还在使用官方或其它repo
Name:           my-nginx
Version:        1.8.0
Release:        1%{?dist}
Summary:        nginx-1.8.0(with lua module) rebuild by potaski@qq.com
License:        GPLv2
BuildRequires:  gcc,make
Requires:       my-luajit,my-pcre,openssl,openssl-devel,lua,lua-devel
Source:         %{name}-%{version}.tar.gz
# 变量是大小写不分的,怎么写都不会出错
 
# 描述,是一定要有的
%description
nginx for centos7
date 20160306

%prep
%setup -q

%build
# ngx加入模块编译,要注意的是,一般编译时“add-module=path_to/module_dir/”最后带个/是没问题。到这里就会出错,所以最后的/不需要加上
./configure --user=nobody --group=nobody --prefix=/usr/local/nginx-1.8.0 --with-ld-opt="-Wl,-rpath,/usr/local/lib" --add-module=ngx_module/echo-nginx-module-master --add-module=ngx_module/lua-nginx-module-0.9.20  --with-http_ssl_module
make


%install
make install DESTDIR=%{buildroot}
# 安装完后插入自己的配置文件
%{__install} -p -m 0744 %{_sourcedir}/nginx %{buildroot}/usr/local/nginx-1.8.0/conf/nginx%{__install} -p -m 0644 %{_sourcedir}/proxy.conf_my.remote.port %{buildroot}/usr/local/nginx-1.8.0/conf/proxy.conf
%{__install} -p -m 0644 %{_sourcedir}/nginx-jsp.conf.1.8.0 %{buildroot}/usr/local/nginx-1.8.0/conf/nginx.conf
%{__install} -p -m 0644 %{_sourcedir}/my.lua %{buildroot}/usr/local/nginx-1.8.0/conf/my.lua

%files
# 打包过程
# 这里打的包路径为ngx编译时prefix指定的路径;如果是没有指定路径的也要尽量缩小路径
# 例如一个包要同时部署到/usr/lib和/usr/sbin,打包时要写/usr;其实打包时偷懒用/也可以,只是会提示与filesystem包冲突;删除时却不会删掉/,放心
%defattr(-,root,root)
/usr/local/nginx-1.8.0

%post
# 安装完rpm后运行的shell,可以做点环境
ln -s /usr/local/nginx-1.8.0 /usr/local/nginx
yes|cp /usr/local/nginx-1.8.0/conf/nginx /etc/init.d/nginx
echo "/etc/init.d/nginx start" >> /etc/rc.local

%preun
# 卸载前运行的shell
/etc/init.d/nginx stop

%postun
# 卸载后运行的shell,最好把屁股擦干净。以免留隐患
sed '/nginx start/'d /etc/rc.local -i
rm /usr/local/nginx -f
rm /etc/init.d/nginx -f

执行 rpmbuild –bb nginx.spec,就可以在SPEC目录下收货了

原文地址:https://www.cnblogs.com/tutuye/p/5264560.html