zabbix-2.2.1 下载位置
http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.2.1/zabbix-2.2.1.tar.gz
目标: 创建 zabbix server 端 RPM 软件包, 方便进行软件分发
安装位置:
应用程序: /apps/svr/zabbix 配置文件: /apps/conf 库文件: /apps/lib 头文件: /apps/include 启动程序: /apps/sh web 管理: /apps/dat/web/zabbix
编译测试
安装需要的库文件
[root@localhost zabbix-2.2.1]# yum install -y net-snmp* curl-devel mysql-devel Dependency Installed: beecrypt.x86_64 0:4.1.2-10.1.1 beecrypt-devel.x86_64 0:4.1.2-10.1.1 curl.i386 0:7.15.5-15.el5 elfutils-devel.x86_64 0:0.137-3.el5 elfutils-devel-static.x86_64 0:0.137-3.el5 elfutils-libelf-devel.x86_64 0:0.137-3.el5 elfutils-libelf-devel-static.x86_64 0:0.137-3.el5 libidn.i386 0:0.6.5-1.1 libidn-devel.x86_64 0:0.6.5-1.1 lm_sensors.x86_64 0:2.10.7-9.el5 lm_sensors-devel.x86_64 0:2.10.7-9.el5 nspr-devel.x86_64 0:4.8.8-2.el5 nss-devel.x86_64 0:3.12.10-8.el5 rpm-devel.x86_64 0:4.4.2.3-27.el5 Complete!
解压 zabbix 服务端
[root@localhost src]# tar xf /root/zabbix-2.2.1.tar.gz -C /usr/src [root@localhost src]# cd /usr/src/zabbix-2.2.1/
测试
./configure --enable-server --with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2=/apps/lib/libxml2-2.7.8/bin/xml2-config --with-iconv=/apps/lib/libiconv-1.14 Enable server: yes Server details: With database: MySQL WEB Monitoring: yes Native Jabber: no SNMP: yes IPMI: no SSH: no ODBC: no Linker flags: -rdynamic -L//apps/lib/libiconv-1.14/lib -L/apps/svr/mysql5/lib -L/apps/lib/libxml2-2.7.8/lib -L/usr/kerberos/lib64 -L/usr/lib64 -L/usr/lib64 -L/usr/lib64/lib Libraries: -lm -ldl -lrt -lresolv -liconv -lmysqlclient -lxml2 -lcurl -ldl -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lidn -lssl -lcrypto -lz -lnetsnmp -lcrypto -lm -lwrap -lcrypto Enable proxy: no Enable agent: no Enable Java gateway: no LDAP support: no IPv6 support: no *********************************************************** * Now run 'make install' * * * * Thank you for using Zabbix! * * <http://www.zabbix.com> * ***********************************************************
make 成功不报错后退出编译
开始创建 RPM 软件包, 当前使用 rhel5.8
文件说明
spec 文件用于定义编译及 RPM 创建信息, 默认需要存放至 /usr/src/redhat/SPECS/zabbix-2.2.1.spec source 文件用于编译并生成 RPM 文件, 默认需要存放至 /usr/src/redhat/SOURCES/zabbix-2.2.1.tar.gz
Name: 软件包名称 Version: 版本 Release: 1%{?dist} 分发版本号 Summary: 摘要 Group: rpm组定义, 可参考 /usr/share/doc/rpm-4.4.2.3/GROUPS 文件获取相关信息 License: 许可 URL: 软件相关 URL Source0: 源码位置 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) 编译时的位置 BuildRequires: 编译时需要的软件包依赖 Requires: 安装时需要的软件包依赖 %description 相关软件包描述 %prep 编译前执行的脚本 %setup -q %build %configure 重点, 软件包编译参数 make %{?_smp_mflags} 编译 %install rm -rf %{buildroot} 删除编译后的垃圾文件 make install DESTDIR=%{buildroot} 安装位置定义 %clean rm -rf %{buildroot} 创建 RPM 软件包后, 删除编译安装的软件 %files %defattr(-,root,root,-) 定义 RPM 安装时的文件属性 %doc 文档说明 %changelog 当前 RPM 的简单信息说明
下面是编辑后的 zabbix-2.2.1.spec
Name: zabbix Version: 2.2.1 Release: 20140121.vipclound.el5 Summary: use for monitor openstack VM. Group: Applications/System License: PSF URL: http://www.zabbix.com/download.php Source0: http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/2.2.1/zabbix-2.2.1.tar.gz BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) BuildRequires: autoconf BuildRequires: bzip2 BuildRequires: bzip2-devel BuildRequires: db4-devel BuildRequires: expat-devel BuildRequires: findutils BuildRequires: gcc-c++ BuildRequires: glibc-devel BuildRequires: make BuildRequires: openssl-devel BuildRequires: pkgconfig BuildRequires: readline-devel BuildRequires: sqlite-devel BuildRequires: tar BuildRequires: zlib-devel Requires: curl Requires: curl-devel Requires: nss-devel Requires: nspr-devel Requires: elfutils-devel Requires: beecrypt-devel Requires: net-snmp-devel Requires: mysql-devel ####### # DEFINE LOCATION ####### %define _prefix /apps %define _exec-prefix /apps %define _bindir /apps/svr/zabbix/bin %define _sbindir /apps/svr/zabbix/sbin %define _sysconfdir /apps/conf %define _includedir /apps/include %define _libexecdir /apps/lib %define _infodir /apps/info %define _oldincludedir /apps/include %define _libdir /apps/lib %define _defaultdocdir /apps/man %define _mandir /apps/man %description Zabbix is the ultimate enterprise-level software designed for monitoring availability and performance of IT infrastructure components. Zabbix is open source and comes at no cost. %prep %setup -q %build %configure --enable-server --enable-proxy --with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2=/apps/lib/libxml2-2.7.8/bin/xml2-config --with-iconv=/apps/lib/libiconv-1.14 make %{?_smp_mflags} %install rm -rf %{buildroot} make install DESTDIR=%{buildroot} mkdir %{buildroot}/apps/conf/zabbix -p cp $RPM_BUILD_DIR/zabbix-2.2.1/database/mysql/schema.sql %{buildroot}/apps/conf/zabbix/schema.sql cp $RPM_BUILD_DIR/zabbix-2.2.1/database/mysql/images.sql %{buildroot}/apps/conf/zabbix/images.sql cp $RPM_BUILD_DIR/zabbix-2.2.1/database/mysql/data.sql %{buildroot}/apps/conf/zabbix/data.sql mkdir %{buildroot}/apps/dat/web/zabbix -p mkdir %{buildroot}/apps/sh/ -p cp -rp $RPM_BUILD_DIR/zabbix-2.2.1/frontends/php/* %{buildroot}/apps/dat/web/zabbix/. cp $RPM_BUILD_DIR/zabbix-2.2.1/misc/init.d/fedora/core/zabbix_server %{buildroot}/apps/sh/zabbix_server %clean rm -rf %{buildroot} %files %defattr(-,root,root,-) %{_sysconfdir}/zabbix_server.conf %{_mandir}/man8/zabbix_server.8 %{_sbindir}/zabbix_server %{_sysconfdir}/zabbix_proxy.conf %{_mandir}/man8/zabbix_proxy.8 %{_sbindir}/zabbix_proxy %config(noreplace) /apps/conf/zabbix/schema.sql %config(noreplace) /apps/conf/zabbix/images.sql %config(noreplace) /apps/conf/zabbix/data.sql %config(noreplace) /apps/dat/web/* %config(noreplace) /apps/sh/zabbix_server %doc %changelog * Wed Jan 22 2014 terrytsang <[email protected]> -- example
注, 当前库依赖关系使用到自定义的 libxml2-devel 及 iconv-devel, 各位可自行重新进行定义, 另外, 当前不需要监控 JAVA 服务, 因此没有使用参数 --enable-java
编译方法
[root@localhost SPECS]# rpmbuild -bb zabbix-2.2.1.spec
留意编译最后的信息
Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/zabbix-2.2.1-20140121.vipclound.el5-A16601 Wrote: /usr/src/redhat/RPMS/x86_64/zabbix-2.2.1-20140121.vipclound.el5.x86_64.rpm Wrote: /usr/src/redhat/RPMS/x86_64/zabbix-debuginfo-2.2.1-20140121.vipclound.el5.x86_64.rpm Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.94541 + umask 022 + cd /usr/src/redhat/BUILD + cd zabbix-2.2.1 + rm -rf /var/tmp/zabbix-2.2.1-20140121.vipclound.el5-A16601 + exit 0
软件编译成功后, 默认在 /usr/src/redhat/RPMS 目录中生成, 留意
Wrote: /usr/src/redhat/RPMS/x86_64/zabbix-2.2.1-20140121.vipclound.el5.x86_64.rpm Wrote: /usr/src/redhat/RPMS/x86_64/zabbix-debuginfo-2.2.1-20140121.vipclound.el5.x86_64.rpm
测试软件安装
[root@localhost SPECS]# rpm -ivh /usr/src/redhat/RPMS/x86_64/zabbix-2.2.1-20140121.vipclound.el5.x86_64.rpm Preparing... ########################################### [100%] 1:zabbix ########################################### [100%]
rpm 编译文件 spec 中的宏变量, 可参考 /usr/lib/rpm/macros 文件如下描述
%__awk gawk %__bzip2 /usr/bin/bzip2 %__cat /bin/cat %__chgrp /bin/chgrp %__chmod /bin/chmod %__chown /bin/chown %__cp /bin/cp %__cpio /bin/cpio %__file /usr/bin/file %__gpg /usr/bin/gpg %__grep /bin/grep %__gzip /bin/gzip %__id /usr/bin/id %__install /usr/bin/install %__ln_s ln -s %__make /usr/bin/make %__mkdir /bin/mkdir %__mkdir_p /bin/mkdir -p %__mv /bin/mv %__patch /usr/bin/patch %__perl /usr/bin/perl %__pgp /usr/bin/pgp %__python /usr/bin/python %__rm /bin/rm %__rsh /usr/bin/rsh %__sed /bin/sed %__ssh /usr/bin/ssh %__tar /bin/tar %__unzip /usr/bin/unzip %__xz %{_bindir}/xz %__lzma %{__xz} --format=lzma %__ar ar %__as as %__cc gcc %__cpp gcc -E %__cxx g++ %__ld /usr/bin/ld %__nm /usr/bin/nm %__objcopy /usr/bin/objcopy %__objdump /usr/bin/objdump %__ranlib ranlib %__remsh %{__rsh} %__strip /usr/bin/strip # XXX avoid failures if tools are not installed when rpm is built. %__libtoolize libtoolize %__aclocal aclocal %__autoheader autoheader %__automake automake %__autoconf autoconf %_defaultdocdir %{_usr}/doc %_gzipbin %{__gzip} %_instchangelog 5 %_pgpbin %{__pgp} %_rpmdir %{_topdir}/RPMS %_rpmfilename %{_build_name_fmt} %_signature gpg %_sourcedir %{_topdir}/SOURCES %_specdir %{_topdir}/SPECS %_srcrpmdir %{_topdir}/SRPMS %_tmppath %{_var}/tmp %_topdir %{_usrsrc}/redhat %_unzipbin %{__unzip} %_install_script_path /sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin %_install_langs all %_javadir %{_datadir}/java %_javadocdir %{_datadir}/javadoc %_prefix /usr %_exec_prefix %{_prefix} %_bindir %{_exec_prefix}/bin %_sbindir %{_exec_prefix}/sbin %_libexecdir %{_exec_prefix}/libexec %_datadir %{_prefix}/share %_sysconfdir %{_prefix}/etc %_sharedstatedir %{_prefix}/com %_localstatedir %{_prefix}/var %_lib lib %_libdir %{_exec_prefix}/%{_lib} %_includedir %{_prefix}/include %_oldincludedir /usr/include %_infodir %{_prefix}/info %_mandir %{_prefix}/man %_build %{_host} %_build_alias %{_host_alias} %_build_cpu %{_host_cpu} %_build_vendor %{_host_vendor} %_build_os %{_host_os} %_host x86_64-redhat-linux-gnu %_host_alias %{nil} %_host_cpu x86_64 %_host_vendor redhat %_host_os linux-gnu %_target %{_host} %_target_alias %{_host_alias} %_target_cpu %{_host_cpu} %_target_vendor %{_host_vendor} %_target_os %{_host_os}