为了方便批量进行软件安装,我们通常将源代码打包,放到yum仓库中进行统一管理,本文记录了一次rpm打包过程。
1、安装rpm-build 1 yum install -y rpm-build
2、安装编译依赖包 1 yum install -y make gcc gcc-c++ libtool autoconf automake imake
3、安装软件本身依赖的软件包 以CoreSeek安装为例,Coreseek 是一款中文全文检索/搜索软件,以GPLv2许可协议开源发布,基于Sphinx研发并独立发布,专攻中文搜索和信息处理领域,适用于行业/垂直搜索、论坛/站内搜索、数据库搜索、文档/文献检索、信息检索、数据挖掘等应用场景。
1 yum install -y libxml2-devel expat-devel mysql-devel python-devel
4、如下创建rpmbuild 1 2 [root@salt ~] BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
5、编写描述文件 CoreSeek依赖mmseg中文分词库,所有先给mmseg打包。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 [root@salt SPECS] Name: mmseg Version: 3.2.14 Release: 1%{?dist} Summary: A Word Identification System for Mandarin Chinese Text Based on Two Variants of the Maximum Matching Algorithm Group: System Environment/Daemons License: Free for noncommercial use URL: http://www.coreseek.cn/opensource/mmseg/ Source0: http://www.coreseek.cn/uploads/csft/3.2/mmseg-3.2.14.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) %description A Word Identification System for Mandarin Chinese Text Based on Two Variants of the Maximum Matching Algorithm %prep %setup -q -n %{name}-%{version} %build ./bootstrap ./configure --prefix=/usr/local /mmseg make %install rm -rf $RPM_BUILD_ROOT make DESTDIR=$RPM_BUILD_ROOT install %clean /bin/rm -rf $RPM_BUILD_ROOT /bin/rm -rf $RPM_BUILD_DIR /%{name}-%{version} %files %defattr(-,root,root) %dir /usr/local /mmseg %changelog
CoreSeek描述文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 [root@salt SPECS] Name: coreseek Version: 4.1b Release: 1%{?dist} Summary: 支持中文全文检索的Sphinx定制版本 Group: System Environment/Daemons License: GPLv2 URL: http://www.coreseek.cn/ Source0: csft-4.1.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) Requires: mmseg Requires: mysql-devel Requires: libxml2-devel Requires: expat-devel Requires: python-devel Requires(post): chkconfig Requires(preun): chkconfig Requires(preun): initscripts Requires(postun): initscripts %description 支持中文全文检索的Sphinx定制版本 %prep %setup -q -n csft-4.1 %build sh buildconf.sh ./configure --prefix=/usr/local /coreseek --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local /mmseg/include/mmseg/ --with-mmseg-libs=/usr/local /mmseg/lib/ --with-mysql --with-python make %install rm -rf $RPM_BUILD_ROOT make DESTDIR=$RPM_BUILD_ROOT install mv $RPM_BUILD_ROOT /usr/local /coreseek/etc/sphinx.conf.dist $RPM_BUILD_ROOT /usr/local /coreseek/etc/sphinx.conf mkdir -p $RPM_BUILD_ROOT %{_initrddir} cp /etc/init.d/searchd $RPM_BUILD_ROOT %{_initrddir}/ %clean /bin/rm -rf $RPM_BUILD_ROOT /bin/rm -rf $RPM_BUILD_DIR /%{name}-%{version} %files %defattr(-,root,root) %attr(0755, root, root) %{_initrddir}/ %config(noreplace) /usr/local /coreseek/etc/sphinx.conf /usr/local /coreseek/etc/example.sql /usr/local /coreseek/etc/sphinx-min.conf.dist %dir /usr/local /coreseek/bin /usr/local /coreseek/share %attr(-, sphinx, root) /usr/local /coreseek/var %preun if [ $1 -eq 0 ] ; then /sbin/service searchd stop >/dev/null 2>&1 /sbin/chkconfig --del searchd fi %post cat /etc/passwd |grep -q '^sphinx:' if (( $? != 0 )); then /usr/sbin/groupadd -g 495 sphinx &>/dev/null /usr/sbin/useradd -g 495 -u 495 -m -c 'Sphinx Search' -d /var/lib/sphinx -s /sbin/nologin www &>/dev/null fi /sbin/chkconfig --add searchd %changelog
searchd启动脚本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 #!/bin/sh . /etc/rc.d/init.d/functions exec ="/usr/local/coreseek/bin/searchd" prog="searchd" config="/usr/local/coreseek/etc/sphinx.conf" username="sphinx" lockfile=/var/lock/subsys/searchd start () { [ -x $exec ] || exit 5 [ -f $config ] || exit 6 echo -n $"Starting $prog : " daemon --user=$username $exec --config $config retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop () { echo -n $"Stopping $prog : " killproc $prog retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart () { stop start } reload () { restart } force_reload () { restart } rh_status () { status $prog } rh_status_q () { rh_status >/dev/null 2>&1 } case "$1 " in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 restart ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" exit 2 esac exit $?
6、打包 执行下面命令为mmseg打包:
rpmbuild -ba mmseg.spec
如果没问题,软件包会根据服务器架构放置到相应目录中。如:/root/rpmbuild/RPMS/x86_64/mmseg-3.2.14-1.el6.x86_64.rpm
安装好编译的mmseg包再开始编译coreseek:
rpm -ivh /root/rpmbuild/RPMS/x86_64/mmseg-3.2.14-1.el6.x86_64.rpm
rpmbuild -ba coreseek.spec
完成后编译包为:/root/rpmbuild/RPMS/x86_64/coreseek-4.1b-1.el6.x86_64.rpm