这个是自己写在CSDN上写的第一个技术博客, 因为最近自己在研究rpm打包. 今天把它分享出来哈~~ rpm的优势就是安装和后期升级方便快捷,无需再次手动编译源代码。节省很多时间。. 这里已Nginx 服务器安装包为实例进行试验.
1. 系统: CentOS release 6.5 (Final) x86_64
1. nginx 官网下载最新压缩包: wget http://nginx.org/download/nginx-1.6.0.tar.gz
2. 安装 rpmbuild 编译必备工具(群组安装方式): yum groupinstall "Development Tools"
[
huzhong@
s186
SPECS
]$
cat
nginx.
spec
%
define
_localstatedir
/
home
%
define
nginx_user
nginx
%
define
nginx_group
nginx
# distribution specific definitions
%
define
use_systemd
(
0
%
{?
fedora
}
&&
0
%
{?
fedora
}
>=
18
)
||
(
0
%
{?
rhel
}
&&
0
%
{?
rhel
}
>=
7
)
%
if
0
%
{?
rhel
}
==
5
Group:
System
Environment
/
Daemons
Requires
(
pre
):
shadow
-
utils
Requires:
initscripts
>=
8.36
Requires
(
post
):
chkconfig
Requires:
openssl
BuildRequires:
openssl
-
devel
%
endif
%
if
0
%
{?
rhel
}
==
6
Group:
System
Environment
/
Daemons
Requires
(
pre
):
shadow
-
utils
Requires:
initscripts
>=
8.36
Requires
(
post
):
chkconfig
Requires:
openssl
>=
1.0.1
BuildRequires:
openssl
-
devel
>=
1.0.1
%
define
with_spdy
1
%
endif
%
if
0
%
{?
rhel
}
==
7
Group:
System
Environment
/
Daemons
Requires
(
pre
):
shadow
-
utils
Requires:
systemd
Requires:
openssl
>=
1.0.1
BuildRequires:
systemd
BuildRequires:
openssl
-
devel
>=
1.0.1
%
define
with_spdy
1
%
endif
%
if
0
%
{?
suse_version
}
Group:
Productivity
/
Networking
/
Web
/
Servers
BuildRequires:
libopenssl
-
devel
Requires
(
pre
):
pwdutils
%
endif
# end of distribution specific definitions
Summary:
High
performance
web
server
Name:
nginx
Version:
1.6.0
Release:
1
%
{?
dist
}.
ngx
Vendor:
nginx
inc.
URL:
http:
//
nginx.
org
/
Source0:
http:
//
nginx.
org
/
download
/%
{
name
}
-%
{
version
}.
tar.
gz
Source1:
run.
sh
Source2:
nginx.
conf
License:
2
-
clause
BSD
-
like
license
BuildRoot:
%
{
_tmppath
}
/%
{
name
}
-%
{
version
}
-%
{
release
}
-
root
BuildRequires:
zlib
-
devel
BuildRequires:
pcre
-
devel
Provides:
webserver
%
description
nginx
[
engine
x
]
is
an
HTTP
and
reverse
proxy
server,
as
well
as
a
mail
proxy
server.
configure
arguments:
%
prep
%
setup
-
q
%
build
.
/
configure \
--
prefix
=%
{
_localstatedir
}
/
nginx \
--
conf
-
path
=%
{
_localstatedir
}
/
nginx
/
conf
/
nginx.
conf \
--
http
-
client
-
body
-
temp
-
path
=%
{
_localstatedir
}
/
nginx
/
cache
/
client_temp \
--
http
-
proxy
-
temp
-
path
=%
{
_localstatedir
}
/
nginx
/
cache
/
proxy_temp \
--
http
-
fastcgi
-
temp
-
path
=%
{
_localstatedir
}
/
nginx
/
cache
/
fastcgi_temp \
--
http
-
uwsgi
-
temp
-
path
=%
{
_localstatedir
}
/
nginx
/
cache
/
uwsgi_temp \
--
http
-
scgi
-
temp
-
path
=%
{
_localstatedir
}
/
nginx
/
cache
/
scgi_temp \
--
user
=%
{
nginx_user
} \
--
group
=%
{
nginx_group
} \
--
with
-
http_ssl_module \
--
with
-
http_realip_module \
--
with
-
http_addition_module \
--
with
-
http_sub_module \
--
with
-
http_dav_module \
--
with
-
http_flv_module \
--
with
-
http_gunzip_module \
--
with
-
http_gzip_static_module \
--
with
-
http_random_index_module \
--
with
-
http_secure_link_module \
--
with
-
http_stub_status_module \
--
with
-
http_auth_request_module \
--
with
-
mail \
--
with
-
mail_ssl_module \
--
with
-
file
-
aio \
make
%
{?
_smp_mflags
}
%
install
%
{
__rm
}
-
rf
$RPM_BUILD_ROOT
%
{
__make
}
DESTDIR
=
$RPM_BUILD_ROOT
install
%
{
__mkdir
}
-
p
$RPM_BUILD_ROOT
%
{
_localstatedir
}
/
nginx
/
cache
%
{
__mkdir
}
-
p
$RPM_BUILD_ROOT
%
{
_localstatedir
}
/
nginx
/
conf
/
conf.
d
%
{
__install
}
-
m
755
-
p
%
{
SOURCE1
} \
$RPM_BUILD_ROOT
%
{
_localstatedir
}
/
nginx
/
run.
sh
%
{
__install
}
-
m
644
-
p
%
{
SOURCE2
} \
$RPM_BUILD_ROOT
%
{
_localstatedir
}
/
nginx
/
conf
/
nginx.
conf
%
{
__mkdir
}
-
p
$RPM_BUILD_ROOT
%
{
_localstatedir
}
/
nginx
/
cache
%
clean
%
{
__rm
}
-
rf
$RPM_BUILD_ROOT
%
pre
# Add the "nginx" user
/
usr
/
bin
/
id
-
g
nginx
>/
dev
/
null
2
>&
1
||
/
usr
/
sbin
/
groupadd
nginx
/
usr
/
bin
/
id
-
u
nginx
>/
dev
/
null
2
>&
1
||
/
usr
/
sbin
/
useradd
-
M
-
g
nginx
nginx
if
[
-
r
/
home
/
nginx
/
sbin
/
nginx
] ;
then
/
bin
/
cp
-
f
/
home
/
nginx
/
sbin
/
nginx
{,.
old
}
>/
dev
/
null
2
>&
1
|| :
fi
%
post
# print site info
cat
<<
BANNER
----------------------------------------------------------------------
Thanks
for
using
nginx!
Please
find
the
official
documentation
for
nginx
here:
*
http:
//
nginx.
org
/
en
/
docs
/
Commercial
subscriptions
for
nginx
are
available
on:
*
http:
//
nginx.
com
/
products
/
----------------------------------------------------------------------
BANNER
%
preun
if
[
"$1"
=
"0"
] ;
then
/
home
/
nginx
/
run.
sh
stop
>/
dev
/
null
2
>&
1
|| :
fi
%
postun
#/home/nginx/run.sh softupdate >/dev/null 2>&1 || :
%
files
%
defattr
(
-,
nginx,
nginx
)
%
config
(
noreplace
)
/
home
/
nginx
/
conf
/
nginx.
conf
/
home
/
nginx
/
conf
/
fastcgi_params.
default
/
home
/
nginx
/
conf
/
mime.
types
/
home
/
nginx
/
conf
/
nginx.
conf.
default
/
home
/
nginx
/
html
/50
x.
html
/
home
/
nginx
/
html
/
index.
html
/
home
/
nginx
/
sbin
/
nginx
/
home
/
nginx
/
logs
/
home
/
nginx
/
run.
sh
%
exclude
/
home
/
nginx
/
conf
/
koi
-
utf
%
exclude
/
home
/
nginx
/
conf
/
koi
-
win
%
exclude
/
home
/
nginx
/
conf
/
win
-
utf
%
exclude
/
home
/
nginx
/
conf
/
fastcgi_params
%
exclude
/
home
/
nginx
/
conf
/
mime.
types.
default
%
exclude
/
home
/
nginx
/
conf
/
fastcgi.
conf
%
exclude
/
home
/
nginx
/
conf
/
fastcgi.
conf.
default
/
home
/
nginx
/
conf
/
scgi_params
/
home
/
nginx
/
conf
/
scgi_params.
default
/
home
/
nginx
/
conf
/
uwsgi_params
/
home
/
nginx
/
conf
/
uwsgi_params.
default
%
changelog
*
Thu
Apr
28
2014
Viman
<
zhong.
hu@
baoyugame.
com
>
-
1.6.0.1
*
Thu
Apr
24
2014
Konstantin
Pavlov
<
thresh@
nginx.
com
>
-
1.6.0