CentOS 7 Build Tengine RPM Package

2022年 10月 18日 发表评论
免费、便宜/高性价比 服务器汇总(已更新):点击这里了解

本站教程收集整理的这篇文章主要介绍了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 GeoIP-devel openssl-devel

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

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

useradd knmax  su - knmax

生成rpmbuild目录结构

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

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

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

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

$ cd rpmbuild/@R_874_9016@ES/  $ wget http://tENGIne.taobao.org/download/tENGIne-2.2.0.tar.gz  $ ls rpmbuild/@R_874_9016@ES/  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<[emailprotected]>    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    @R_874_9016@e0:    %{name}-%{version}.tar.gz  @R_874_9016@e1:    init.Nginx  @R_874_9016@e2:    Nginx.logrotate  @R_874_9016@e3:        Nginx.conf  @R_874_9016@e100:      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 %{@R_874_9016@E1} %{Buildroot}%{_initrddir}/Nginx  %{__install} -p -D -m 0755 %{@R_874_9016@E1} %{Buildroot}%{_unitdir}/Nginx.service  %{__install} -p -D -m 0644 %{@R_874_9016@E2} %{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 %{@R_874_9016@E100} %{Buildroot}%{Nginx_webroot}  %{__install} -p -m 0755 %{@R_874_9016@E3} %{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 <[emailprotected]> - 2.2.0  - initial package

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

@H_489_55@打包生成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)  @R_874_9016@e 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<[emailprotected]>  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) <[emailprotected]>  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  @R_874_9016@e 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<[emailprotected]>  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所遇到的程序开发问题。

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

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

小咸鱼

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: