customizing RPM packages and adding internal yum Server

Source: Internet
Author: User
Tags haproxy rpmbuild
customizing RPM packages and adding internal yum ServerThis article is reproduced in the original address: http://dreamway.blog.51cto.com/1281816/1110822



1, the production of RPM package Linux system environment

# Cat/etc/redhat-release

CentOS Release 5.8 (Final)

# Uname-r

2.6.18-308.el5

# uname-m

X86_64 2, pre-build the directory structure required to create Rpmbuild, usually installed cent0s5.8 system has created a directory structure, as follows:

# LS/USR/SRC

Debug Kernels Redhat

# ls/usr/src/redhat/

Build RPMS SOURCES SPECS Srpms root user to make RPM package use the directory under/usr/src/redhat/if you use ordinary users, you can create a good directory manually, the following command

# mkdir-p/home/zxp/{build,rpms,sources,specs,srpms} Directory Description : Build: The temporary storage space for the source code when compiling the software package.
RPMS: The output position of the prepared binary package.
SOURCES: The location of the source code.
The location where the specs:spec files are stored.
SRPMS: The output location of the source RPM package is produced, which still needs to be compiled before the package is installed. 3, spec file details to build a standard RPM package, you need to create a. spec file in the directory specs, which contains all the detailed information about the software that will be installed. Then execute the rpmbuild command on the text in the system, and the system will automatically generate the final RPM package according to the steps set by the. Spec content. 3.1 Spec file syntax (take Haproxy as an example)

# Cat Haproxy.spec

Summary:ha-proxy is a tcp/http reverse Proxy for high availability environments #软件摘要信息

Name:haproxy #软件名称

version:1.4.22 #软件版本

RELEASE:20130106_HEXUN_AS5 #软件分支版本

LICENSE:GPL #软件版权

Group:system environment/daemons #软件所属分类

url:http://haproxy.1wt.eu/#软件主页

Source0:http://haproxy.1wt.eu/download/1.4/src/%{name}-%{version}.tar.gz #源码位置

BuildRoot:%{_tmppath}/%{name}-%{version}-root #安装目录

Buildrequires:pcre-devel #编译依赖软件包

Requires:/sbin/chkconfig,/sbin/service #安装依赖软件包

%description #软件详细的描述信息

Ha-proxy is a tcp/http reverse Proxy which are particularly suited for high

Availability environments. Indeed, it can:

-Route HTTP requests depending on statically assigned cookies

-Spread the load among several servers while assuring server persistence

Through the use of HTTP cookies

-Switch to backup servers in the event a main one fails

-Accept connections to special ports dedicated to service monitoring

-Stop accepting connections without breaking existing ones

-Add/modify/delete HTTP headers both ways

-Block requests matching a particular pattern

It needs very little resource. It Event-driven architecture allows it to easily

Handle thousands of simultaneous connections on hundreds of instances without

Risking the system ' s stability.

#%PREP defines the preparation to be done before the build, usually%setup define how to unpack

%prep

%setup-q

# We don ' t want any perl dependecies into this RPM:

%define __perl_requires/bin/true #定义不使用perl依赖关系

%build #编译源码命令, usually./configure && make, depending on the installation method of the specific package

%{__make} arch=%{_target_cpu} target=linux26

%install #安装阶段

['%{buildroot} '!= '/'] &&%{__rm}-RF%{buildroot}

%{__install}-D%{buildroot}%{_sbindir}

%{__install}-D%{BUILDROOT}%{_SYSCONFDIR}/RC.D/INIT.D

%{__install}-D%{buildroot}%{_sysconfdir}/%{name}

%{__install}-D%{buildroot}%{_mandir}/man1/

%{__install}-S%{name}%{buildroot}%{_sbindir}/

%{__install}-c-m 644 Examples/%{name}.cfg%{buildroot}%{_sysconfdir}/%{name}/

%{__install}-c-m 755 Examples/%{name}.init%{buildroot}%{_sysconfdir}/rc.d/init.d/%{name}

%{__install}-c-m 755 doc/%{name}.1%{buildroot}%{_mandir}/man1/

%clean #清理BUILD目录阶段

['%{buildroot} '!= '/'] &&%{__rm}-RF%{buildroot}

%post #安装后制定的脚本

/sbin/chkconfig--add%{name}

%preun #卸载前执行的脚本

If [$ = 0]; Then

/sbin/service%{name} stop >/dev/null 2>&1 | | :

/sbin/chkconfig--del%{name}

Fi

%postun #卸载后执行的脚本

If ["$"-ge "1"]; Then

/sbin/service%{name} condrestart >/dev/null 2>&1 | | :

Fi

%files #文件列表, mainly set the file, directory properties after installing the RPM package

