海运的博客

制作OpenResty RPM包

发布时间:January 27, 2014 // 分类:CentOS // No Comments

创建rpmbuild目录:

mkdir -p ~/rpmbuild/{SOURCES,SPECS,SRPMS}

下载OpenResty源码:

wget -P ~/rpmbuild/SOURCE http://openresty.org/download/ngx_openresty-1.4.3.4.tar.gz

创建spec文件:

%define nginx_home %{_localstatedir}/cache/nginx
%define nginx_user nginx
%define nginx_group nginx
%define filename ngx_openresty-1.4.3.4

Summary: High performance web server
Name: openresty
Version: 1.4.3
Release: 4%{?dist}
Vendor: nginx inc.
URL: http://openresty.org/

Source0: http://openresty.org/download/%{filename}.tar.gz
Source1: logrotate
Source2: nginx.init
Source3: nginx.sysconf
Source4: nginx.conf
Source5: nginx.vh.default.conf
Source6: nginx.vh.example_ssl.conf

License: 2-clause BSD-like license
Group: System Environment/Daemons

BuildRequires: zlib-devel
BuildRequires: pcre-devel
BuildRequires: perl
BuildRequires: openssl-devel
BuildRequires: readline-devel
Requires: initscripts >= 8.36
Requires(pre): shadow-utils
Requires(post): chkconfig
Provides: webserver

%description
nginx [engine x] is an HTTP and reverse proxy server, as well as
a mail proxy server.

%package debug
Summary: debug version of nginx
Group: System Environment/Daemons
Requires: openresty
%description debug
Not stripped version of nginx built with the debugging log support.

%prep
#解压文件到build目录,默认目录名名称+版本 -n进入到指定的目录,用于文件名和解压目录名不同
%setup -q -n %{filename}

%build
./configure \
        --sbin-path=%{_sbindir}/nginx \
        --conf-path=%{_sysconfdir}/nginx/nginx.conf \
        --error-log-path=%{_localstatedir}/log/nginx/error.log \
        --http-log-path=%{_localstatedir}/log/nginx/access.log \
        --pid-path=%{_localstatedir}/run/nginx.pid \
        --lock-path=%{_localstatedir}/run/nginx.lock \
        --http-client-body-temp-path=%{_localstatedir}/cache/nginx/client_temp \
        --http-proxy-temp-path=%{_localstatedir}/cache/nginx/proxy_temp \
        --http-fastcgi-temp-path=%{_localstatedir}/cache/nginx/fastcgi_temp \
        --http-uwsgi-temp-path=%{_localstatedir}/cache/nginx/uwsgi_temp \
    --without-http_scgi_module \
        --user=%{nginx_user} \
        --group=%{nginx_group} \
    --with-luajit \
        --with-http_ssl_module \
        --with-http_gunzip_module \
        --with-http_gzip_static_module \
        --with-file-aio \
        --with-ipv6 \
        --with-debug \
        $*
make %{?_smp_mflags}
#$RPM_BUILD_DIR为rpmbuild/BUILD目录,编译软件所在的目录
%{__mv} %{_builddir}/%{filename}/build/nginx-1.4.3/objs/nginx %{_builddir}/nginx.debug
./configure \
        --sbin-path=%{_sbindir}/nginx \
        --conf-path=%{_sysconfdir}/nginx/nginx.conf \
        --error-log-path=%{_localstatedir}/log/nginx/error.log \
        --http-log-path=%{_localstatedir}/log/nginx/access.log \
        --pid-path=%{_localstatedir}/run/nginx.pid \
        --lock-path=%{_localstatedir}/run/nginx.lock \
        --http-client-body-temp-path=%{_localstatedir}/cache/nginx/client_temp \
        --http-proxy-temp-path=%{_localstatedir}/cache/nginx/proxy_temp \
        --http-fastcgi-temp-path=%{_localstatedir}/cache/nginx/fastcgi_temp \
        --http-uwsgi-temp-path=%{_localstatedir}/cache/nginx/uwsgi_temp \
    --without-http_scgi_module \
        --user=%{nginx_user} \
        --group=%{nginx_group} \
    --with-luajit \
        --with-http_ssl_module \
        --with-http_gunzip_module \
        --with-http_gzip_static_module \
        --with-file-aio \
        --with-ipv6 \
        $*
make %{?_smp_mflags}

%install
#$RPM_BUILD_ROOT 虚拟安装的根目录,位于rpmbuild/BUILDROOT/名称+版本
%{__rm} -rf $RPM_BUILD_ROOT
%{__make} DESTDIR=$RPM_BUILD_ROOT install

