金庸武功之“神照经”--RPM包制作


一.环境

centos6.8

关闭selinux iptables

yum install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel  gd-devel -y

二.Nginx RPM包的制作


1.安装rpm-build

yum -y install rpm-build


2.增加普通用户并修改工作车间目录


# useradd hero

# su - hero

[hero@localhost ~]$ vim ~/.rpmmacros

  %_topdir        /home/hero/rpmbuild

[hero@localhost ~]# mkdir -pv ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS} 

[hero@localhost ~]# rpmbuild --showrc | grep _topdir    #会发现,工作车间已然改变:_topdir    /home/hero/rpmbuild


3、收集源码文件

(1)文件列表


[root@localhost SOURCES]# pwd

/home/hero/rpmbuild/SOURCES

[root@localhost SOURCES]# ls

fastcgi_params  init.nginx  nginx-1.10.2.tar.gz  nginx.conf




(2)nginx-1.10.2.tar.gz 源码包

$ cp /opt/src/nginx-1.10.2.tar.gz /home/hero/rpmbuild/SOURCES/


init.nginx 脚本文件

fastcgi_params 参数

在 SPECS 目录下创建 nginx.spec

 cd rpmbuild/SPECS/

以上3处见附件:



下面给出一个具体的我写的例子


Name: nginx          

Version: 1.10.2       

Release: 3%{?dist} 

Summary: nginx-1.10.2.tar.gz to nginx-1.10.2.rpm  

Group: Applications/Archiving    

License: GPLv2                    

URL: http://nginx.org/download

Packager: mxl0721 <54957565@qq.com>

Vendor: mxl0721

Source0: %{name}-%{version}.tar.gz     

Source1: init.nginx                    

Source2: nginx.conf                

Source3: fastcgi_params

BuildRoot: %_topdir/BUILDROOT

 

BuildRequires:  gcc gcc-c++ automake pcre pcre-devel  zlib-devel openssl openssl-devel  gd-devel

Requires:  gcc gcc-c++ automake pcre pcre-devel  zlib-devel openssl openssl-devel  gd-devel

 

%description             

Custom a rpm by yourself!Build nginx-1.10.2.tar.gz to nginx-1.10.2.rpm

 

 

%prep 

%setup -q   

 

 

%build

 

./configure \

--prefix=/usr/local/nginx \

--user=www \

--group=www \

--with-http_ssl_module \

--with-http_flv_module \

--with-http_stub_status_module \

--with-http_gzip_static_module \

--http-client-body-temp-path=/var/tmp/nginx/client/ \

--http-proxy-temp-path=/var/tmp/nginx/proxy/ \

--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \

--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \

--http-scgi-temp-path=/var/tmp/nginx/scgi \

--with-pcre

make %{?_smp_mflags}             

 

 

%install

rm -rf %{buildroot}

make install DESTDIR=%{buildroot}

%{__install} -p -D -m 0755 %{SOURCE1} %{buildroot}/etc/rc.d/init.d/nginx

%{__install} -p -D %{SOURCE2} %{buildroot}/usr/local/nginx/conf/nginx.conf

%{__install} -p -D %{SOURCE3} %{buildroot}/usr/local/nginx/conf/fastcgi_params

 

%pre

if [ $1 == 1 ];then                                                         

        /usr/sbin/useradd -r www -s /sbin/nologin 2> /dev/null             

fi                                                                              

                                                                          

%post

if [ $1 == 1 ];then

        /sbin/chkconfig --add %{name}

        /sbin/chkconfig %{name} on

        echo '# Add  #下面主要是内核参数的优化,包括tcp的快速释放和重利用等。   

net.ipv4.tcp_max_syn_backlog = 65536

net.core.netdev_max_backlog =  32768

net.core.somaxconn = 32768

 

net.core.wmem_default = 8388608

net.core.rmem_default = 8388608

net.core.rmem_max = 16777216

net.core.wmem_max = 16777216

 

net.ipv4.tcp_timestamps = 0

net.ipv4.tcp_synack_retries = 2

net.ipv4.tcp_syn_retries = 2

 

net.ipv4.tcp_tw_recycle = 1

net.ipv4.tcp_tw_reuse = 1

 

net.ipv4.tcp_mem = 94500000 915000000927000000

net.ipv4.tcp_max_orphans = 3276800

 

#net.ipv4.tcp_fin_timeout = 30

#net.ipv4.tcp_keepalive_time = 120

net.ipv4.ip_local_port_range = 1024  65535' >> /etc/sysctl.conf

sysctl -p 2>&1 /dev/null

fi

 

%preun

if [ $1 == 0 ];then

        /usr/sbin/userdel -r www 2> /dev/null

        /etc/init.d/nginx stop > /dev/null 2>&1

fi

%postun

 

 

%clean

rm -rf %{buildroot}

 

 

%files              

%defattr(-,root,root,0755)

/usr/local/nginx/

%attr(0755,root,root) /etc/rc.d/init.d/nginx

%config(noreplace) /usr/local/nginx/conf/nginx.conf

%config(noreplace) /usr/local/nginx/conf/fastcgi_params

 

 

%changelog

*  Tue Oct 31 2017 mxl0721 <54957565@qq.com> - 1.10.2-3

- Initial version



制作rpm包


rpmbuild -bp nginx.spec 制作到%prep段
rpmbuild - bc  nginx.spec 制作到%build段
rpmbuild -bi nginx.spec 执行 spec 文件的  "%install"  阶段 (在执行了 %prep 和 %build 阶段之后)。这通常等价于执行了一次  "make install"
rpmbuild -bb nginx.spec 制作二进制包
rpmbuild -ba nginx.spec 表示既制作二进制包又制作src格式包



   [hero@localhost ~]$  rpmbuild -bb nginx.spec







bibliography  :  http://www.cnblogs.com/seaspring/articles/5282516.html