怎樣將apache和nginx的源碼包轉換爲rpm包?

源代碼轉換

1.準備工做
清空防火牆,iptables -F

httpd-2.2.25.tar.gz(2.2.25的版本)

yum -y install gcc*

2.安裝httpd服務
tar zxf httpd-2.2.25.tar.gz -C /usr/src/
cd /usr/src/httpd-
./configure --prefix=/usr/local/httpd  --enable-so --enable-rewribe  --enable-charset-lite  --enable-sockets --enable-cgi && make && make install

注意:
cd /usr/src/httpd
安裝不會的時候。
而後查看 INSTALL 大寫的都是可閱讀文件 READAM

cd /usr/local/httpd/bin/
cp -p apachectl /etc/init.d
mv apachectl httpd
chmod +x httpd


vim /etc/init.d/network
複製裏邊的兩行
# chkconfig: 2345 10 90
# description: Activates/Deactivates all network interfaces configured to start at boot time.

vim /etc/init.d/httpd
修改:
# chkconfig: 2345 91 91
# description:This is my web——server



計算機的開機啓動級別
cd /etc/rc0.d/
cd /etc/rc1.d/
cd /etc/rc2.d/
cd /etc/rc3.d/
cd /etc/rc4.d/
cd /etc/rc5.d/
k——kill
s——start
將系統服務軟鏈接到開機自啓動3和5級別裏。
ln -s /etc/init.d/httpd /etc/rc3.d/K91httpd
ln -s /etc/init.d/httpd /etc/rc5.d/K91httpd
ln -s /etc/init.d/httpd /etc/rc3.d/S91httpd
ln -s /etc/init.d/httpd /etc/rc5.d/S91httpd

chkconfig --add httpd
chkconfig httpd on
chkconfig httpd --list
service httpd restart

2.root用戶安裝軟件包管理器build
yum -y install rpm-build
rpm -qa | grep rpm-build

3.建立用戶:
useradd li
passwd li

切換用戶:
su - li

**********************************************
4.在root用戶下查看未安裝軟件包的詳細信息

cd /media/cdrom/PACKGES/
rpm -qpi httpd-2.2.25-1.el6.x86_64.rpmnginx


Name        : httpd                        Relocations: (not relocatable)
Version     : 2.2.15                            Vendor: CentOS
Release     : 29.el6.centos                 Build Date: 2013年08月14日 星期三 01時30分33秒
Install Date: (not installed)               Build Host: c6b8.bsys.dev.centos.org
Group       : System Environment/Daemons    Source RPM: httpd-2.2.15-29.el6.centos.src.rpm
Size        : 3076447                          License: ASL 2.0
Signature   : RSA/SHA1, 2013年08月14日 星期三 01時32分39秒, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
URL         : http://httpd.apache.org/
Summary     : Apache HTTP Server
Description :
The Apache HTTP Server is a powerful, efficient, and extensible
web server.


上邊的參數解釋:


名稱:HTTPD重定位:(不可從新定位)

版本:2.2.15供應商:CITOS

發佈日期:27.el6的建造日期:2013,08,14,01,30,33

安裝日期:(未安裝)構建主機:C6B8Bys.DEV.CENTSO.ORG

組:系統環境/守護進程源RPM:HTTPD-2.2.15-27.el6 CENT.SRC.RPM

尺寸:3076447許可證:ASL 2

簽名:RSA/Sa1,2013,08,14,01,32,32,39,鑰匙ID 0946FCA2C105B9DE

打包器:CENTOS構建系統

URL:HTTP:/HTTP.APACHE.Org/

Apache HTTP服務器概述

描述:

Apache HTTP服務器是一種強大的、高效的、可擴展的服務器。

Web服務器。

***************************************************

5.編輯源碼轉換rpm包的文件
vim httpd.spec

Name:httpd

Version:2.2.25    

Release:    1%{?dist}

Summary:Apache HTTP Server    


Group:System Environment/Daemons        

License:GPL

URL:http://httpd.apache.org/        

Source0:httpd-2.2.25.tar.gz

BuildRoot:    %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)

BuildRequires:openssl-devel

Requires:vsftpd



%description
The Apache HTTP Server is a powerful, efficient, and extensible
web server.

%prep

%setup -q




%build

./configure --prefix=/usr/local/myhttpd  --enable-so --enable-rewribe  --enable-charset-lite  --enable-sockets --enable-cgi


make %{?_smp_mflags}



%install

rm -rf %{buildroot}

make install DESTDIR=%{buildroot}




%clean

rm -rf %{buildroot}

%files

%defattr(-,root,root,-)