%{__rm} -f $RPM_BUILD_ROOT%{_sysconfdir}/nginx/*.default
%{__rm} -f $RPM_BUILD_ROOT%{_sysconfdir}/nginx/scgi_params

%{__mkdir} -p $RPM_BUILD_ROOT%{_localstatedir}/log/nginx
%{__mkdir} -p $RPM_BUILD_ROOT%{_localstatedir}/run/nginx
%{__mkdir} -p $RPM_BUILD_ROOT%{_localstatedir}/cache/nginx
%{__mkdir} -p $RPM_BUILD_ROOT%{_localstatedir}/www

%{__mv} $RPM_BUILD_ROOT/usr/local/openresty/nginx/html $RPM_BUILD_ROOT%{_localstatedir}/www
%{__rm} -rf $RPM_BUILD_ROOT/usr/local/openresty/nginx/

%{__mkdir} -p $RPM_BUILD_ROOT%{_sysconfdir}/nginx/conf.d
%{__rm} $RPM_BUILD_ROOT%{_sysconfdir}/nginx/nginx.conf
%{__install} -m 644 -p %{SOURCE4} $RPM_BUILD_ROOT%{_sysconfdir}/nginx/nginx.conf
%{__install} -m 644 -p %{SOURCE5} $RPM_BUILD_ROOT%{_sysconfdir}/nginx/conf.d/default.conf
%{__install} -m 644 -p %{SOURCE6} $RPM_BUILD_ROOT%{_sysconfdir}/nginx/conf.d/example_ssl.conf

%{__mkdir} -p $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig
%{__install} -m 644 -p %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/nginx

# install init
%{__mkdir} -p $RPM_BUILD_ROOT%{_initrddir}
%{__install} -m755 %{SOURCE2} $RPM_BUILD_ROOT%{_initrddir}/nginx

# install log rotation stuff
%{__mkdir} -p $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d
%{__install} -m 644 -p %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/nginx

# install debug
%{__install} -m644 %{_builddir}/nginx.debug $RPM_BUILD_ROOT%{_sbindir}/nginx.debug

#rpm build完成后删除虚拟安装目录
%clean
%{__rm} -rf $RPM_BUILD_ROOT

%files
#默认权限目录755,文件644
%defattr(-,root,root)

%{_sbindir}/nginx

#仅包含目录
%dir %{_sysconfdir}/nginx
%dir %{_sysconfdir}/nginx/conf.d
%{_localstatedir}/www/html/
#包含目录内所有文件
/usr/local/openresty/
%attr(0777,root,root) /usr/local/openresty/luajit/bin/luajit

#配置文件升级时不覆盖
%config(noreplace) %{_sysconfdir}/nginx/nginx.conf
%config(noreplace) %{_sysconfdir}/nginx/conf.d/default.conf
%config(noreplace) %{_sysconfdir}/nginx/conf.d/example_ssl.conf
%config(noreplace) %{_sysconfdir}/nginx/mime.types
%config(noreplace) %{_sysconfdir}/nginx/uwsgi_params
%config(noreplace) %{_sysconfdir}/nginx/fastcgi_params
%config(noreplace) %{_sysconfdir}/nginx/fastcgi.conf
%config(noreplace) %{_sysconfdir}/nginx/koi-utf
%config(noreplace) %{_sysconfdir}/nginx/koi-win
%config(noreplace) %{_sysconfdir}/nginx/win-utf

%config(noreplace) %{_sysconfdir}/logrotate.d/nginx
%config(noreplace) %{_sysconfdir}/sysconfig/nginx
%{_initrddir}/nginx

%attr(0755,root,root) %dir %{_localstatedir}/cache/nginx
%attr(0755,root,root) %dir %{_localstatedir}/log/nginx

%files debug
%attr(0755,root,root) %{_sbindir}/nginx.debug

%pre
#如安装httpd删除
rpm -q httpd > /dev/null && /sbin/service httpd stop > /dev/null 2>&1 && rpm -e httpd
#安装前添加运行nginx用户
getent group %{nginx_group} >/dev/null || groupadd -r %{nginx_group}
getent passwd %{nginx_user} >/dev/null || \
    useradd -r -g %{nginx_group} -s /sbin/nologin \
    -d %{nginx_home} -c "nginx user"  %{nginx_user}
exit 0

%post
# Register the nginx service
if [ $1 -eq 1 ]; then
    /sbin/chkconfig --add nginx
    # 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

    # Touch and set permisions on default log files on installation

    if [ -d %{_localstatedir}/log/nginx ]; then
        if [ ! -e %{_localstatedir}/log/nginx/access.log ]; then
            touch %{_localstatedir}/log/nginx/access.log
            %{__chmod} 640 %{_localstatedir}/log/nginx/access.log
            %{__chown} nginx:adm %{_localstatedir}/log/nginx/access.log
        fi

        if [ ! -e %{_localstatedir}/log/nginx/error.log ]; then
            touch %{_localstatedir}/log/nginx/error.log
            %{__chmod} 640 %{_localstatedir}/log/nginx/error.log
            %{__chown} nginx:adm %{_localstatedir}/log/nginx/error.log
        fi
    fi
fi

%preun
if [ $1 -eq 0 ]; then
    /sbin/service nginx stop > /dev/null 2>&1
    /sbin/chkconfig --del nginx
fi

%postun
if [ $1 -ge 1 ]; then
    /sbin/service nginx upgrade &>/dev/null || :
fi

build:

yum install readline-devel pcre-devel openssl-devel rpm-build
rpmbuild -ba openresty.spec 

安装打包的rpm程序:

rpm -ivh ~/rpmbuild/RPMS/x86_64/openresty-1.4.3-4.el6.x86_64.rpm 

标签:none

发表评论

分类
最新文章
最近回复
  • xiongrui: 看图
  • 傻狍子: filebrowser好像和这功能一样? https://github.com/filebro...
  • 陶国文: 想看看能不能安装
  • 傻狍子: 服务端设置了用户名密码认证的话,在openwrt的openvpn客户端的配置文件当中该如何更改...
  • 王阴阳师: 感谢,一点不啰嗦,还很管用!
  • simon: 刚刚看了我的vps,玛德,居然也有人在一直尝试登录,幸好我的密码是强密码
  • thornbird: 又学会一招,不错
  • 头很黑: 除了发送eth转账 ,还能转账其他的代币吗 比如eos
  • 米扑博客: 总结的很棒
  • 米扑博客: 很赞的博客