定製zabbix的rpm包—spec檔案的書寫
定製zabbix的rpm包
- #
- %define zabbix_group zabbix
- %define zabbix_user zabbix
- Name: zabbix
- Version: 2.0.4
- Release: 1%{?dist}.zbx
- Summary: zabbix monitor
- Vendor: itnihao@qq.com
- Group: System Environment/Daemons
- License: GPL
- URL: http://www.zabbix.com
- Source0: http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.0.4/zabbix-2.0.4.tar.gz
- Source1: zabbix_custom.tar.gz
- Source2: zabbix-web.conf
- #BuildRoot: %{_tmppath}/%{name}-%{version}
- BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
- BuildRequires: gcc
- BuildRequires: make
- Requires(pre):gcc
- Requires(post):chkconfig
- Provides:Monitor
- %description
- Zabbix is the ultimate open source availability and performance monitoring solution. Zabbix offers advanced monitoring, alerting, and visualization features today which are missing in other monitoring systems, even some of the best commercial ones
- %package server
- Summary:server version of zabbix
- Group: System Environment/Daemons
- Requires(post): /sbin/chkconfig
- Requires(preun): /sbin/chkconfig
- Requires(preun): /sbin/service
- Requires(postun): /sbin/service
- %description server
- Zabbix server common files
- %package agentd
- Summary: Zabbix Agent
- Group: Applications/Internet
- Requires(pre): shadow-utils
- Requires(post): /sbin/chkconfig
- Requires(preun): /sbin/chkconfig
- Requires(preun): /sbin/service
- Requires(postun): /sbin/service
- %description agentd
- The Zabbix client agent, to be installed on monitored systems.
- %package proxy
- Summary: Zabbix Proxy
- Group: Applications/Internet
- Requires(pre): shadow-utils
- Requires(post): /sbin/chkconfig
- Requires(preun): /sbin/chkconfig
- Requires(preun): /sbin/service
- Requires(postun): /sbin/service
- Requires: fping
- %description proxy
- The Zabbix proxy
- %package web
- Summary: Zabbix Web
- Group: Applications/Internet
- BuildArch: noarch
- Requires(pre): shadow-utils
- Requires(post): /sbin/chkconfig
- Requires(preun): /sbin/chkconfig
- Requires(preun): /sbin/service
- Requires(postun): /sbin/service
- Requires: dejavu-sans-fonts
- %description web
- The Zabbix web
- %prep
- %setup -q
- %build
- common_flags=”
- –enable-dependency-tracking
- –enable-proxy
- –enable-agent
- –enable-ipv6
- –with-net-snmp
- –with-libcurl
- –disable-java
- –sysconfdir=%{_sysconfdir}/zabbix
- –datadir=%{_sharedstatedir}
- ”
- %configure $common_flags –enable-server –with-mysql –with-cc-opt=“%{optflags} $(pcre-config –cflags)”
- make %{?_smp_mflags}
- #./configure –prefix=/usr/local –sysconfdir=/etc/zabbix –libdir=/usr/lib –mandir=/usr/share/man –enable-proxy –enable-agent –with-sqlite3
- #make %{?_smp_mflags}
- %install
- %{__rm} -rf $RPM_BUILD_ROOT
- [ “%{buildroot}” != “/” ] && %{__rm} -rf %{buildroot}
- #%{__make} DESTDIR=%{buildroot} install
- %{__install} -d %{buildroot}%{_sbindir}
- %{__install} -d %{buildroot}%{_sysconfdir}/rc.d/init.d
- %{__install} -d %{buildroot}%{_datadir}/%{name}
- %{__install} -d %{buildroot}%{_sysconfdir}/%{name}/scripts
- %{__install} -d %{buildroot}%{_sysconfdir}/%{name}/zabbix_agentd.conf.d
- %{__install} -d %{buildroot}%{_mandir}/man1/
- %{__install} -d %{buildroot}%{_mandir}/man8/
- %{__install} -d %{buildroot}%{_localstatedir}/log/%{name}
- %{__install} -d %{buildroot}%{_localstatedir}/run/%{name}
- %{__install} -d %{buildroot}%{_sysconfdir}/%{name}/externalscripts
- %{__install} -d %{buildroot}%{_sysconfdir}/%{name}/alertscripts
- %{__install} -d %{buildroot}%{_datadir}/%{name}
- %{__make} DESTDIR=$RPM_BUILD_ROOT install
- #%{__mkdir} -p $RPM_BUILD_ROOT%{_initrddir}
- %{__install} -m 755 misc/init.d/fedora/core/zabbix_agentd $RPM_BUILD_ROOT%{_initrddir}/zabbix_agentd
- %{__install} -m 755 misc/init.d/fedora/core/zabbix_server $RPM_BUILD_ROOT%{_initrddir}/zabbix_server
- %{__install} -m 755 misc/init.d/fedora/core/zabbix_server $RPM_BUILD_ROOT%{_initrddir}/zabbix_proxy
- %{__mv} frontends/php $RPM_BUILD_ROOT/%{_datadir}/zabbix
- %{__sed} -i “s@BINARY_NAME=zabbix_server@BINARY_NAME=zabbix_proxy@g” $RPM_BUILD_ROOT%{_initrddir}/zabbix_proxy
- %{__sed} -i “s@BASEDIR=/usr/local@BASEDIR=/usr@g” $RPM_BUILD_ROOT%{_initrddir}/zabbix_server
- %{__sed} -i “s@BASEDIR=/usr/local@BASEDIR=/usr@g” $RPM_BUILD_ROOT%{_initrddir}/zabbix_agentd
- %{__sed} -i “s@BASEDIR=/usr/local@BASEDIR=/usr@g” $RPM_BUILD_ROOT%{_initrddir}/zabbix_proxy
- install -m 0755 -p src/zabbix_server/zabbix_server $RPM_BUILD_ROOT%{_sbindir}/
- install -m 0755 -p src/zabbix_proxy/zabbix_proxy $RPM_BUILD_ROOT%{_sbindir}/
- install -m 0755 -p src/zabbix_get/zabbix_get $RPM_BUILD_ROOT%{_sbindir}/
- install -m 0755 -p src/zabbix_sender/zabbix_sender $RPM_BUILD_ROOT%{_sbindir}/
- install -m 0755 -p src/zabbix_agent/zabbix_agent $RPM_BUILD_ROOT%{_sbindir}/
- install -m 0755 -p src/zabbix_agent/zabbix_agentd $RPM_BUILD_ROOT%{_sbindir}/
- install -m 0644 -p conf/zabbix_server.conf $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/
- install -m 0644 -p conf/zabbix_agent.conf $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/
- install -m 0644 -p conf/zabbix_agentd.conf $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/
- install -m 0644 -p conf/zabbix_proxy.conf $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/
- install -m 0644 -p man/zabbix_agentd.man $RPM_BUILD_ROOT%{_mandir}/man8/zabbix_agentd.8
- install -m 0644 -p man/zabbix_server.man $RPM_BUILD_ROOT%{_mandir}//man8/zabbix_server.8
- install -m 0644 -p man/zabbix_proxy.man $RPM_BUILD_ROOT%{_mandir}/man8/zabbix_proxy.8
- install -m 0644 -p man/zabbix_get.man $RPM_BUILD_ROOT%{_mandir}/man1/zabbix_get.1
- install -m 0644 -p man/zabbix_sender.man $RPM_BUILD_ROOT%{_mandir}/man1/zabbix_sender.1
- %{__tar} xf %{SOURCE1} -C $RPM_BUILD_ROOT%{_sysconfdir}/%{name}
- install -m 0644 -p %{SOURCE2} $RPM_BUILD_ROOT/%{_datadir}/%{name}
- install -d $RPM_BUILD_ROOT/%{_datadir}/%{name}/database/mysql/
- install -m 0644 -p database/mysql/* $RPM_BUILD_ROOT/%{_datadir}/%{name}/database/mysql/
- sed -i
- -e `s|# PidFile=.*|PidFile=%{_localstatedir}/run/%{name}/zabbix_agentd.pid|g`
- -e `s|^LogFile=.*|LogFile=%{_localstatedir}/log/%{name}/zabbix_agentd.log|g`
- -e `/# UnsafeUserParameters=0/aUnsafeUserParameters=1
` - -e `/# Include.*zabbix_agentd.conf.d//aInclude=/etc/zabbix/zabbix_agentd.conf.d/
` - -e `s|# LogFileSize=.*|LogFileSize=0|g`
- -e `s|/usr/local|/usr|g`
- $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/zabbix_agentd.conf
- sed -i
- -e `s|/usr/local|/usr|g`
- -e `/# UnsafeUserParameters=0/aUnsafeUserParameters=1
` - -e `s@# Include=/usr/etc/zabbix_agentd.conf.d@Include=/etc/zabbix/zabbix_agentd.conf.d@g`
- $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/zabbix_agent.conf
- sed -i
- -e `s|# PidFile=.*|PidFile=%{_localstatedir}/run/%{name}/zabbix_server.pid|g`
- -e `s|^LogFile=.*|LogFile=%{_localstatedir}/log/%{name}/zabbix_server.log|g`
- -e `s|# LogFileSize=.*|LogFileSize=0|g`
- -e `s|^DBUser=root|DBUser=zabbix|g`
- -e `/# DBPassword=/aDBPassword=zabbix
` - -e `s|# DBSocket=/tmp/mysql.sock|DBSocket=%{_sharedstatedir}/mysql/mysql.sock|g`
- -e `s|# ExternalScripts=${datadir}/zabbix/externalscripts|ExternalScripts=%{_sysconfdir}/%{name}/externalscripts|`
- -e `s|/usr/local|/usr|g`
- $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/zabbix_server.conf
- sed -i
- -e `s|# PidFile=.*|PidFile=%{_localstatedir}/run/%{name}/zabbix_proxy.pid|g`
- -e `s|^LogFile=.*|LogFile=%{_localstatedir}/log/%{name}/zabbix_proxy.log|g`
- -e `s|# LogFileSize=.*|LogFileSize=0|g`
- -e `s|^DBUser=root|DBUser=zabbix|g`
- -e `/# DBPassword=/aDBPassword=zabbix
` - -e `s|# DBSocket=/tmp/mysql.sock|DBSocket=%{_sharedstatedir}/mysql/mysql.sock|g`
- -e `s|# ExternalScripts=${datadir}/zabbix/externalscripts|ExternalScripts=%{_sysconfdir}/%{name}/externalscripts|`
- -e `s|/usr/local|/usr|g`
- $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/zabbix_proxy.conf
- %clean
- %{__rm} -rf $RPM_BUILD_ROOT
- %files server
- %defattr(-,root,root,-)
- %doc
- %attr(0755,zabbix,zabbix) %dir %{_localstatedir}/log/%{name}
- %attr(0775,root,zabbix) %dir %{_localstatedir}/run/%{name}
- %config(noreplace) %{_sysconfdir}/%{name}/zabbix_server.conf
- %config(noreplace) %{_sysconfdir}/%{name}/scripts
- %{_sbindir}/zabbix_sender
- %{_sbindir}/zabbix_server
- %{_sbindir}/zabbix_get
- %{_initrddir}/zabbix_server
- %config(noreplace) %{_sysconfdir}/%{name}/externalscripts
- %config(noreplace) %{_sysconfdir}/%{name}/alertscripts
- %{_mandir}/man8/zabbix_server.8*
- %{_mandir}/man1/zabbix_get.1*
- %{_mandir}/man1/zabbix_sender.1*
- %files agentd
- %defattr(-,root,root,-)
- %doc
- %attr(0755,zabbix,zabbix) %dir %{_localstatedir}/log/%{name}
- %attr(0775,root,zabbix) %dir %{_localstatedir}/run/%{name}
- %attr(0775,root,zabbix) %dir %{_sysconfdir}/%{name}/zabbix_agentd.conf.d
- %config(noreplace) %{_sysconfdir}/%{name}/zabbix_agent.conf
- %config(noreplace) %{_sysconfdir}/%{name}/zabbix_agentd.conf
- %config(noreplace) %{_sysconfdir}/%{name}/scripts
- %{_sbindir}/zabbix_sender
- %{_sbindir}/zabbix_agent
- %{_sbindir}/zabbix_agentd
- %{_sbindir}/zabbix_get
- %attr(0755,root,zabbix) %{_sysconfdir}/%{name}/scripts/*
- %attr(0755,root,zabbix) %{_sysconfdir}/%{name}/zabbix_agentd.conf.d/*
- %{_initrddir}/zabbix_agentd
- #%{_localstatedir}/run/%{name}
- #%{_localstatedir}/log/%{name}
- %config(noreplace) %{_sysconfdir}/%{name}/zabbix_agentd.conf.d
- %{_mandir}/man8/zabbix_agentd.8*
- %{_mandir}/man1/zabbix_get.1*
- %{_mandir}/man1/zabbix_sender.1*
- %files proxy
- %defattr(-,root,root,-)
- %doc
- %attr(0755,zabbix,zabbix) %dir %{_localstatedir}/log/%{name}
- %attr(0775,root,zabbix) %dir %{_localstatedir}/run/%{name}
- %config(noreplace) %{_sysconfdir}/%{name}/zabbix_proxy.conf
- %config(noreplace) %{_sysconfdir}/%{name}/scripts
- %{_sbindir}/zabbix_proxy
- %{_initrddir}/zabbix_proxy
- %{_mandir}/man8/zabbix_proxy.8*
- #%{_localstatedir}/run/%{name}
- #%{_localstatedir}/log/%{name}
- %config(noreplace) %{_sysconfdir}/%{name}/externalscripts
- %config(noreplace) %{_sysconfdir}/%{name}/alertscripts
- %files web
- %defattr(-,root,root,-)
- %config(noreplace) %{_datadir}/%{name}/*
- %post server
- if [ $1 -eq 1 ]; then
- /sbin/chkconfig zabbix_server on
- fi
- %post agentd
- if [ $1 -eq 1 ]; then
- sed -i “s@Hostname=Zabbix server@Hostname=$HOSTNAME@g” /etc/zabbix/zabbix_agentd.conf
- getent group zabbix >/dev/null || groupadd -r zabbix
- getent passwd zabbix >/dev/null || useradd -r -g zabbix -d %{_sharedstatedir}/zabbix -s /sbin/nologin -c “zabbix user” zabbix
- /sbin/chkconfig zabbix_agentd on
- /sbin/service zabbix_agentd start
- chown root:zabbix /bin/netstat
- chmod 4755 /bin/netstat
- fi
- %post proxy
- if [ $1 -eq 1 ]; then
- /sbin/chkconfig zabbix_proxy on
- fi
- %post web
- mv %{_datadir}/%{name}/php/* %{_datadir}/%{name}
- rm -rf %{_datadir}/%{name}/php
- [ -d “/etc/http/conf.d” ] && cp %{_datadir}/%{name}/conf/zabbix-web.conf /etc/http/conf.d &&chown -R apache.apache %{_datadir}/%{name} && cat <<EOF
- ——————————————————–
- you installed Apache Server,the zabbix-web.conf configuration file in /etc/http/conf.d
- ——————————————————–
- EOF
- [ -d “/etc/http/conf.d” ] || cat <<EOF
- ——————————————————————————————-
- you should configure Web Server,the web file in %{_datadir}/%{name}
- ——————————————————————————————-
- EOF
- #then
- #mv %{_datadir}/%{name} /var/www/html/
- cat <<EOF
- ———————————————————————————————
- Author:itnihao Mail:itnihao@qq.com Blog: http://itnihao.blog.51cto.com
- you can configure web server on directory /usr/share/zabbix
- if your web server is Apache,you can use the /etc/httpd/conf.d/zabbix-web.conf file to
- start your web server,and others you must configure your web server
- to running the server and web, you will install packages;
- yum install httpd php mysql mysql-server php-mysql httpd-manual mod_ssl mod_perl mod_auth_mysql php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc php-bcmath mysql-connector-odbc mysql-devel libdbi-dbd-mysql net-snmp-devel curl-devel
- #setting /etc/php.ini for zabbix
- sed -i “s/;date.timezone =/date.timezone = Asia/Shanghai/g” /etc/php.ini
- sed -i “s#max_execution_time = 30#max_execution_time = 300#g” /etc/php.ini
- sed -i “s#post_max_size = 8M#post_max_size = 32M#g” /etc/php.ini
- sed -i “s#max_input_time = 60#max_input_time = 300#g” /etc/php.ini
- sed -i “s#memory_limit = 128M#memory_limit = 128M#g” /etc/php.ini
- sed -i “/;mbstring.func_overload = 0/ambstring.func_overload = 2
” /etc/php.ini - #config apache
- sed -i “s/DirectoryIndex index.html index.html.var/DirectoryIndex index.php index.html index.html.var/g” /etc/httpd/conf/httpd.conf
- sed -i “s/ServerTokens OS/ServerTokens Prod/g” /etc/httpd/conf/httpd.conf
- #create mysql database to zabbix
- service mysqld start
- chkconfig mysqld on
- mysqladmin -u root password `mysqlpass`
- mysql -uroot -pmysqlpass -e “create database zabbix character set utf8”
- mysql -uroot -pmysqlpass -e “grant all privileges on zabbix.* to zabbix@localhost identified by `zabbix`”
- mysql -uroot -pmysqlpass -e “flush privileges”
- #source zabbix database
- cd /usr/share/zabbix
- mysql -uzabbix -pzabbix zabbix < ./database/mysql/schema.sql
- mysql -uzabbix -pzabbix zabbix < ./database/mysql/images.sql
- mysql -uzabbix -pzabbix zabbix < ./database/mysql/data.sql
- ———————————————————————————————-
- EOF
- #fi
- %pre server
- #add zabbix to services
- grep zabbix /etc/services
- [ “$?” != 0 ] && cat >> /etc/services <<EOF
- zabbix-agent 10050/tcp #Zabbix Agent
- zabbix-agent 10050/udp #Zabbix Agent
- zabbix-trapper 10051/tcp #Zabbix Trapper
- zabbix-trapper 10051/udp #Zabbix Trapper
- EOF
- # Add the “zabbix” user
- getent group zabbix >/dev/null || groupadd -r zabbix
- getent passwd zabbix >/dev/null || useradd -r -g zabbix -d %{_sharedstatedir}/zabbix -s /sbin/nologin -c “zabbix user” zabbix
- %pre agentd
- #add zabbix to services
- grep zabbix /etc/services
- [ “$?” != 0 ] && cat >> /etc/services <<EOF
- zabbix-agent 10050/tcp #Zabbix Agent
- zabbix-agent 10050/udp #Zabbix Agent
- zabbix-trapper 10051/tcp #Zabbix Trapper
- zabbix-trapper 10051/udp #Zabbix Trapper
- EOF
- # Add the “zabbix” user
- getent group zabbix >/dev/null || groupadd -r zabbix
- getent passwd zabbix >/dev/null || useradd -r -g zabbix -d %{_sharedstatedir}/zabbix -s /sbin/nologin -c “zabbix user” zabbix
- %preun server
- if [ “$1” = 0 ]
- then
- /sbin/service zabbix_server stop >/dev/null 2>&1
- /sbin/chkconfig –del zabbix_server
- fi
- %preun proxy
- if [ “$1” = 0 ]
- then
- /sbin/service zabbix_proxy stop >/dev/null 2>&1
- /sbin/chkconfig –del zabbix_proxy
- fi
- %preun agentd
- if [ “$1” = 0 ]
- then
- /sbin/service zabbix_agentd stop >/dev/null 2>&1
- /sbin/chkconfig –del zabbix_agentd
- fi
- %changelog
- * Fri Jan 25 2013 First version is build ok <itnihao@qq.com>
- – 2.0.4
待續
本文轉自it你好 51CTO部落格,原文連結:http://blog.51cto.com/itnihao/1125883,如需轉載請自行聯絡原作者
相關文章
- RPM 的 spec 檔案如何編寫
- 如何編寫 RPM 的 spec 檔案
- RPM打包技術與典型SPEC檔案分析(轉)
- rpm包的校驗和檔案讀取
- 製作PHP的RPM包例項PHP
- 如何製作一個 RPM 檔案
- Pyinstaller利用spec檔案打包的使用模板
- 如何不安裝但是獲取rpm包中的檔案
- 《RPM原始碼包的製作》RHEL6原始碼
- Linux自己製作rpm包Linux
- Centos6系統RPM包安裝Zabbix3.0CentOS
- Centos 7 製作MySQL 5.7 RPM包CentOSMySql
- 檢視某個檔案屬於哪個RPM包
- rpm包的查詢
- 自制mysql的rpm包MySql
- 湃兔更新映象檔案的製作與燒寫
- RPM包的權威指南。
- Python製作egg檔案包Python
- 像MIUI一樣做Zabbix二次開發(3)——Zabbix深度定製的意義UI
- 原始碼包和rpm包的區別原始碼
- 專業rpm包製作神器multipkg介紹
- Python檔案讀寫詳解及設定檔案的字元編碼Python字元
- 檔案的讀寫
- 構建自己的postgresql rpm包SQL
- 提取rpm檔案內容
- J2ee檔案讀寫包錯
- linux原始碼包與RPM包的區別Linux原始碼
- Java的WAR包檔案分析Java
- RPM包的安裝與升級
- 查詢命令對應的RPM包
- 普通檔案的讀寫
- 配置檔案的編寫
- 使用CheckInstall從原始碼製作RPM安裝包原始碼
- 從Spec Export - Sketch Measure網頁生成Storyboard檔案Export網頁
- 怎樣製作證書請求檔案CSR
- oracle利用utl_file包來讀寫檔案Oracle
- .Prettierrc檔案的設定
- 製作URL檔案的方法