金庸武功之“神照經”--RPM包制作
金庸武功之“神照經”--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)文件列表
# 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
(2)nginx-1.7.7.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 <[email protected]>
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 <[email protected]> - 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
金庸武功之“神照經”--RPM包制作