/usr/local/myhttpd/bin/*

/usr/local/myhttpd/cgi-bin/*

%config /usr/local/myhttpd/conf/*

/usr/local/myhttpd/build/*

/usr/local/myhttpd/error/*

/usr/local/myhttpd/htdocs/*

/usr/local/myhttpd/icons/*

/usr/local/myhttpd/include/*

/usr/local/myhttpd/lib/*

%dir /usr/local/myhttpd/logs

%doc /usr/local/myhttpd/man/*

%doc /usr/local/myhttpd/manual/*

/usr/local/myhttpd/modules/*


%post

ln -s /usr/local/myhttpd/bin/* /usr/local/bin/

cp -p /usr/local/myhttpd/bin/apachectl /etc/init.d/myhttpd

chmod +x /etc/init.d/myhttpd

sed -i '1a #chkconfig: 2345 91 91' /etc/init.d/myhttpd

sed -i '2a # description: haha' /etc/init.d/myhttpd

ln -s /etc/init.d/myhttpd /etc/rc3.d/K92myhttpd

ln -s /etc/init.d/myhttpd /etc/rc5.d/K92myhttpd

ln -s /etc/init.d/myhttpd /etc/rc3.d/S92myhttpd

ln -s /etc/init.d/myhttpd /etc/rc5.d/S92myhttpd

chkconfig --add myhttpd


%preun

/etc/init.d/myhttp stop

chkconfig --del myhttpd

rm -rf /etc/rc3.d/K92myhttpd

rm -rf /etc/rc5.d/K92myhttpd

rm -rf /etc/rc3.d/S92myhttpd

rm -rf /etc/rc5.d/S92myhttpd

rm -rf /etc/init.d/myhttpd

rm -rf /usr/local/myhttpd



%changelog

* Wed May 9 2018 lisir <lisir@redhat.com> 2.2.25-1    //注意:必須和本身系統時間相同

- first rpm from httpd-2.2.25

"httpd.spec" 78L, 1881C



********************************************
5.httpd.spec文件參數解釋:

build requires
生成源碼包的依賴包,必須存在,
編譯是的依賴包 openssl-devel
安裝時候的依賴包 vsftpd

要執行哪一個語句安裝:
&buil
./configure --prefix=/usr/local/myhttpd  --enable-so --enable-rewribe  --enable-charset-lite  --enable-sockets --enable-cgi


%files安裝後生成的文件
cd /usr/local/httpd ls


/usr/local/myhttpd/bin/*
/usr/local/myhttpd/cgi-bin/*
%config /usr/local/myhttpd/conf/*
/usr/local/myhttpd/build/*
/usr/local/myhttpd/error/*
/usr/local/myhttpd/htdocs/*
/usr/local/myhttpd/icons/*
/usr/local/myhttpd/include/*
/usr/local/myhttpd/lib/*
%dir /usr/local/myhttpd/logs
%doc /usr/local/myhttpd/man/*
%doc /usr/local/myhttpd/manual/*
/usr/local/myhttpd/modules/*



安裝完成執行的操做
%post
ln -s /usr/local/myhttpd/bin/* /usr/local/bin/
cp -p /usr/local/myhttpd/bin/apachectl /etc/init.d/myhttpd
chmod +x /etc/init.d/myhttpd
sed -i '1a #chkconfig: 2345 91 91' /etc/init.d/myhttpd
sed -i '2a # description: haha' /etc/init.d/myhttpd
ln -s /etc/init.d/myhttpd /etc/rc3.d/K92myhttpd
ln -s /etc/init.d/myhttpd /etc/rc5.d/K92myhttpd
ln -s /etc/init.d/myhttpd /etc/rc3.d/S92myhttpd
ln -s /etc/init.d/myhttpd /etc/rc5.d/S92myhttpd
chkconfig --add myhttpd

卸載的時候須要的操做
%preun
/etc/init.d/myhttp stop
chkconfig --del myhttpd
rm -rf /etc/rc3.d/K92myhttpd
rm -rf /etc/rc5.d/K92myhttpd
rm -rf /etc/rc3.d/S92myhttpd
rm -rf /etc/rc5.d/S92myhttpd
rm -rf /etc/init.d/myhttpd
rm -rf /usr/local/myhttpd

交換日誌信息時間和日期,必須和本身的系統時間同樣
%changelog
* Wed May 9 2018 lisir <lisir@redhat.com> 2.2.25-1
- first rpm from httpd-2.2.25
"httpd.spec" 78L, 1881C


***************************************************

6.查看交換日誌信息,包含時間日期等,將這個寫到httpd.spec文件裏最後。
cd /media/Packages
rpm -qp  -changelog httpd-2.2.15-29.el6.centos.x86_64.rpm

7.安裝依賴關係包
yum -y install openssl vsftpd

8.執行配置文件,報錯生成路徑,用來複制httpd要修改的源碼包。

[li@localhost ~]$ rpmbuild httpd.spec
error: File /home/li/rpmbuild/SOURCES/httpd-2.2.25.tar.gz: 沒有那個文件或目錄
[li@localhost ~]$ ls
httpd.spec  rpmbuild

9.在root用戶下執行:
cp /root/httpd-2.2.25.tar.gz /home/li/rpmbuild/SOURCES

10.執行轉換文件
rpmbuild -ba httpd.spec

參數解釋:
-ba 生成源碼包和二進制包
-bb 只生成二進制包

11.查看生成的rpm包
cd rpmbuild/RPMS/x86_64/

ls /home/li/rpmbuild/SRPMS
httpd-2.2.25-1.el6.src.rpm

cd rpmbuild/SRPMS/

ls /home/li/rpmbuild/RPMS/x86_64
httpd-2.2.25-1.el6.x86_64.rpm  httpd-debuginfo-2.2.25-1.el6.x86_64.rpm

12.將li用戶生成的rpm轉換包複製到/tmp/目錄下,而後用root用戶執行
cp httpd-2.2.25-1.el6.x86_64.rpm /tmp

13.yum安裝經過編譯轉換的rpm包。
root用戶:
rpm -ivh /root/桌面/httpd-2.2.25-1.el6.x86_64.rpm
service myhttpd restart
firefox 192.168.117.145
看到it work!

*************************************
nginx源碼包轉換爲rpm包,其餘安裝步驟如同apache

yum -y install rpm-build
yum -y install pcre-devel zlib-devel
vim nginx.spec
編輯修改:

Name:nginx    
Version:1.8.1
Release:    1%{?dist}
Summary:nginx service     

Group:System Environment/Daemons
License:GPL
URL:www.nginx.com    
Source0:nginx-1.8.1.tar.gz
BuildRoot:    %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)

BuildRequires:pcre-devel
Requires:vim

%description
this is nginx service


%prep
%setup -q


%build
./configure --prefix=/usr/local/nginx
make %{?_smp_mflags}


%install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}


%clean
rm -rf %{buildroot}


%files
%defattr(-,root,root,0755)
/usr/local/nginx/
%config(noreplace) /usr/local/nginx/conf/nginx.conf
%config(noreplace) /usr/local/nginx/conf/fastcgi_params


%post
echo '#!/bin/bash' > /etc/init.d/nginx
echo '#### welcome to nginx ####' >> /etc/init.d/nginx
echo '# chkconfig: - 99 20' >> /etc/init.d/nginx
echo '# description: this is nginx server' >> /etc/init.d/nginx
echo 'PROG="/usr/local/nginx/sbin/nginx"' >> /etc/init.d/nginx
echo 'PIDF="/usr/local/nginx/logs/nginx.pid"' >> /etc/init.d/nginx
echo 'case "$1" in' >> /etc/init.d/nginx
echo ' start)' >> /etc/init.d/nginx
echo ' $PROG' >> /etc/init.d/nginx
echo ' ;;' >> /etc/init.d/nginx
echo ' stop)' >> /etc/init.d/nginx
echo ' kill -s QUIT $(cat $PIDF)' >> /etc/init.d/nginx
echo ' ;;' >> /etc/init.d/nginx
echo ' restart)' >> /etc/init.d/nginx
echo ' $0 stop' >> /etc/init.d/nginx
echo ' $0 start' >> /etc/init.d/nginx
echo ' ;;' >> /etc/init.d/nginx
echo ' reload)' >> /etc/init.d/nginx
echo ' kill -s HUP $(cat $PIDF)' >> /etc/init.d/nginx
echo ' ;;' >> /etc/init.d/nginx
echo ' *)' >> /etc/init.d/nginx
echo ' echo "Usage: $0 {start|stop|restart|status}"' >> /etc/init.d/nginx
echo ' exit' >> /etc/init.d/nginx
echo ' ;;' >> /etc/init.d/nginx
echo ' esac' >> /etc/init.d/nginx
echo ' exit 0' >> /etc/init.d/nginx
chmod +x /etc/init.d/nginx
service nginx start
chkconfig --add nginx
chkconfig nginx on


%preun
/etc/init.d/nginx stop
chkconfig --del nginx
rm -rf /etc/init.d/httpd
rm -rf /usr/local/httpd

%changelog
* Wed May 9 2018 lipengcheng <930777521@qq.com> 1.8.1
- first rpm from nginx-1.8.1web

 

執行轉換配置文件:
rpmbuild nginx.spec
cp nginx-1.8.1.tar.gz /root/rpmbuild/SOURCES/
rpmbuild -ba nginx.spec


cd rpmbuild/SRPMS/
ls      

cd rpmbuild/RPMS/x86_64/
ls
 
rpm -ivh nginx-1.8.1-1.el6.x86_64.rpm
service nginx restart
netstat -anpt | grep nginx
firefox 192.168.117.145



apache

相關文章
相關標籤/搜索