486
技術社區[雲棲]
zabbix-2.2.1 打造 server 端 自定義 rpm 方法 [備忘]
zabbix-2.2.1 下載位置
https://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! *
* <https://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
默認 spec 模板及簡單說明
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: https://www.zabbix.com/download.php
Source0: https://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 <signmem@hotmail.com>
-- 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}
最後更新:2017-04-03 12:54:45