%defattr (-,root,root) #定义默认属性

%doc changelog TODO examples/*.cfg doc/haproxy-en.txt doc/haproxy-fr.txt doc/architecture.txt doc/configuration.txt # Specifying software documentation

%doc%{_mandir}/man1/%{name}.1* #指定man帮助文档

%attr (0755,root,root)%{_sbindir}/%{name} #单独指定目录属性

%dir%{_sysconfdir}/%{name} #定义软件安装目录

%attr (0644,root,root)%config (noreplace)%{_sysconfdir}/%{name}/%{name}.cfg #单独指定文件属性

%attr (0755,root,root)%config%{_sysconfdir}/rc.d/init.d/%{name} #单独指定文件属性

%changelog #软件升级日志

* Tue Aug Willy Tarreau <w@1wt.eu>

-Updated to 1.4.22

............ Slightly..................

* Thu OCT 2003 Simon Matter <simon.matter@invoca.ch>

-Initial build 3, get the Spec file method (three methods) 3.1 Method 1: Get download & install the corresponding SRC.RPM package via SRC.RPM Package

# CD srpms/

# wget http://1wt.eu/tools/haproxy/src/devel/haproxy-1.2.3-1.src.rpm

# RPM-IVH haproxy-1.2.3-1.src.rpm

1:haproxy ########################################### [100%] here the "installation" refers to the xxx.src.rpm tar.gz, patches, xxx.s The PEC and other files are exported to/usr/src/redhat/'s sources, specs, etc. to view the generated files

# ls/usr/src/redhat/{sources,specs}

/usr/src/redhat/sources:

Haproxy-1.2.3.tar.gz

/usr/src/redhat/specs:

Haproxy.spec Find spec file, make backup, modify

# Cd/usr/src/redhat/specs

# Cd/usr/src/redhat/specs

# CP Haproxy.spec haproxy.spec_bak$ (date +%f)

# ls

Haproxy.spec haproxy.spec_bak2013-01-06 3.2 Method 2: New Spec file specs, create a new spec file, according to the spec file syntax specification, this is more difficult, suitable for their own development software. 3.3 Method 3: Get the existing spec file from the source package (recommended method)

# tar zxf haproxy-1.4.22.tar.gz

# CD haproxy-1.4.22

# ll Haproxy.spec

-rw-rw-r--1 root 7442 Aug 15:09 haproxy.spec

#cd haproxy-1.4.22/examples/

# ls

Haproxy.spec the spec into the directory specs

# CP haproxy.spec/usr/src/redhat/specs/Backup

# CP Haproxy.spec haproxy.spec.$ (date +%f) This method is used to get spec 4, Edit spec

# Pwd/usr/src/redhat/specs

# vim Haproxy.spec changes before and after the content contrast (the original file after)

[Root@study02 specs]# diff Haproxy.spec Haproxy.spec.2013-01-07

4c4

< RELEASE:20130106_HEXUN_AS5

---

> release:1

36c36

<%{__make} ARCH=%{_TARGET_CPU} target=linux26

---

>%{__make} use_pcre=1 debug= "" Arch=%{_target_cpu} target=linux26 5, download the Haproxy source package download source package and put it into the sources directory

# pwd

/usr/src/redhat/sources

# wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.22.tar.gz

# ls haproxy-1.4.22.tar.gz 6, create the RPM package through the Rpmbuild command to parse spec file generation corresponding RPM Package 6.1 confirm Rpmbuild has been installed

# Yum Install rpm-build-y 6.2 Install the dependency pack on the build RPM package system Pcre-devel

# yum-y Install Pcre-devel 6.3 Start build RPM:

# rpmbuild-v-ba Specs/haproxy.spec 6.4 See the following is the creation process, the red content is the build package location

Executing (%PREP):/bin/sh-e/var/tmp/rpm-tmp.44698

+ umask 022

+ Cd/usr/src/redhat/build

+ lang=c

+ Export LANG

+ unset DISPLAY

+ Cd/usr/src/redhat/build

+ RM-RF haproxy-1.4.22

+/bin/gzip-dc/usr/src/redhat/sources/haproxy-1.4.22.tar.gz

+ TAR-XF-

+ status=0

............ Slightly..................

wrote:/usr/src/redhat/srpms/haproxy-1.4.22-20130106_hexun_as5.src.rpm

wrote:/usr/src/redhat/rpms/x86_64/haproxy-1.4.22-20130106_hexun_as5.x86_64.rpm

wrote:/usr/src/redhat/rpms/x86_64/haproxy-debuginfo-1.4.22-20130106_hexun_as5.x86_64.rpm

Executing (%clean):/bin/sh-e/var/tmp/rpm-tmp.75459

+ umask 022

+ Cd/usr/src/redhat/build

+ CD haproxy-1.4.22

+ ' ['/var/tmp/haproxy-1.4.22-root '!= '/'] '

+/bin/rm-rf/var/tmp/haproxy-1.4.22-root

+ Exit 0 #注意输出status为0 Create process error 7, test RPM package 7.1 use mocks and Koji to test RPM packages see Fedora new software maintainers Guide 7.2 list file information in RPM software package

# rpm-qpl/usr/src/redhat/rpms/x86_64/haproxy-1.4.22-20130106_hexun_as5.x86_64.rpm

/etc/haproxy

/etc/haproxy/haproxy.cfg

/etc/rc.d/init.d/haproxy

/usr/sbin/haproxy

/usr/share/doc/haproxy-1.4.22

/usr/share/doc/haproxy-1.4.22/changelog

/usr/share/doc/haproxy-1.4.22/todo

/usr/share/doc/haproxy-1.4.22/acl-content-sw.cfg

/usr/share/doc/haproxy-1.4.22/architecture.txt

/usr/share/doc/haproxy-1.4.22/auth.cfg

/usr/share/doc/haproxy-1.4.22/build.cfg

/usr/share/doc/haproxy-1.4.22/configuration.txt

/usr/share/doc/haproxy-1.4.22/content-sw-sample.cfg

/usr/share/doc/haproxy-1.4.22/cttproxy-src.cfg

/usr/share/doc/haproxy-1.4.22/examples.cfg

/usr/share/doc/haproxy-1.4.22/haproxy-en.txt

/usr/share/doc/haproxy-1.4.22/haproxy-fr.txt

/usr/share/doc/haproxy-1.4.22/haproxy.cfg

/usr/share/doc/haproxy-1.4.22/option-http_proxy.cfg

/usr/share/doc/haproxy-1.4.22/tarpit.cfg

/usr/share/doc/haproxy-1.4.22/test-section-kw.cfg

/usr/share/doc/haproxy-1.4.22/url-switching.cfg

/usr/share/man/man1/haproxy.1.gz 7.3 Lists the description information for the RPM package

# rpm-qpi/usr/src/redhat/rpms/x86_64/haproxy-1.4.22-20130106_hexun_as5.x86_64.rpm

Name:haproxy Relocations: (not relocatable)

version:1.4.22 Vendor: (none)

RELEASE:20130106_HEXUN_AS5 Build Date:mon Modified 2013 09:36:21 AM CST

Install Date: (not installed) build host:study02

Group:system environment/daemons Source rpm:haproxy-1.4.22-20130106_hexun_as5.src.rpm

size:1275757 LICENSE:GPL

Signature: (None)

url:http://haproxy.1wt.eu/

Summary:ha-proxy is a tcp/http reverse Proxy for high availability environments

Description:

Ha-proxy is a tcp/http reverse Proxy which are particularly suited for high

Availability environments. Indeed, it can:

-Route HTTP requests depending on statically assigned cookies

-Spread the load among several servers while assuring server persistence

Through the use of HTTP cookies

-Switch to backup servers in the event a main one fails

-Accept connections to special ports dedicated to service monitoring

-Stop accepting connections without breaking existing ones

-Add/modify/delete HTTP headers both ways

-Block requests matching a particular pattern

It needs very little resource. It Event-driven architecture allows it to easily

Handle thousands of simultaneous connections on hundreds of instances without

Risking the system ' s stability. 7.4 RPM Mode installation verification

[Root@study01 tools]# RPM-IVH haproxy-1.4.22-20130106_hexun_as5.x86_64.rpm

Preparing ... ########################################### [100%]

1:haproxy ########################################### [100%]

[Root@study01 tools]# ls

haproxy-1.4.22-20130106_hexun_as5.x86_64.rpm

[Root@study01 tools]# ls/etc/haproxy/#安装目录及主配置文件

Haproxy.cfg

[Root@study01 tools]# Ll/etc/rc.d/init.d/haproxy #服务启动文件

-rwxr-xr-x 1 root root 2553 7 09:36/etc/rc.d/init.d/haproxy

[Root@study01 tools]# Ll/etc/init.d/haproxy

-rwxr-xr-x 1 root root 2553 7 09:36/etc/init.d/haproxy

[Root@study01 tools]# Rpm-qf/etc/init.d/haproxy #查看软件所属软件包

Haproxy-1.4.22-20130106_hexun_as5

Now that the custom RPM package has been produced, we can then use the Common application software source package to be made into the Yum warehouse, the future deployment of software is very convenient. To continue, please move to the "Add custom RPM package to the internal Yum Sever" http://dreamway.blog.51cto.com/blog/1281816/1110874

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.