上次和Sogou运维的同学交流,他们是通过本地yum源来统一安装应用

借鉴人家的经验,我们今后的运维部署工作,也准备使用yum统一完成

周末2天在家捣鼓了一番,终于完成了nginx的rpm包,并通过yum安装

打包rpm的过程:

1. RedHat上默认的打包路径是/usr/src/redhat/,可以自己定义:

mkdir /opt/rpmbuild

echo %_topdir /opt/rpmbuild > ~/.rpmmacros

2. 建立相应的目录

mkdir /opt/rpmbuild/BUILD

mkdir /opt/rpmbuild/RPMS

mkdir /opt/rpmbuild/RPMS/x86_64

mkdir /opt/rpmbuild/RPMS/noarch

mkdir /opt/rpmbuild/SOURCES

mkdir /opt/rpmbuild/SPECS

mkdir /opt/rpmbuild/SRPMS

3. 将nginx1.0.2源码以及相关附加包拷贝到/opt/rpmsrc/nginx下,并生成tgz

tar zcvf nginx-passport-1.0.2.tgz nginx-passport-1.0.2/

cp nginx-1.0.2-passport.tgz  /opt/rpmbuild/SOURCES/

4. 编辑相应的spec文件

vi /opt/rpmbuild/SPECS/nginx-passort.spec

Summary: Nginx not include mod_passport 

Name: nginx-nopassport

Version: 1.0.2

Release: 1

Source0: %{name}-%{version}.tgz

Packager: yushunzhi

License: GPL

Group: Applications/System

BuildRoot: %{_builddir}/%{name}-root

%define nginx_datadir   /opt/apps_install/nginx-%{version}


BuildRequires: pcre,zlib,openssl-devel,perl

Requires: pcre,zlib,openssl

%description

Nginx %{version} not include mod_passport

%prep

%setup -q

%build

./configure --prefix=%{nginx_datadir} ......

make

%install

rm -rf $RPM_BUILD_ROOT

make install DESTDIR=$RPM_BUILD_ROOT

%clean

rm -rf $RPM_BUILD_ROOT

%files

%{nginx_datadir}/

5. 执行打包

rpmbuild -bb nginx-passport.spec

 

建立本地的yum源:

1. 建立目录

mkdir /opt/yum

mkdir /opt/yum/Server

2. 生成repo文件

vi /etc/yum.repos.d/mtpc.repo

[Server]

name=Server

baseurl=http://..../Server

enabled=1

gpgcheck=0

3. 生成本地xml metadata信息

createrepo -v /opt/yum/Server/

4. 安装

yum install nginx-passport.x86_64