安装编译需要的gcc gcc-c++ 和rpmbuild
[root@LookBack-Node ~]# yum install gcc gcc-c++ rpm-build
添加个普通用户
[root@LookBack-Node ~]# name=rpmbuild [root@LookBack-Node ~]# useradd $name
设定普通用户的rpmbuild根目录
[root@LookBack-Node ~]# echo "%_topdir /home/$name/rpmbuild" >> /home/$name/.rpmmacros [root@LookBack-Node ~]# chown $name.$name /home/$name/.rpmmacros
添加sudo权限
[root@LookBack-Node ~]# echo "$name ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers [root@LookBack-Node ~]# su - $name
创建必要的目录
[rpmbuild@LookBack-Node ~]$ mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS} [rpmbuild@LookBack-Node ~]$ rpmbuild --showrc | grep _topdir -14: _builddir %{_topdir}/BUILD -14: _buildrootdir %{_topdir}/BUILDROOT -14: _rpmdir %{_topdir}/RPMS -14: _sourcedir %{_topdir}/SOURCES -14: _specdir %{_topdir}/SPECS -14: _srcrpmdir %{_topdir}/SRPMS -14: _topdir /home/rpmbuild/rpmbuild [rpmbuild@LookBack-Node ~]$ cd rpmbuild/SOURCES/
下载Nginx的src rpm包
[rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ wget http://nginx.org/packages/mainline/centos/7/SRPMS/nginx-1.9.9-1.el7.ngx.src.rpm
解包
[rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ rpm2cpio nginx-1.9.9-1.el7.ngx.src.rpm |cpio -dvi [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ ls COPYRIGHT nginx-1.9.9-1.el7.ngx.src.rpm nginx.conf nginx-debug.sysconf nginx.service nginx.suse.logrotate nginx.upgrade.sh logrotate nginx-1.9.9.tar.gz nginx-debug.service nginx.init.in nginx.spec nginx.sysconf nginx.vh.default.conf
给Nginx源码包添加自己需要的东西,这里我加了三个模块
[rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ tar xf nginx-1.9.9.tar.gz [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ cd nginx-1.9.9/ [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES/nginx-1.9.9]$ git clone https://github.com/aperezdc/ngx-fancyindex.git [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES/nginx-1.9.9]$ git clone https://github.com/cuber/ngx_http_google_filter_module.git [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES/nginx-1.9.9]$ git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module.git [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES/nginx-1.9.9]$ cd ..
将新的源码目录打包
[rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ tar zcf nginx-1.9.9.tar.gz nginx-1.9.9/ [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ tar zcf nginx-1.9.9.tar.gz nginx-1.9.9 [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ rm -rf nginx-1.9.9
备份原有的spec,下载新的spec,当然这里自己重新写也是可以的
[rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ mv nginx.spec{,_bak} [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ wget http://www.dwhd.org/wp-content/uploads/2015/12/nginx.spec
对必备文件做适量修改让其适配我们自己的spec文件
[rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ sed -i 's@/usr/sbin/nginx@/usr/local/nginx/sbin/nginx@' nginx-debug.service nginx-debug.sysconf nginx.service nginx.sysconf nginx.upgrade.sh [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ sed -i 's@/etc/nginx@/usr/local/nginx/conf@' nginx-debug.service nginx-debug.sysconf nginx.init.in nginx.service nginx.sysconf nginx.upgrade.sh nginx.conf [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ sed -i 's@/usr/share/nginx/html@/data/wwwroot/default@' nginx.vh.default.conf [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ sed -ri 's/^(user).*/\1 www;/;s/^(worker_processes).*/\1 auto;/' nginx.conf [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ sed -ri 's@^(\s+include).*@\1 vhost/*.conf;@' nginx.conf [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ sed -i 's@/usr/sbin/%PROVIDES%@/usr/local/nginx/sbin/%PROVIDES%@' nginx.init.in
开始构建rpm包,当系统环境缺少这些依赖的时候会做提示
[rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ rpmbuild -ba nginx.spec 错误:构建依赖失败: openssl-devel >= 1.0.1 被 nginx-1:1.9.9-2.el7.centos.ngx.x86_64 需要 zlib-devel 被 nginx-1:1.9.9-2.el7.centos.ngx.x86_64 需要 pcre-devel 被 nginx-1:1.9.9-2.el7.centos.ngx.x86_64 需要 gd-devel 被 nginx-1:1.9.9-2.el7.centos.ngx.x86_64 需要 [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ sudo yum install -y openssl-devel zlib-devel pcre-devel gd-devel [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ rpmbuild -ba nginx.spec
安装自己制作的rpm包
[rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ sudo yum install -y /home/rpmbuild/rpmbuild/RPMS/x86_64/nginx-1.9.9-2.el7.centos.ngx.x86_64.rpm
安装好之后来看看具体情况
[rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ . /etc/profile.d/nginx.sh [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ which nginx /usr/local/nginx/sbin/nginx [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ yum list all |grep nginx.*@ nginx.x86_64 1:1.9.9-2.el7.centos.ngx @/nginx-1.9.9-2.el7.centos.ngx.x86_64 [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ nginx -V nginx version: nginx/1.9.9 built by gcc 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013 TLS SNI support enabled configure arguments: --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=www --group=www --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_image_filter_module --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_v2_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --add-module=ngx_http_substitutions_filter_module --add-module=ngx_http_google_filter_module --add-module=ngx-fancyindex [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ rpm -qi nginx Name : nginx Epoch : 1 Version : 1.9.9 Release : 2.el7.centos.ngx Architecture: x86_64 Install Date: 2015年12月11日 星期五 01时03分20秒 Group : System Environment/Daemons Size : 2215625 License : 2-clause BSD-like license Signature : (none) Source RPM : nginx-1.9.9-2.el7.centos.ngx.src.rpm Build Date : 2015年12月11日 星期五 00时59分25秒 Build Host : LookBack-Node.dwhd.org Relocations : (not relocatable) Vendor : nginx inc. URL : http://nginx.org Summary : High performance web server Description : nginx [engine x] is an HTTP and reverse proxy server, as well as a mail proxy server. add : --with-http_v2_module \ --with-http_image_filter_module \ --add-module=ngx_http_google_filter_module \ --add-module=ngx_http_substitutions_filter_module \ --add-module=ngx-fancyindex [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ rpm -ql nginx /data/wwwroot/default /data/wwwroot/default/50x.html /data/wwwroot/default/index.html /etc/logrotate.d/nginx /usr/lib/systemd/system/nginx-debug.service /usr/lib/systemd/system/nginx.service /usr/libexec/initscripts/legacy-actions/nginx /usr/libexec/initscripts/legacy-actions/nginx/upgrade /usr/local/nginx /usr/local/nginx/conf /usr/local/nginx/conf/fastcgi.conf.default /usr/local/nginx/conf/fastcgi_params /usr/local/nginx/conf/fastcgi_params.default /usr/local/nginx/conf/koi-utf /usr/local/nginx/conf/koi-win /usr/local/nginx/conf/mime.types /usr/local/nginx/conf/mime.types.default /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.default /usr/local/nginx/conf/scgi_params /usr/local/nginx/conf/scgi_params.default /usr/local/nginx/conf/uwsgi_params /usr/local/nginx/conf/uwsgi_params.default /usr/local/nginx/conf/vhost /usr/local/nginx/conf/vhost/default.conf /usr/local/nginx/conf/win-utf /usr/local/nginx/doc/nginx-1.9.9 /usr/local/nginx/doc/nginx-1.9.9/COPYRIGHT /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx-debug /usr/local/sysconfig/nginx /usr/local/sysconfig/nginx-debug /var/cache/nginx /var/log/nginx [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$
启动试试
[rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ sudo systemctl enable nginx.service ln -s '/usr/lib/systemd/system/nginx.service' '/etc/systemd/system/multi-user.target.wants/nginx.service' [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ sudo systemctl start nginx.service [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ sudo systemctl status nginx.service nginx.service - nginx - high performance web server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled) Active: active (running) since 五 2015-12-11 01:41:27 CST; 5s ago Docs: http://nginx.org/en/docs/ Process: 43638 ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS) Process: 43636 ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS) Main PID: 43640 (nginx) CGroup: /system.slice/nginx.service ├─43640 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf ├─43641 nginx: worker process └─43642 nginx: worker process 12月 11 01:41:27 LookBack-Node.dwhd.org systemd[1]: Starting nginx - high performance web server... 12月 11 01:41:27 LookBack-Node.dwhd.org nginx[43636]: nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored 12月 11 01:41:27 LookBack-Node.dwhd.org nginx[43636]: nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok 12月 11 01:41:27 LookBack-Node.dwhd.org nginx[43636]: nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful 12月 11 01:41:27 LookBack-Node.dwhd.org nginx[43638]: nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored 12月 11 01:41:27 LookBack-Node.dwhd.org systemd[1]: Started nginx - high performance web server. [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$ curl localhost <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html> [rpmbuild@LookBack-Node ~/rpmbuild/SOURCES]$
CentOS 6 上测试
[root@02748dd85f09 /]# rpm -qi nginx Name : nginx Relocations: (not relocatable) Version : 1.9.9 Vendor: nginx inc. Release : 2.el6.ngx Build Date: Thu Dec 10 23:27:58 2015 Install Date: Thu Dec 10 23:28:33 2015 Build Host: 02748dd85f09 Group : System Environment/Daemons Source RPM: nginx-1.9.9-2.el6.ngx.src.rpm Size : 2145548 License: 2-clause BSD-like license Signature : (none) URL : http://nginx.org Summary : High performance web server Description : nginx [engine x] is an HTTP and reverse proxy server, as well as a mail proxy server. add : --with-http_v2_module \ --with-http_image_filter_module \ --add-module=ngx_http_google_filter_module \ --add-module=ngx_http_substitutions_filter_module \ --add-module=ngx-fancyindex [root@02748dd85f09 /]#
文件
您可以选择一种方式赞助本站
支付宝扫一扫赞助
微信钱包扫描赞助
赏