rpm包的制作真几把烦,制作php的rpm花了我3天时间,因为是根据线上环境来做的,依赖的第三方库太多,本来想把所有的第三方库做进php包,后来发现在rpmbuild -bb的时候非常耗时,而且乱七八糟的错满天飞,好不容易全部解决了第一次成功第二次又不行了,因此决定能用yum安装的就用yum安装,没有的才用源码。

1、安装rpm-build和rpmdevtools

  yum install rpmdevtools rpm-build

2、生成制作rpm包的必备目录,没有安装rpmdevtools则无法使用以下命令

  cd ~

  rpmdev-setuptree

  此时,你的家目录中有一个rpmbuild文件夹,里面有5个文件夹,分别是SPEC,SOURCE,RPMS,BUILD,SRPMS。spec文件夹存放书写生成rpm包的文件,rpms存放生成的rpm包,build存放生成rpm包过程中产生的文件,SRPMS存放srpm包,source存放源码文件和你要装入系统的文件

3、生成过程

  将nginx/php的源码包、配置文件,init.d中的启动文件放入source目录下,进入spec文件夹,写spec文件

  nginx.spec

%define nginx_user nginx
#after compile no dependies check
AutoReqProv: no Name: tengine
Version: 2.1.
Release: %{?dist}
Summary: Tengine from taobao Group: System Environment/Daemons
License: GPLv2
URL: http://www.nginx.org/downloads/nginx-1.2.1.tar.gz
Source0: %{name}-%{version}.tar.gz
Source1: tengine.init
#Source2: pcre-8.32.tar.gz
BuildRoot: %{_topdir}/BUILDROOT/%{name}-%{version}-%{release} BuildRequires: gcc,make
#Requires: pcre,pcre-devel,openssl,openssl-devel,zlib,zlib-devel
#Requires(post): info
#Requires(preun):info
%description
nginx from taobao %prep
%setup -q %build export DESTDIR=%{buildroot}
./configure\
--prefix=/usr/local/sina_mobile/tengine\
--sbin-path=/usr/local/sina_mobile/tengine/sbin/nginx\
--conf-path=/usr/local/sina_mobile/tengine/conf/nginx.conf\
--error-log-path=/usr/local/sina_mobile/tengine/logs/error.log\
--http-log-path=/usr/local/sina_mobile/tengine/logs/access.log\
--pid-path=/usr/local/sina_mobile/tengine/logs/nginx.pid\
--http-client-body-temp-path=/usr/local/sina_mobile/tengine/client_body_temp \
--http-proxy-temp-path=/usr/local/sina_mobile/tengine/proxy_temp \
--http-fastcgi-temp-path=/usr/local/sina_mobile/tengine/fcgi_temp \
--http-uwsgi-temp-path=/usr/local/sina_mobile/tengine/uwsgi_temp \
--http-scgi-temp-path=/usr/local/sina_mobile/tengine/scgi_temp \
--user=%{nginx_user}\
--group=%{nginx_user}\
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_realip_module\
--with-pcre=/usr/local/src/pcre-8.32\
--with-openssl=/usr/local/src/openssl-1.0.1t\
--with-zlib=/usr/local/src/zlib-1.2.
# --with-pcre
make %{?_smp_mflags} %install
rm -rf %{buildroot}%{_infodir}/dir
make install DESTDIR=%{buildroot}
install -p -D -m %{SOURCE1} %{buildroot}/etc/rc.d/init.d/nginx
#install -p -D -m %{SOURCE2} %{buildroot}/usr/local/src/pcre-8.32.tar.gz
#install -p -d -m %{buildroot}/usr/local/nginx/sbin
#install -p -d -m %{buildroot}/usr/local/nginx/conf
#install -p -d -m %{buildroot}/usr/local/nginx/log %pre
if [ $ == ];then
/usr/sbin/useradd -s /bin/false -r %{nginx_user} >/dev/null || :
fi %post
if [ $ == ];then
/sbin/chkconfig --add nginx
/sbin/install-info %{_infodir}/%{name}.info %{_infodir}/dir >/dev/null || :
fi
%preun
if [ $ == ];then
/sbin/service nginx stop > /dev/null >&
/sbin/chkconfig --del nginx
/usr/sbin/userdel -r %{nginx_user} > /dev/null
/sbin/install-info --delete %{_infodir}/%{name}.info %{_infodir}/dir >/dev/null || :
fi %postun
rm -rf /usr/local/sina_mobile/tengine/sbin
rm -rf /usr/local/sina_mobile/tengine/conf
rm -rf /usr/local/sina_mobile/tengine/*_temp
rm -rf /usr/local/sina_mobile/tengine/include
rm -rf /usr/local/sina_mobile/tengine/html
rm -rf /usr/local/sina_mobile/tengine/modules
#rm -rf /usr/local/src/pcre-8.32
rm -f /etc/rc.d/init.d/nginx %clean
rm -rf %{buildroot} %files
%defattr(-,root,root,-)
#/usr/local/src/pcre-8.32
/usr/local/sina_mobile/tengine/*
%attr(0755,root,root) /etc/rc.d/init.d/nginx %changelog
* Fri Jul 5 2016 laoguang <weijing@qq.com> - 2.1.2-1.el6
- Initial version

rpmbuild -bb nginx.spec即可生成rpm包

php.spec

%define         php_path        /usr/local/sina_mobile/phpfpm538
%define dep_path /usr/local/sina_mobile
%define debug_package %{nil}
#AutoReq: 0          #阻止rpm自动解析需要的依赖,当你确定你使用的库都会在本文件中安装,则可以使用此选项
#AutoProv: 0          #阻止rpm自动解析提供的依赖 Name: php
Version: 5.3.
Release: %{?dist}
Summary: PHP is a server-side scripting language for creating dynamic Web page
Group: System Environment/Daemons
License: GPLv2
URL: http://www.php.net/downloads/php-5.3.8.tar.gz
Source0: %{name}-%{version}.tar.gz
Source1: libiconv-1.14.tar.gz
#Source2: libxml2-2.7..tar.gz
Source3: libpng-1.5..tar.gz
Source4: freetype-2.4..tar.gz
Source5: libmcrypt-2.5..tar.gz
Source6: gd-2.0..tar.gz
#Source7: mysql-5.5..tar.gz
Source8: jpegsrc.v8d.tar.gz
Source9: php-fpm
Source10: php-fpm.conf
BuildRoot: %{_topdir}/BUILDROOT/%{name}-%{version}-%{release}
BuildRequires: gcc,gcc-c++,make,cmake,ncurses-devel,bison,openssl-devel,libcurl-devel,gdbm-devel,openldap-devel,libtidy-devel,zlib-devel,libxml2-devel,libpng-devel
#Requires: libtool,gd-devel,mhash
%description
PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. %prep
%setup -q -b -b -b -b -b -b %build
cd ../jpeg-8d
./configure --prefix=%{dep_path}/jpeg
make %{?_smp_mflags} cd ../libpng-1.5.
./configure --prefix=%{dep_path}/libpng
CFLAGS="-O3 -fPIC"
make %{?_smp_mflags} cd ../freetype-2.4.
./configure --prefix=%{dep_path}/freetype
CFLAGS="-O3 -fPIC"
make %{?_smp_mflags} cd ../gd-2.0.
./configure --prefix=%{dep_path}/gd --with-jpeg=%{dep_path}/jpeg --with-freetype=%{dep_path}/freetype --with-png=%{dep_path}/libpng
CFLAGS="-O3 -fPIC"
make %{?_smp_mflags} cd ../libiconv-1.14
./configure --prefix=%{dep_path}/libiconv
CFLAGS="-O3 -fPIC"
make %{?_smp_mflags} #cd ../libxml2-2.7.
#./configure --prefix=%{dep_path}/libxml2
#CFLAGS="-O3 -fPIC"
#make %{?_smp_mflags} #cd ../mysql-5.5.
#cmake -DCMAKE_INSTALL_PREFIX=%{dep_path}/mysql
#make %{?_smp_mflags} cd ../libmcrypt-2.5.
./configure --prefix=%{dep_path}/libmcrypt
CFLAGS="-O3 -fPIC"
make %{?_smp_mflags}
cd libltdl
./configure --prefix=%{dep_path}/libltdl --enable-ltdl-install
make %{?_smp_mflags} cd ../../php-5.3.
./configure\
--prefix=%{php_path} \
--with-config-file-path=%{php_path}/etc\
--with-iconv-dir=%{dep_path}/libiconv\
--with-mysql=%{dep_path}/mysql\
--with-mysqli=%{dep_path}/mysql/bin/mysql_config\
--with-pdo-mysql=%{dep_path}/mysql\
--with-mcrypt=%{dep_path}/libmcrypt\
--with-png-dir=%{dep_path}/libpng\
--with-freetype-dir=%{dep_path}/freetype\
--with-libxml-dir=%{dep_path}/libxml2\
--with-jpeg-dir=%{dep_path}/jpeg\
--with-gd\
--with-zlib\
--with-openssl\
--with-pear\
--with-gettext\
--enable-fpm\
--enable-safe-mode\
--enable-mbstring\
--enable-zip\
--enable-soap\
--enable-sysvsem\
--enable-shmop\
--enable-sockets\
--enable-ftp\
--enable-gd-native-ttf\
--enable-bcmath\
--with-gdbm\
--with-curl\
--with-mhash\
--with-curlwrappers\
--with-ldap\
--enable-pcntl\
--enable-maintainer-ztswith-xmlrpc\
--with-tidy
make %{?_smp_mflags} %install
rm -rf %{buildroot}
rm -rf %{buildroot}/{.channels,.depdb,.depdblock,.filemap,.lock,.registry}
cd ../jpeg-8d
mkdir -p %{buildroot}/usr/local/bin/{bin,include,lib,man/man1}
make install DESTDIR=%{buildroot}
cd ../libpng-1.5.
make install DESTDIR=%{buildroot}
cd ../freetype-2.4.
make install DESTDIR=%{buildroot}
cd ../gd-2.0.
make install DESTDIR=%{buildroot}
cd ../libiconv-1.14
make install DESTDIR=%{buildroot}
#cd ../libxml2-2.7.
#make install DESTDIR=%{buildroot}
#cd ../mysql-5.5.
#make install DESTDIR=%{buildroot}
cd ../libmcrypt-2.5.
make install DESTDIR=%{buildroot}
cd libltdl
make install DESTDIR=%{buildroot}
cd ../../php-5.3.
make install INSTALL_ROOT=%{buildroot}
mkdir -p %{buildroot}%{_initrddir}
install -p -D -m %{SOURCE9} %{buildroot}%{_initrddir}/php-fpm
install -p -D -m %{SOURCE10} %{buildroot}%{php_path}/etc/php-fpm.conf
install -p -D -m php.ini-production %{buildroot}%{php_path}/etc/php.ini #Grep reports BUILDROOT inside our object files; disable that test.
QA_SKIP_BUILD_ROOT=1          #忽略buildroot检查,这在生成rpm包时报错found ${buildroot} in installed files;abort时,可以加此参数避过检查
QA_RPATHS=$[ 0x0001|0x0010 ]     #禁止rpath检查,这在生成rpm包时出现图一情况可以加此参数 
export QA_SKIP_BUILD_ROOT       
export QA_RPATHS %clean
rm -rf %{buildroot} %post
if [ $ == ];then
/bin/ln -s /usr/lib64/libldap* /usr/lib > /dev/null >&
cat >/etc/profile.d/php.sh<<EOF
PATH=$PATH:%{dep_path}/gd/bin:%{dep_path}/libmcrypt/bin:%{dep_path}/libiconv/bin:%{dep_path}/libpng/bin:%{dep_path}/libxml2/bin:%{dep_path}/mysql/bin:%{dep_path}/freetype/bin
EOF
source /etc/profile.d/php.sh
cat >/etc/ld.so.conf.d/php.conf<<EOF
%{dep_path}/libiconv/lib
%{dep_path}/libmcrypt/lib
%{dep_path}/libltdl/lib
%{dep_path}/gd/lib
%{dep_path}/libpng/lib
%{dep_path}/mysql/lib
#%{dep_path}/libxml2/lib
%{dep_path}/freetype/lib
EOF
/sbin/ldconfig > /dev/null >&
[ -z "`grep ^'export PATH=' /etc/profile`" ] && echo "export PATH=%{php_path}/bin:\$PATH" >> /etc/profile
[ -n "`grep ^'export PATH=' /etc/profile`" -a -z "`grep '%{php_path}' /etc/profile`" ] && sed -i "s@^export PATH=\(.*\)@export PATH=%{php_path}/bin:\1@" /etc/profile
/sbin/chkconfig --add php-fpm
/sbin/chkconfig php-fpm on
Mem=`free -m | awk '/Mem:/{print $2}'` #下面主要是参数的优化
if [ $Mem -le ];then
Mem_level=512M
Memory_limit=
elif [ $Mem -gt -a $Mem -le ];then
Mem_level=1G
Memory_limit=
elif [ $Mem -gt -a $Mem -le ];then
Mem_level=2G
Memory_limit=
elif [ $Mem -gt -a $Mem -le ];then
Mem_level=3G
Memory_limit=
elif [ $Mem -gt -a $Mem -le ];then
Mem_level=4G
Memory_limit=
elif [ $Mem -gt -a $Mem -le ];then
Mem_level=6G
Memory_limit=
elif [ $Mem -gt ];then
Mem_level=8G
Memory_limit=
fi
sed -i "s@^memory_limit.*@memory_limit = ${Memory_limit}M@" %{php_path}/etc/php.ini
sed -i 's@^output_buffering =@output_buffering = On\noutput_buffering =@' %{php_path}/etc/php.ini
sed -i 's@^;cgi.fix_pathinfo.*@cgi.fix_pathinfo=0@' %{php_path}/etc/php.ini
sed -i 's@^short_open_tag = Off@short_open_tag = On@' %{php_path}/etc/php.ini
sed -i 's@^expose_php = On@expose_php = Off@' %{php_path}/etc/php.ini
sed -i 's@^request_order.*@request_order = "CGP"@' %{php_path}/etc/php.ini
sed -i 's@^;date.timezone.*@date.timezone = Asia/Shanghai@' %{php_path}/etc/php.ini
sed -i 's@^post_max_size.*@post_max_size = 50M@' %{php_path}/etc/php.ini
sed -i 's@^upload_max_filesize.*@upload_max_filesize = 50M@' %{php_path}/etc/php.ini
sed -i 's@^;upload_tmp_dir.*@upload_tmp_dir = /tmp@' %{php_path}/etc/php.ini
sed -i 's@^max_execution_time.*@max_execution_time = 5@' %{php_path}/etc/php.ini
sed -i 's@^disable_functions.*@disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket,popen@' %{php_path}/etc/php.ini
sed -i 's@^session.cookie_httponly.*@session.cookie_httponly = 1@' %{php_path}/etc/php.ini
sed -i 's@^mysqlnd.collect_memory_statistics.*@mysqlnd.collect_memory_statistics = On@' %{php_path}/etc/php.ini
#cat > %{php_path}/etc/php-fpm.conf < /dev/null >&
if [ -e '/etc/profile.d/custom_profile_new.sh' ];then
sed -i 's@%{php_path}/bin:@@' /etc/profile.d/custom_profile_new.sh
else
sed -i 's@%{php_path}/bin:@@' /etc/profile
fi
fi
%preun
if [ "$1" = ] ; then
/sbin/service php-fpm stop > /dev/null >&
/sbin/chkconfig --del php-fpm
fi %postun
if [ "$1" = ] ; then
/bin/rm -rf %{php_path}
/bin/rm -rf %{dep_path}/libmcrypt
/bin/rm -rf %{dep_path}/libiconv
/bin/rm -rf %{dep_path}/libltdl
/bin/rm -rf %{dep_path}/libpng
# /bin/rm -rf %{dep_path}/libxml2
# /bin/rm -rf %{dep_path}/mysql
/bin/rm -rf %{dep_path}/freetype
/bin/rm -rf %{dep_path}/gd
/bin/rm -rf /etc/profile.d/php.sh
/bin/rm -rf /etc/ld.so.conf.d/php.conf
fi
%files
%defattr(-,root,root,-)
%{dep_path}/libmcrypt
%{dep_path}/libltdl
%{dep_path}/libiconv
%{dep_path}/libpng
#%{dep_path}/libxml2
%{dep_path}/jpeg
#%{dep_path}/mysql
%{dep_path}/freetype
%{dep_path}/gd
%{php_path}
%config(noreplace) %{php_path}/etc/php-fpm.conf
%config(noreplace) %{php_path}/etc/php.ini
%attr(,root,root) /etc/rc.d/init.d/php-fpm
%exclude /.channels
%exclude /.depdb
%exclude /.depdblock
%exclude /.filemap
%exclude /.lock %changelog
* Tue Jul wejing <weijing@qq.com> - 5.3.-.el6
- Initial version

php-fpm里面关于php的路径需要修改为实际安装的路径,此文件在源码包的support-files中有

php-fpm.conf将pid,log等几个参数的注释去掉,然后就能启动了

使用此php包的前提是已经安装了mysql,并且系统能找到libmysqlclient.so.18

mysql.spec

%define mysql_user mysql
%define mysql_group mysql
%define debug_package %{nil}
AutoReq: Name: mysql
Version: 5.5.
Release: %{?dist}
Summary: database Group: System Environment/Daemons
License: GPLv2
URL: http://www.mysql.com/downloads/%{name}-%{version}.tar.gz
Source0: %{name}-%{version}.tar.gz
Source1: mysql3306.cnf
Source2: mysql
BuildRoot: %{_topdir}/%{name}-%{version}-%{release} #BuildRequires: gcc-c++,ncurses,ncurses-devel,bison,cmake,zlib %description %prep
%setup -q %build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/sina_mobile/mysql -DWITH_MYISAM_STORAGE_ENGINE= -DWITH_INNOBASE_STORAGE_ENGINE= -DWITH_ARCHIVE_STORAGE_ENGINE= -DWITH_BLACKHOLE_STORAGE_ENGINE= -DWITH_MEMORY_STORAGE_ENGINE= -DWITH_PARTITION_STORAGE_ENGINE= -DWITH_PERFSCHEMA_STORAGE_ENGINE= -DWITH_PIC= -DWITH_READLINE= -DWITH_DEBUG= -DENABLED_LOCAL_INFILE= -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -Wno-dev
make %{?_smp_mflags} %install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}
install -p -D -m %{SOURCE1} %{buildroot}/data/mysql3306/mysql3306.cnf
install -p -D -m %{SOURCE2} %{buildroot}/etc/init.d/mysql %pre
if [ $ == ];then
/usr/sbin/groupadd mysql
/usr/sbin/useradd -r %{mysql_user} -M -g %{mysql_group} -s /bin/false >/dev/null || :
fi %post
if [ $ == ];then
/bin/chown -R mysql:mysql /usr/local/sina_mobile/mysql
/usr/local/sina_mobile/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/sina_mobile/mysql --datadir=/data/mysql3306
/bin/chown -R root /usr/local/sina_mobile/mysql
/bin/chown -R mysql /data/mysql3306
#/bin/cp /usr/local/sina_mobile/mysql/support-files/mysql.server /etc/init.d/mysql
#/bin/sed -i "s@^basedir=@basedir=/usr/local/sina_mobile/mysql@g;s@^datadir=@datadir=/data/mysql3306@g;s@conf=/etc/my.cnf@conf=/data/mysql3306/mysql3306.cnf@g" /etc/init.d/mysql
#/bin/chmod /etc/init.d/mysql
/sbin/chkconfig --add mysql
#/bin/echo "PATH=$PATH:/usr/local/sina_mobile/mysql/bin" >/etc/profile.d/mysql.sh
#source /etc/profile.d/mysql.sh
#/bin/echo "/usr/local/sina_mobile/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
#/sbin/ldconfig > /dev/null >&
/bin/ln -s /data/mysql3306/mysql3306.sock /tmp/mysql.sock >/dev/null
/bin/ln -s /usr/local/sina_mobile/mysql/bin/* /usr/local/bin/
/bin/ln -s /usr/local/sina_mobile/mysql/scripts/* /usr/local/bin/
/sbin/install-info %{_infodir}/%{name}.info %{_infodir}/dir 2>/dev/null || :
fi %preun
if [ $1 == 0 ];then
/sbin/service mysql stop > /dev/null 2>&1
/sbin/chkconfig --del mysql
#/usr/sbin/userdel -r %{mysql_user} 2> /dev/null
#/usr/sbin/groupdel %{mysql_user} 2> /dev/null
/sbin/install-info --delete %{_infodir}/%{name}.info %{_infodir}/dir 2>/dev/null || :
fi %postun
#rm -rf /etc/profile.d/mysql.sh
#rm -rf /etc/ld.so.conf.d/mysql.conf
rm -rf /tmp/mysql.sock
rm -rf /usr/local/bin/mysql*
rm -rf /usr/local/bin/myisam*
rm -rf /usr/local/bin/resolve*
rm -rf /usr/local/bin/{innochecksum,msql2mysql,my_print_defaults,perror,replace}
rm -rf /usr/local/sina_mobile/mysql/*
rm -rf /etc/init.d/mysql %clean
rm -rf %{buildroot} %files
%defattr(-,root,root,-)
/usr/local/sina_mobile/mysql/*
/data/mysql3306/mysql3306.cnf
%attr(0755,root,root) /etc/init.d/mysql
%doc %changelog
* Thu Jul 21 2016 weijing <645509024@qq.com> - 5.5.29-1.el6
- Initial version

全部搞定,搞了爸爸一周,不过感觉对于包管理和rpm打包的流程清晰了很多,可能以后安装别的包发生了dependence错误会更清楚的知道哪里出了问题

附上友情链接:

http://blog.digitalstruct.com/2011/12/21/rpm-packaging-building-and-deploying-your-own-php/    这是制作php的

http://www.centoscn.com/image-text/config/2014/1201/4215.html                    这是制作nginx

http://www.bkjia.com/Linuxjc/1088197.html                              这是制作rpm包出错的解决方法

http://ju.outofmemory.cn/entry/95476                                 这是rpm包每个字段的解释

http://fedoraproject.org/wiki/How_to_create_an_RPM_package                      这是fedora的官方文档,英语牛逼的可以直接看这个

最新文章

  1. css实现水平垂直居中
  2. PourOver – 快速筛选和排序大的数据集合
  3. CUDA2.2-原理之存储器访问
  4. 人脸识别经典算法一:特征脸方法(Eigenface)
  5. mysql客户端授权后连接失败问题
  6. iOS Block传值
  7. 254. Factor Combinations
  8. Linux就是这个范儿之第一次亲密接触(3)
  9. TCP/UDP是如何传输的?
  10. Scrum 学习笔记
  11. HDU 1232 畅通工程(模板——并查集)
  12. 学会python可以上天!20行代码获取斗鱼平台房间数据,就是这么牛逼!
  13. Connection 对象简介 方法解读 JDBC简介(四)
  14. QT槽函数处理线程
  15. 洛谷P1309 瑞士轮(归并排序)
  16. Python Redis hash
  17. Java学习笔记49(DBUtils工具类二)
  18. &lt;数据结构与算法分析&gt;读书笔记--实现泛型构件pre-Java5
  19. CSS3提交意见输入框样式
  20. ubuntu 上使用valgrind

热门文章

  1. AEAI DP开发平台升级说明
  2. Try out the latest C++ compiler toolset without waiting for the next update of Visual Studio
  3. Python入门笔记(8):列表
  4. 重新想象 Windows 8 Store Apps (37) - 契约: Settings Contract
  5. .net多线程的发展
  6. [moka同学代码]PHP初级知识:上传文件源码
  7. jquery checkbox checked
  8. Android 手机卫士12--进程管理
  9. oschina github使用指南
  10. [Intellij] 编译报错 javacTask