CentOS   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了CentOS 7 Build Tengine RPM Package大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

安装rpmbuild工具及tENGIne编译环境 yum -y install rpmdevtools yum -y install rpm-build wget make m4 gcc-c++ autoconf automake lua-devel pcre-devel libxml2-devel gd-devel perl-ExtUtils-Embed libxslt-devel GeoI

安装rpmbuild工具及tENGIne编译环境

yum -y install rpmdevtools
yum -y install rpm-build wget make m4 gcc-c++ autoconf automake lua-devel  pcre-devel  libxml2-devel gd-devel perl-ExtUtils-Embed libxslt-devel GeoIP-devel openssl-devel

建立普通用户,在普通用户下进行包的制作

这样防止制作包的过程中出错造成对系统的影响

useradd knmax
su - knmax

生成rpmbuild目录结构

这个也可以手动去创建目录,当然使用命令更方便

$ rpmdev-setuptree
$ tree rpmbuild/
rpmbuild/
├── BUILD   //打包过程中的工作目录
├── RPMS    //存放生成的二进制包
├── sourcES  //打包资源,源码补丁文件
├── SPECS  //spec文档
└── SRPMS  //存放生成的源码包

注意:如果需要改变次认位置,可以修改配置文件:~/.rpmmacros中变量_topdir对应的值即可

获取源码、配置文件、服务启动脚本、主页放入sourcE目录

$ cd rpmbuild/sourcES/
$ wget http://tENGIne.taobao.org/download/tENGIne-2.2.0.tar.gz
$ ls rpmbuild/sourcES/
index.html  init.Nginx  Nginx.conf  Nginx.logrotate  tENGIne-2.2.0.tar.gz

文件内容

Nginx.conf

user  Nginx;
worker_processes  auto;

error_log  /var/log/Nginx/error.log warn;
pid        /var/run/Nginx.pid;


events {
    worker_connections  1024;
    use epoll;
    multi_accept on;
}


