安装rpm-build软件包
1. [[email protected] ~]# yum -y install rpm-build(建造)
2)生成rpmbuild目录结构
1. [[email protected] ~]# rpmbuild -ba nginx.spec(为了生成下面6个目录 没有其他作用)
2. [[email protected] ~]# ls /root/rpmbuild
3. BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
Chroot +任何目录 都可以将此目录伪装成根
准备工作,将源码软件复制到SOURCES目录
1. [[email protected] ~]# cp nginx-1.8.0.tar.gz /root/rpmbuild/SOURCES/(存放源码包)
4)创建并修改SPEC配置文件
1. [[email protected] ~]# vim SPECS/nginx.spec 自动生成
2. 填空
3. Name:nginx 必须填对
4. Version:1.8.0 必须填对
5. Release: 1%{?dist}
6. Summary:test
7.
8. License:GPL 协议 任意复制 粘贴 修改 转发 具有继承性,改过之后的版本 必须也是开源 否则违法被告 GPL受法律保护
9. URL: www.test.com
10. Source0:nginx-1.8.0.tar.gz必须跟包名一样
11.
12. #BuildRequires: 依赖包
13. #Requires:
14.
15. %description 软件的详细描述
16. test too##########***********随意写
17. 以上属于描述信息
18. ####################################
19.
20. %post
21. sh /root/rpmbuild/SPECS/nginx.sh
22. 可以创建用户 可以echo 可以启动服务等
23. 也可以通过路径指定脚本
24. 写脚本的话路径必须要与下面的路径同步
25. %prep
26. %setup -q 自动tar解包 自动cd进去nginx-1。8
%build
27. ./configure --prefix=/usr/local/nginx --with-http_ssl_module 自己添加模块 需要指定路径
28. make %{?_smp_mflags}
29. %install
30.
31. make install DESTDIR=%{buildroot}
32. mkdir -p %{buildroot}/etc/init.d/
33. install /root/rpmbuild/SPECS/nginx.sh %{buildroot}/etc/init.d/
34. ##注意,这里是将一个脚本拷贝到安装目录,如果没有则不需要该指令
35. install 相当于cp
36. %files
37. %doc
38. /etc/init.d/nginx.sh #将前面拷贝的脚本,打包到RPM中
39. /usr/local/nginx/* 此时的根是buildroot
40.
41. %changelog
步骤二:使用配置文件创建RPM包
1)安装依赖软件包
1. [[email protected] ~]# yum –y install gcc pcre-devel zlib-devel openssl-devel (安全ssl的依赖包)
2)rpmbuild创建RPM软件包
1. [[email protected] ~]# rpmbuild -ba SPECS/nginx.spec
2. [[email protected] ~]# ls RPMS/x86_64/nginx-1.8.0-1.x86_64.rpm
3. [[email protected] ~]# rpm -qpi /root/rpmbuildRPMS/x86_64/nginx-1.8.0-1.x86_64.rpm
4. 查看软件包的详细信息
5. Name : nginx Relocations: (not relocatable)
6. Version : 1.8.0 Vendor: (none)
7. Release : 1 Build Date: Mon 02 May 2016 02:30:53 AM PDT
8. Install Date: (not installed) Build Host: localhost
9. Group : Applications/Internet Source RPM: nginx-1.8.0-1.src.rpm
10. Size : 721243 License: GPL
11. Signature : (none)
12. URL : www.nginx.org
13. Summary : Nginx is a web server software.
14. Description :
15. nginx [engine x] is an HTTP and reverse proxy server, a mail proxy server, and a generic TCP/UDP proxy server, originally written by Igor Sysoev. For a long time, it has been running on many heavily loaded Russian sites including Yandex, Mail.Ru, VK, and Rambler.
16. [[email protected] ~]# rpm -qpl RPMS/x86_64/nginx-1.8.0-1.x86_64.rpm
17. /usr
18. /usr/local
19. /usr/local/nginx
20. /usr/local/nginx/conf
21. /usr/local/nginx/conf/fastcgi.conf
22. /usr/local/nginx/conf/fastcgi.conf.default
23. /usr/local/nginx/conf/fastcgi_params
24. /usr/local/nginx/conf/fastcgi_params.default
25. /usr/local/nginx/conf/koi-utf
26. /usr/local/nginx/conf/koi-win
27. /usr/local/nginx/conf/mime.types
28. /usr/local/nginx/conf/mime.types.default
29. /usr/local/nginx/conf/nginx.conf
30. /usr/local/nginx/conf/nginx.conf.default
31. /usr/local/nginx/conf/scgi_params
32. /usr/local/nginx/conf/scgi_params.default
33. /usr/local/nginx/conf/uwsgi_params
34. /usr/local/nginx/conf/uwsgi_params.default
35. /usr/local/nginx/conf/win-utf
36. /usr/local/nginx/html
37. /usr/local/nginx/html/50x.html
38. /usr/local/nginx/html/index.html
39. /usr/local/nginx/logs
40. /usr/local/nginx/sbin
41. /usr/local/nginx/sbin/nginx
步骤三:安装、卸载软件
1. [[email protected] ~]# rpm -ivh RPMS/x86_64/nginx-1.8.0-1.x86_64.rpm
2. [[email protected] ~]# rpm -qa |grep nginx
3. [[email protected] ~]# /usr/local/nginx/sbin/nginx
4. [[email protected] ~]# curl http://127.0.0.1/
5. [[email protected] ~]# /usr/local/nginx/sbin/nginx -s stop
6. [[email protected] ~]# rpm -e nginx 卸载
可以通过scp将打包好的nginx包传给其他主机
scp /root/rpmbuild/RPMS/x86_64/nginx-1.8.0-1.x86_64.rpm [email protected]:/
新建yum仓库进行yum安装