设为首页 收藏本站
查看: 778|回复: 0

rpmbuild使用

[复制链接]

尚未签到

发表于 2019-1-15 06:21:56 | 显示全部楼层 |阅读模式
  nagios客户端一般需要nagios-plugins,nrpe,为了方便与puppet结合,所以最好把源码打包成软件包

spec文件内容如下:

nrpe.spec:




  • %define name nrpe
  • %define version 2.13
  • %define release 10
  • %define nsusr nagios
  • %define nsgrp nagios
  • %define nsport 5666

  • # Reserve option to override port setting with:
  • # rpm -ba|--rebuild --define 'nsport 5666'
  • %{?port:%define nsport %{port}}

  • # Macro that print mesages to syslog at package (un)install time
  • %define nnmmsg logger -t %{name}/rpm

  • Summary: Host/service/network monitoring agent for Nagios
  • URL: http://www.nagios.org
  • Name: %{name}
  • Version: %{version}
  • Release: %{release}
  • License: GPL
  • Group: Application/System
  • Source0: %{name}-%{version}.tar.gz
  • BuildRoot: %{_tmppath}/%{name}-buildroot
  • Prefix: %{_prefix}
  • Prefix: /usr/local/nagios
  • Requires: bash, grep, nagios-plugins,xinetd
  • PreReq: /usr/bin/logger, chkconfig, sh-utils, shadow-utils, sed, initscripts, fileutils, mktemp

  • %description
  • Nrpe is a system daemon that will execute various Nagios plugins
  • locally on behalf of a remote (monitoring) host that uses the
  • check_nrpe plugin.  Various plugins that can be executed by the  
  • daemon are available at:

  • %prep
  • %setup -q

  • %pre
  • if [ $? -eq 2 ] ; then
  •     /usr/sbin/groupadd %{nsgrp} || %nnmmsg Unexpected error adding group "%{nyysgrp}". Aborting install process.
  • fi

  • # Create `nagios' user on the system if necessary
  • if [ $? -eq 2 ] ; then
  •     /usr/sbin/useradd -d %{nsgrp} -s /bin/nologin -c "%{nsusr}" -g %{nsgrp} %{nsusr} || \
  •         %nnmmsg Unexpected error adding user "%{nsusr}". Aborting install process.
  • fi

  • %post
  • if [ "$1" = 1 ]; then
  •   chown -R "%{nsusr}":"%{nsgrp}" %{_prefix}
  •   chkconfig --add xinetd
  •   chkconfig xinetd on
  •   echo "nrpe         5666/tcp             #nrpe" >> /etc/services
  •   /sbin/service xinetd restart > /dev/null 2>&1
  • fi

  • %preun
  • if [ "$1" = 0 ]; then
  •   /bin/rm /etc/xinetd.d/nrpe -f
  •   sed -i '/^nrpe.*/d' /etc/services
  • fi

  • %postun
  • if [ "$1" = 0 ]; then
  •     /sbin/service xinetd restart >/dev/null 2>&1 || :
  • fi

  • %build
  • export PATH=$PATH:/usr/sbin
  • CFLAGS="$RPM_OPT_FLAGS" CXXFLAGS="$RPM_OPT_FLAGS" \
  • ./configure \
  •     --with-init-dir=/etc/init.d \
  •     --with-nrpe-port=%{nsport} \
  •     --with-nrpe-user=%{nsusr} \
  •     --with-nrpe-group=%{nsgrp} \
  •     --prefix=%{_prefix} \
  •     --exec-prefix=%{_prefix}/bin \
  •     --bindir=%{_prefix}/bin \
  •     --sbindir=%{_prefix}/lib/nagios/cgi \
  •     --libexecdir=%{_prefix}/libexec \
  •     --datadir=%{_prefix}/share \
  •     --sysconfdir=/etc/nagios \
  •     --localstatedir=/var/log/nagios \
  •     --enable-command-args

  • make all

  • %install
  • [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT
  • install -d -m 0755 ${RPM_BUILD_ROOT}/etc/xinetd.d
  • install -c -m 0755 -d ${RPM_BUILD_ROOT}/usr/local/nagios/libexec
  • install -c -m 0755 src/check_nrpe ${RPM_BUILD_ROOT}/usr/local/nagios/libexec
  • install -c -m 0755 -d ${RPM_BUILD_ROOT}/usr/local/nagios/bin
  • install -c -m 0755 src/nrpe ${RPM_BUILD_ROOT}/usr/local/nagios/bin
  • install -c -m 0755 -d ${RPM_BUILD_ROOT}/usr/local/nagios/etc
  • install -c -m 0755 sample-config/nrpe.cfg ${RPM_BUILD_ROOT}/usr/local/nagios/etc/nrpe.cfg
  • install -c -m 0644 sample-config/nrpe.xinetd ${RPM_BUILD_ROOT}/etc/xinetd.d/nrpe
  • sed -i 's#server_args.*#server_args     = -c %{_prefix}/etc/nrpe.cfg --inetd#' ${RPM_BUILD_ROOT}/etc/xinetd.d/nrpe
  • %clean
  • rm -rf $RPM_BUILD_ROOT

  • %files
  • %defattr(755,root,root)
  • %{_prefix}/bin/nrpe
  • %defattr(644,root,root)
  • %config(noreplace) /usr/local/nagios/etc/*.cfg
  • %config(noreplace) /etc/xinetd.d/nrpe
  • %defattr(755,%{nsusr},%{nsgrp})
  • %doc Changelog LEGAL README  
  • %doc %{_prefix}/libexec

  • %changelog
  • * Wed Apr 3 2013 xxx build - 2.13-10  
  • - fixed nrpe.cfg relocation to sample-config

nagios-plugins.spec




  • # Macros
  • %define isaix %(test "`uname -s`" = "AIX" && echo "1" || echo "0")
  • %define islinux %(test "`uname -s`" = "Linux" && echo "1" || echo "0")
  • %define isredhatfamily %(test -f /etc/redhat-release && echo "1" || echo "0")

  • %if %{isaix}
  •     %define _prefix /usr/local/nagios
  • #   %define _defaultdocdir %{_datadir}/doc
  • %else
  •     %define _libexecdir %{_exec_prefix}/libexec
  • %endif
  • %define _sysconfdir /usr/local/nagios/etc

  • %define npusr nagios
  • %define nphome /home/nagios
  • %define npgrp nagios

  • Name: nagios-plugins
  • Version: 1.4.16
  • Release: 10
  • Summary: Host/service/network monitoring program plugins for Nagios

  • Group: Applications/System
  • License: GPL
  • URL: http://nagiosplug.sourceforge.net/
  • Source0: http://dl.sf.net/sourceforge/nagiosplug/%{name}-%{version}.tar.gz
  • BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

  • %define npdir %{_builddir}/%{name}-%{version}

  • %if %{isaix}
  • Prefix: %{_prefix}
  • %else
  • Prefix: %{_prefix}/lib/nagios/plugins
  • %endif
  • Packager: Karl DeBisschop  
  • Vendor: Nagios Plugin Development Group
  • Provides: nagios-plugins

  • %{!?custom:%global custom 0}
  • Obsoletes: nagios-plugins-custom nagios-plugins-extras


  • # Requires
  • %if %{isaix}
  • Requires:   fping  
  • Requires:   gawk
  • Requires:   net-snmp  
  • Requires:   net-snmp-perl  
  • Requires:   net-snmp-utils
  • Requires:   openldap
  • Requires:   openssl
  • Requires:   perl
  • Requires:   python
  • Requires:   openssl
  • BuildRequires:  fping  
  • BuildRequires:  gawk
  • BuildRequires:  net-snmp  
  • BuildRequires:  net-snmp-perl  
  • BuildRequires:  net-snmp-utils
  • BuildRequires:  openldap-devel
  • %endif
  • %if %{isredhatfamily}
  • Requires:   bind-utils
  • Requires:   coreutils
  • Requires:   fping  
  • Requires:   gawk
  • Requires:   grep
  • Requires:   iputils
  • Requires:   mysql
  • Requires:   net-snmp-utils
  • Requires:   ntp
  • Requires:   openldap
  • Requires:   openssl
  • Requires:   openssh-clients
  • Requires:   perl
  • Requires:   postgresql-libs
  • Requires:   procps
  • Requires:   python
  • Requires:   samba-client
  • Requires:   shadow-utils
  • Requires:   traceroute
  • Requires:   /usr/bin/mailq
  • BuildRequires:  bind-utils
  • BuildRequires:  coreutils
  • BuildRequires:  iputils
  • BuildRequires:  mysql-devel
  • BuildRequires:  net-snmp-utils
  • BuildRequires:  net-tools
  • BuildRequires:  ntp
  • BuildRequires:  openldap-devel
  • BuildRequires:  openssh-clients
  • BuildRequires:  openssl-devel
  • BuildRequires:  postgresql-devel
  • BuildRequires:  procps
  • BuildRequires:  samba-client
  • BuildRequires:  /usr/bin/mailq
  • %endif


  • %description

  • Nagios is a program that will monitor hosts and services on your
  • network, and to email or page you when a problem arises or is
  • resolved. Nagios runs on a unix server as a background or daemon
  • process, intermittently running checks on various services that you
  • specify. The actual service checks are performed by separate "plugin"
  • programs which return the status of the checks to Nagios. This package
  • contains those plugins.


  • %prep
  • %setup -q


  • %build
  • %{?isaix: MAKE=gmake} ./configure \
  • --prefix=%{_prefix} \
  • --exec-prefix=%{_exec_prefix} \
  • --libexecdir=%{_libexecdir} \
  • --sysconfdir=%{_sysconfdir} \
  • --datadir=%{_datadir} \
  • #--with-cgiurl=/nagios/cgi-bin
  • ls -1 %{npdir}/plugins > %{npdir}/ls-plugins-before
  • ls -1 %{npdir}/plugins-root > %{npdir}/ls-plugins-root-before
  • ls -1 %{npdir}/plugins-scripts > %{npdir}/ls-plugins-scripts-before
  • make %{?_smp_mflags}
  • ls -1 %{npdir}/plugins > %{npdir}/ls-plugins-after
  • ls -1 %{npdir}/plugins-root > %{npdir}/ls-plugins-root-after
  • ls -1 %{npdir}/plugins-scripts > %{npdir}/ls-plugins-scripts-after
  • %pre
  • # Create `nagios' group on the system if necessary
  • %if %{isaix}
  • lsgroup %{npgrp} > /dev/null 2> /dev/null
  • if [ $? -eq 2 ] ; then
  •     mkgroup %{npgrp} || %nnmmsg Unexpected error adding group "%{npgrp}". Aborting install process.
  • fi
  • %endif
  • %if %{islinux}
  • getent group %{npgrp} > /dev/null 2> /dev/null
  • if [ $? -ne 0 ] ; then
  •     groupadd %{npgrp} || %nnmmsg Unexpected error adding group "%{npgrp}". Aborting install process.
  • fi
  • %endif

  • # Create `nagios' user on the system if necessary
  • %if %{isaix}
  • lsuser %{npusr} > /dev/null 2> /dev/null
  • if [ $? -eq 2 ] ; then
  •     useradd -d %{nphome} -s /bin/nologin -c "%{npusr}" -g %{npgrp} %{npusr} || \
  •         %nnmmsg Unexpected error adding user "%{npusr}". Aborting install process.
  • fi
  • %endif
  • %if %{islinux}
  • getent passwd %{npusr} > /dev/null 2> /dev/null
  • if [ $? -ne 0 ] ; then
  •     useradd -r -d %{nphome} -s /bin/nologin -c "%{npusr}" -g %{npgrp} %{npusr} || \
  •         %nnmmsg Unexpected error adding user "%{npusr}". Aborting install process.
  • fi
  • %endif

  • %post
  • chown -R "%{npusr}":"%{npgrp}" %{_prefix}

  • %install
  • rm -rf $RPM_BUILD_ROOT
  • make AM_INSTALL_PROGRAM_FLAGS="" DESTDIR=${RPM_BUILD_ROOT} install
  • build-aux/install-sh -c  -d ${RPM_BUILD_ROOT}%{_sysconfdir}
  • build-aux/install-sh -c  -m 664 command.cfg ${RPM_BUILD_ROOT}%{_sysconfdir}
  • %find_lang %{name}
  • echo "%defattr(755,%{npusr},%{npgrp})" >> %{name}.lang
  • comm -13 %{npdir}/ls-plugins-before %{npdir}/ls-plugins-after | egrep -v "\.o$|^\." | gawk -v libexecdir=%{_libexecdir} '{printf( "%s/%s\n", libexecdir, $0);}' >> %{name}.lang
  • echo "%defattr(755,root,root)" >> %{name}.lang
  • comm -13 %{npdir}/ls-plugins-root-before %{npdir}/ls-plugins-root-after | egrep -v "\.o$|^\." | gawk -v libexecdir=%{_libexecdir} '{printf( "%s/%s\n", libexecdir, $0);}' >> %{name}.lang
  • echo "%defattr(755,%{npusr},%{npgrp})" >> %{name}.lang
  • comm -13 %{npdir}/ls-plugins-scripts-before %{npdir}/ls-plugins-scripts-after | egrep -v "\.o$|^\." | gawk -v libexecdir=%{_libexecdir} '{printf( "%s/%s\n", libexecdir, $0);}' >> %{name}.lang
  • echo "%{_libexecdir}/utils.pm" >> %{name}.lang
  • echo "%{_libexecdir}/utils.sh" >> %{name}.lang

  • %clean
  • rm -rf $RPM_BUILD_ROOT


  • %files -f %{name}.lang
  • %doc CODING COPYING FAQ INSTALL LEGAL README REQUIREMENTS SUPPORT THANKS
  • %doc ChangeLog  
  • %if ! %{isaix}
  • %{_datadir}/locale/de/LC_MESSAGES/nagios-plugins.mo
  • %{_datadir}/locale/fr/LC_MESSAGES/nagios-plugins.mo
  • /usr/local/nagios/libexec/check_ldaps
  • /usr/local/nagios/etc/command.cfg
  • %endif

  • %changelog
  • * Wed Apr 3 2013 xxx build   - 1.4.16-10   
  • - Initial Package














运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-663301-1-1.html 上篇帖子: nagios服务器端自动安装脚本 下篇帖子: 使用ramdisk 优化nagios IO性能
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表