http {
    include       /etc/Nginx/mime.types;
    default_type  application/octet-stream;

    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 50m;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forWARDed_for"';

    access_log  /var/log/Nginx/access.log  main;

    sendfile        on;
    tcp_nopush     on;
    server_tokens off;
    keepalive_timeout  65;

    gzip  on;
    gzip_min_length  1k;
    gzip_buffers    4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types      text/plain application/x-javascript text/css application/xml;
    gzip_vary on;

    charset utf-8;

    server {
        listen       80;
        server_name  localhost;

        LOCATIOn / {
            root   html;
            index  index.html index.htm;
        }
    }
    include /etc/Nginx/conf.d/*.conf;
}

init.Nginx

[Unit]
Description=Nginx - high perfoRMANce web server
Documentation=http://Nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[service]
Type=forking
PIDFile=/var/run/Nginx.pid
ExecStartPre=/usr/sbin/Nginx -t -c /etc/Nginx/Nginx.conf
ExecStart=/usr/sbin/Nginx -c /etc/Nginx/Nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Nginx.logrotate

/var/log/Nginx/*log {
    daily
    rotate 10
    missingok
    notifempty
    compress
    sharedscripts
    postrotate
        /bin/kill -USR1 $(cat /var/run/Nginx.pid 2>/dev/null) 2>/dev/null || :
    endscript
}

index.html

<h1>This is knmax_tENGIne test page</h1>

编写spec文件

$ vim SPECS/tENGIne.spec
%define Nginx_user      Nginx
%define Nginx_group     %{Nginx_user}
%define Nginx_home      %{_localstatedir}/lib/Nginx
%define Nginx_home_tmp  %{Nginx_homE}/tmp
%define Nginx_logdir    %{_localstatedir}/log/Nginx
%define Nginx_confdir   %{_sysconfdir}/Nginx
%define Nginx_datadir   /var/www
%define Nginx_webroot   %{Nginx_datadir}/html

Name:           tENGIne
Version:        2.2.0
Release:        1%{?dist}
SumMary:        small and High PerfoRMANce http and Reverse Proxy Server
Group:          System Environment/Daemons
License:        BSD
URL:            http://knmax.com
buildroot:      %{_tmppath}/Nginx-%{version}-%{releasE}-root-%(%{__id_u} -n)
Packager:       Ron<[email protected]>

buildrequires:  pcre-devel,zlib-devel,perl,perl(ExtUtils::Embed),libxslt-devel,GeoIP-devel,gd-devel
requires:       pcre,openssl,GeoIP,gd,perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $version))
# for /usr/sbin/useradd
requires(prE):      shadow-utils
#requires(post):     chkconfig
requires(post):     systemd
# for /sbin/service
#requires(preun):    chkconfig,initscripts
#requires(postun):   initscripts
requires(preun):    systemd
requires(postun):   systemd

source0:    %{name}-%{version}.tar.gz
source1:    init.Nginx
source2:    Nginx.logrotate
source3:        Nginx.conf
source100:      index.html
%description
Nginx [ENGIne x] is an http(S) server,http(S) reverse proxy and IMAP/POP3
proxy server

%prep
%setup -q

%build
export DESTDIR=%{buildroot}
./configure     --user=%{Nginx_user}     --group=%{Nginx_group}     --prefix=%{Nginx_datadir}     --sbin-path=%{_sbindir}/Nginx     --conf-path=%{Nginx_confdir}/Nginx.conf     --error-log-path=%{Nginx_logdir}/error.log     --http-log-path=%{Nginx_logdir}/access.log     --http-client-body-temp-path=%{Nginx_home_tmp}/clienT_Body     --http-proxy-temp-path=%{Nginx_home_tmp}/proxy     --http-fastcgi-temp-path=%{Nginx_home_tmp}/fastcgi     --http-uwsgi-temp-path=%{Nginx_home_tmp}/uwsgi     --http-scgi-temp-path=%{Nginx_home_tmp}/scgi     --pid-path=%{_localstatedir}/run/Nginx.pid     --lock-path=%{_localstatedir}/lock/subsys/Nginx     --with-http_ssl_module     --with-http_realip_module     --with-http_addition_module     --with-http_xslt_module     --with-http_image_filter_module     --with-http_geoip_module     --with-http_sub_module     --with-http_dav_module     --with-http_flv_module     --with-http_gzip_static_module     --with-http_random_index_module     --with-http_secure_link_module     --with-http_degradation_module     --with-http_stub_status_module     --with-http_perl_module     --with-file-aio     --with-cc-opt="%{optflags} $(pcre-config --cflags)"     --with-ld-opt="-Wl,-E" # so the perl module finds its symbols
make %{?_smp_mflags}



%install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot} INSTALLDIRS=vendor
find %{buildroot} -type f -name .packlist -exec rm -f {} \;
find %{buildroot} -type f -name perllocal.pod -exec rm -f {} \;
find %{buildroot} -type f -empty -exec rm -f {} \;
find %{buildroot} -type f -exec chmod 0644 {} \;
find %{buildroot} -type f -name '*.so' -exec chmod 0755 {} \;
chmod 0755 %{buildroot}%{_sbindir}/Nginx
#%{__install} -p -D -m 0755 %{sourcE1} %{buildroot}%{_initrddir}/Nginx
%{__install} -p -D -m 0755 %{sourcE1} %{buildroot}%{_unitdir}/Nginx.service
%{__install} -p -D -m 0644 %{sourcE2} %{buildroot}%{_sysconfdir}/logrotate.d/Nginx
%{__install} -p -d -m 0755 %{buildroot}%{Nginx_confdir}/conf.d
%{__install} -p -d -m 0755 %{buildroot}%{Nginx_home_tmp}
%{__install} -p -d -m 0755 %{buildroot}%{Nginx_logdir}
%{__install} -p -d -m 0755 %{buildroot}%{Nginx_webroot}
%{__install} -p -m 0644 %{sourcE100} %{buildroot}%{Nginx_webroot}
%{__install} -p -m 0755 %{sourcE3} %{buildroot}%{Nginx_confdir}

%clean
rm -rf %{buildroot}

%pre
if [ $1 == 1 ]; then
    %{_sbindir}/useradd -c "Nginx user" -s /bin/false  %{Nginx_user} 2>/dev/null
    %{_bindir}/mkdir %{Nginx_datadir} 2>/dev/null
fi

%post
if [ $1 == 1 ]; then
#    /sbin/chkconfig --add Nginx
     %{_bindir}/systemctl daemon-reload >/dev/null 2>&1 || :
     %{_bindir}/systemctl enable Nginx >/dev/null 2>&1 || :
     %{_bindir}/systemctl starx Nginx >/dev/null 2>&1 || :
fi

%preun
if [ $1 = 0 ]; then
     %{_bindir}/systemctl stop Nginx >/dev/null 2>&1 || :
     %{_bindir}/systemctl disabled Nginx >/dev/null 2>&1 || :
fi

%postun
if [ $1 == 2 ]; then
     %{_bindir}/systemctl restart Nginx || :
fi

%files
%defattr(-,root,-)
%doc LICENSE CHANGES README
%{Nginx_datadir}/
%{_sbindir}/Nginx
%{_mandir}/man3/Nginx.3pm.gz
#%{_initrddir}/Nginx
%{_unitdir}/Nginx.service
%dir %{Nginx_confdir}
%dir %{Nginx_confdir}/conf.d
%dir %{Nginx_logdir}
%config(noreplacE) %{Nginx_confdir}/win-utf
%config(noreplacE) %{Nginx_confdir}/Nginx.conf.default
%config(noreplacE) %{Nginx_confdir}/mime.types.default
%config(noreplacE) %{Nginx_confdir}/fastcgi.conf
%config(noreplacE) %{Nginx_confdir}/fastcgi.conf.default
%config(noreplacE) %{Nginx_confdir}/fastcgi_params
%config(noreplacE) %{Nginx_confdir}/fastcgi_params.default
%config(noreplacE) %{Nginx_confdir}/scgi_params
%config(noreplacE) %{Nginx_confdir}/scgi_params.default
%config(noreplacE) %{Nginx_confdir}/uwsgi_params
%config(noreplacE) %{Nginx_confdir}/uwsgi_params.default
%config(noreplacE) %{Nginx_confdir}/koi-win
%config(noreplacE) %{Nginx_confdir}/koi-utf
%config(noreplacE) %{Nginx_confdir}/Nginx.conf
%config(noreplacE) %{Nginx_confdir}/mime.types
%config(noreplacE) %{Nginx_confdir}/browsers
%config(noreplacE) %{Nginx_confdir}/module_stubs
%config(noreplacE) %{_sysconfdir}/logrotate.d/Nginx
%doc %{Nginx_webroot}/index.html
%dir %{perl_vendorarch}/auto/Nginx
%{perl_vendorarch}/Nginx.pm
%{perl_vendorarch}/auto/Nginx/Nginx.so
%attr(-,%{Nginx_user},%{Nginx_group}) %dir %{Nginx_webroot}
%attr(-,%{Nginx_group}) %dir %{Nginx_homE}
%attr(-,%{Nginx_group}) %dir %{Nginx_home_tmp}

%changelog
 * Fri Jul 7 2017 <[email protected]> - 2.2.0
- initial package

常用路径及宏变量:https://fedoraproject.org/wiki/Packaging:RPMMacros?rd=Packaging/RPMMacros#RPM_directory_macros
也可以通过rpmbuild --showrc查看

打包生成rpm包

$ rpmbuild -ba SPECS/tENGIne.spec
$ ls RPMS/x86_64/tENGIne-*
RPMS/x86_64/tENGIne-2.2.0-1.el7.centos.x86_64.rpm  RPMS/x86_64/tENGIne-debuginfo-2.2.0-1.el7.centos.x86_64.rpm
$ ls SRPMS/
tENGIne-2.2.0-1.el7.centos.src.rpm

安装rpm包

# rpm -ivh /home/knmax/rpmbuild/RPMS/x86_64/tENGIne-2.2.0-1.el7.centos.x86_64.rpm
# rpm -qi tENGIne
Name        : tENGIne
Version     : 2.2.0
Release     : 1.el7.centos
Architecture: x86_64
Install Date: Sat 08 Jul 2017 12:27:57 AM CST
Group       : System Environment/Daemons
Size        : 1586558
License     : BSD
Signature   : (nonE)
source RPM  : tENGIne-2.2.0-1.el7.centos.src.rpm
Build Date  : Sat 08 Jul 2017 12:26:48 AM CST
Build Host  : localhost
ReLOCATIOns : (not relocatablE)
Packager    : Ron<[email protected]>
URL         : http://knmax.com
SumMary     : small and High PerfoRMANce http and Reverse Proxy Server
Description :
Nginx [ENGIne x] is an http(S) server,http(S) reverse proxy and IMAP/POP3
proxy server

为rpm包签名

生成GPG签名密钥

# gpg --gen-key  一路操作下去就行

查看生成的密钥

# gpg --list-keys
/root/.gnupg/pubring.gpg
------------------------
pub   2048R/176DC0D0 2017-07-07 [expires: 2018-07-07]
uid                  KNAMX (GPG-RPM-KEY) <[email protected]>
sub   2048R/3F02B01C 2017-07-07 [expires: 2018-07-07]

导出公钥

# gpg --export -a "KNAMX" > RPM-GPG-KEY-KNMAX

编缉 .rpmmacros说明我们用哪一个密钥加密,我们用root加密的那就在/root下编辑

# vim ~/.rpmmacros
%_gpg_name KNAMX

为rpm包加签名

# yum install rpm-sign
# rpm --addsign /home/knmax/rpmbuild/RPMS/x86_64/tENGIne-2.2.0-1.el7.centos.x86_64.rpm
Enter pass phrase:
Pass phrase is good.
/home/knmax/rpmbuild/RPMS/x86_64/tENGIne-2.2.0-1.el7.centos.x86_64.rpm:

导入公钥,检查rpm包

# rpm --import RPM-GPG-KEY-KNMAX
# rpm --checksig /home/knmax/rpmbuild/RPMS/x86_64/tENGIne-2.2.0-1.el7.centos.x86_64.rpm
/home/knmax/rpmbuild/RPMS/x86_64/tENGIne-2.2.0-1.el7.centos.x86_64.rpm: rsa sha1 (md5) pgp md5 OK

重新安装软件包,查看信息

# rpm -e tENGIne
# rpm -ivh /home/knmax/rpmbuild/RPMS/x86_64/tENGIne-2.2.0-1.el7.centos.x86_64.rpm
# rpm -qi tENGIne
Name        : tENGIne
Version     : 2.2.0
Release     : 1.el7.centos
Architecture: x86_64
Install Date: Sat 08 Jul 2017 01:41:37 AM CST
Group       : System Environment/Daemons
Size        : 1586558
License     : BSD
Signature   : RSA/SHA1,Sat 08 Jul 2017 01:36:35 AM CST,Key ID 1893bb30176dc0d0
source RPM  : tENGIne-2.2.0-1.el7.centos.src.rpm
Build Date  : Sat 08 Jul 2017 12:26:48 AM CST
Build Host  : localhost
ReLOCATIOns : (not relocatablE)
Packager    : Ron<[email protected]>
URL         : http://knmax.com
SumMary     : small and High PerfoRMANce http and Reverse Proxy Server
Description :
Nginx [ENGIne x] is an http(S) server,http(S) reverse proxy and IMAP/POP3
proxy server

大佬总结

以上是大佬教程为你收集整理的CentOS 7 Build Tengine RPM Package全部内容,希望文章能够帮你解决CentOS 7 Build Tengine RPM Package所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。