You are on page 1of 145

ZABBIX

----- zabbix

QQ 972322817 itnihao@qq.com

ZABBIX
zabbix

http://www.itnihao.com

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
1. ........................................................................................................................................ 4
2. ............................................................................................................................................ 4
3. Zabbix .....................................................................................................................................5
3.1 Zabbix .......................................................................................................................... 6
3.2 ..................................................................................................................................7
4. ........................................................................................................................................ 8
4.1 lamp ................................................................................................... 8
4.2 lamp ............................................................................................... 8
4.3 server ..................................................................................................9
4.3.1 zabbix ................................................................................................... 9
4.3.2 zabbix ................................................................................. 11
4.3.3 zabbix mysql ................................................. 11
4.3.4 service ............................................................................................ 12
4.3.5 zabbix_server.conf .................................................................... 12
4.3.7 apache ................................................................................ 15
4.3.8 zabbix ............................................................................................ 15
4.4 web zabbix............................................................................................... 15
4.5 agentd ...............................................................................................19
4.5.1 linux .................................................................................... 19
4.5.1.1snmp ...................................................................................................... 20
4.5.2 windows .......................................................................................... 21
5. Zabbix .......................................................................................................................24
5.1 Zabbix ............................................................................................ 24
5.2 -- Hosts................................................................. 24
5.3 ................................................................................................................28
5.2.1key ............................................................................................................ 28
5.2.2web ............................................................................................... 30
5.4 key.................................................................................................................34
5.5 Items.........................................................................................................................35
5.6 Triggers.................................................................................................................... 37
5.6.1 Triggers................................................................................................... 37
5.6.2 ......................................................................................................38
5.7 Actions..................................................................................................................... 48
5.8 Medias......................................................................................................................49
5.9 Users.........................................................................................................................49
5.10 WEB Monitorings..................................................................................................52
5.11 Graphs....................................................................................................................56
5.12 Screens................................................................................................................... 57
5.13 Maps.......................................................................................................................60
5.14 MySQL ......................................................................................................... 62
5.15 SNMP ........................................................................................................... 62
http://www.itnihao.com

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
5.16 ............................................................................................................. 62
5.17 Templates............................................................................................................... 66
5.18 Reports............................................................................................67
5.19 Macros.................................................................................................................... 69
5.20 ......................................................................................................... 69
5.21 Inventory.................................................................................................................70
5.22 Export/Import XML..........................................................................................................70
5.23 Maintenance..............................................................................................71
5.24 Proxy ....................................................................................................................73
5.25 zabbix ( postfix ).........................................................................75
5.22.1 meida types................................................................................................... 76
5.22.2 actions........................................................................................................... 77
5.22.3 zabbix .................................................................................................... 79
5.26 ( mail.py ).................................................................................... 81
5.27 ............................................................................................. 84
5.27.1 ........................................................................................................85
5.27.2 ........................................................................................................87
5.27.3 ........................................................................................................89
5.27.4 ........................................................................................................89
5.27.5 ........................................................................................89
5.28 ............................................................................................................. 89
5.28.1 ................................................................................................89
5.28.2 ................................................................................................90
5.28.3 ....................................................................................91
5.28.4 Snmp ............................................................................................. 91
5.28.5 ....................................................... 91
5.29 Zabbix 4 ..........................................................................................92
5.30 zabbix_--agentd........................................................................................ 94
5.31 zabbix_---SNMP.......................................................................................94
5.32 zabbix_---IPMI......................................................................................... 94
5.33 zabbix_---JMX..........................................................................................97
6. Zabbix -............................................................................................. 99
6.1 ............................................................................................................99
4.1.1 ..................................................................................................99
6.1 .......................................................................................100
6.2 low-level discovery ............................................................... 102
6.2.1 zabbix ................................................................................................ 103
6.2.2 ................................................................................................103
6.2.3 key ............................................................................................105
6.2.4 web low-level discovery....................................................................... 106
7. zabbix ......................................................................................................................... 109
http://www.itnihao.com

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
7.1 Zabbix .............................................................................................................. 109
7.2 zabbix_server.conf ................................................................................................... 109
7.3 zabbix_agend.conf ................................................................................................... 109
7.4 Zabbix .......................................................................................................... 109
7.5 zabix .....................................................................................................109
8. ....................................................................................................................120
9. zabbix rpm ...........................................................................................................121

http://www.itnihao.com

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

1.

zabbix
------------ zabbix
v2.0

itnihao

GPL
www.itnihao.com
Mail
admin@itnihao.com
zabbix QQ 92242469216490997()

2012-12-07

V1.0

2013-01-23

V1.1

2013-02-08

V1.2

2013-02-11

V1.2

2013-05-22

V1.3

2013-06-06

rpm v1.4
proxyapi

2013-10-26

v2.0

zabbix zabbix zabbix

zabbix

2.

zabbix

pengyaolihuipeng

http://www.itnihao.com

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

3.

Zabbix
Zabbix

http://www.zabbix.com
2.0.X, 2.12.2
Zabbix 2.0 http://www.zabbix.com/documentation/2.0/manual
Zabbix C/S B/S web
agent SNMP
Server SNMP agent MySQLORACLE
php+apache web
Zabbix
ServerZabbix Server LAMP Linux+Apache+Mysql+PHP
LNMP
Agent agent OS LinuxHPUXSolarisSun
windows
SNMP

http://www.itnihao.com

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

3.1

Zabbix

FTP

low discoverykey

server api

snmp( trapping and polling)IPMIJMXSSHTELNET

http://www.itnihao.com

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

WEB
ZABBIX
Api
api

https://www.zabbix.com/documentation/2.0/manual/introduction/features

3.2

Server

item

server item server

Api

agent,

4.

Zabbix Server CentOSRedHat LinuxDebain Linux

centos6.3_X64
yum
rhel6.3rhel6.4 64 suseubuntu
300G zabbix

/boot

100M-2G

http://www.itnihao.com

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
Swap
/

10G

yum epel yum


shell#rpm
-vih
http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

rpm

-ivh

epel

4.1

lamp
yum -y install

gcc gcc-c++ autoconf

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

net-snmp-devel curl-devel

4.2

mysql-connector-odbc

unixODBC-devel

mysql-devel

OpenIPMI-devel

libdbi-dbd-mysql

java-devel

lamp
php
php.ini

shell#vim

/etc/php.ini

( zabbix web

php.ini
php )
date.timezone = Asia/Shanghai
max_execution_time = 300
post_max_size = 32M
max_input_time=300
memory_limit = 128M
mbstring.func_overload = 2

sed
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\n"

/etc/php.ini

httpdmysqld
shell#chkconfig mysqld

on

http://www.itnihao.com

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
sehll#chkconfig httpd

on

sehll#service

mysqld

start

sehll#service

httpd

start

4.3

server

rpm rpm
lamplnmp rpm

zabbix 2.0.8
http://www.zabbix.com/download.php

http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/

4.3.1 zabbix
shell#http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.0.8/zabbix
-2.0.8.tar.gz
( 2.0.9, 2014 2.2
zabbix
rpm zabbix )
zabbix
shell#groupadd zabbix -g 201
shell#useradd -g zabbix -u 201 -m zabbix
shell#tar xf zabbix-2.0.8.tar.gz

http://www.itnihao.com

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

shell#./configure --prefix=/usr --sysconfdir=/etc/zabbix --enable-server --enable-proxy


--enable-agent
--enable-ipv6 --with-mysql=/usr/bin/mysql_config --with-net-snmp
--with-libcurl --with-openipmi
--with-unixodbc --with-ldap --with-ssh2 --enable-java
--enable-server

configure
shell#make
http://www.itnihao.com

10

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
shell#make install

rpm
rpm https://www.github.com/itnihao/zabbix rpm

4.3.2 zabbix
shell#vim /etc/services
( rhel )
zabbix-agent
10050/tcp
#Zabbix Agent
zabbix-agent
10050/udp
#Zabbix Agent
zabbix-trapper 10051/tcp
#Zabbix Trapper
zabbix-trapper 10051/udp
#Zabbix Trapper

4.3.3 zabbix mysql


Shell#cd
PATH/zabbix-2.0.8
( zabbix )
shell#mysqladmin -uroot password 'mysql_pass'; mysql root
Shell#mysql -uroot -p
mysql>create database zabbix character set utf8;
utf8 web

mysql>grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';


mysql>flush privileges;

Shell#mysql -uzabbix -pzabbix zabbix

http://www.itnihao.com

11

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

# zabbix

shell#mysql -uzabbix -pzabbix zabbix < ./database/mysql/schema.sql


shell#mysql -uzabbix -pzabbix zabbix < ./database/mysql/images.sql
shell#mysql -uzabbix -pzabbix zabbix < ./database/mysql/data.sql

shell#mkdir /var/log/zabbix
sehll#chown zabbix.zabbix /var/log/zabbix

4.3.4 service
shell#cp misc/init.d/fedora/core/zabbix_* /etc/init.d/
shell#chmod 755 /etc/init.d/zabbix_*
shell#sed -i "s#BASEDIR=/usr/local#BASEDIR=/usr/#g" /etc/init.d/zabbix_server
shell#sed -i "s#BASEDIR=/usr/local#BASEDIR=/usr/#g" /etc/init.d/zabbix_agentd

4.3.5 zabbix_server.conf

/etc/zabbix/zabbix_server.conf

DBName=zabbix

DBUser=zabbix

DBPassword=zabbix

http://www.itnihao.com

12

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

mysql rpm mysql.sock


Sed
shell#sed
/etc/zabbix/zabbix_server.conf
shell#sed
-i
/etc/zabbix/zabbix_server.conf
shell#sed
-i
/etc/zabbix/zabbix_server.conf

-i

"s/DBUser\=root/DBUser\=zabbix/g"
"/#

DBPassword=/aDBPassword=zabbix\n"

"s#tmp/zabbix_server.log#var/log/zabbix/zabbix_server.log#g"

Shell#egrep -v "(#|^$)" /etc/zabbix/zabbix_server.conf


LogFile=/var/log/zabbix/zabbix_server.log
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/var/lib/mysql/mysql.sock
DBPort=3306
StartPollers=160
()
StartTrappers=20
()
StartPingers=100
()
StartDiscoverers=120
()
MaxHousekeeperDelete=5000
()
CacheSize=1024M
()
StartDBSyncers=16
()
HistoryCacheSize=1024M
()
TrendCacheSize=1024M
()
HistoryTextCacheSize=512M
()
AlertScriptsPath=/etc/zabbix/alertscripts
LogSlowQueries=1000

2.3.6 zabbix_agentd.conf

/etc/zabbix/zabbix_agentd.conf agentd agent

angentd host server


server
http://www.itnihao.com

13

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
server zabbix_agentd.conf
4
Server=127.0.0.1 ip zabbix_server
ip
ServerActive=127.0.0.1 ip
/tmp/zabbix_agentd.log
UnsafeUserParameters=0 key
1
Include=/etc/zabbix/zabbix_agentd.conf.d/ agentd

192.168.1.89 zabbix ip 20051 10051


sed
shell#sed
-i
"s/Server\=127.0.0.1/Server\=127.0.0.1,192.168.1.89/g"
/etc/zabbix/zabbix_agentd.conf
shell#sed
-i
"s/ServerActive\=127.0.0.1/ServerActive\=192.168.1.89:10051/g"
/etc/zabbix/zabbix_agentd.conf
shell#sed
-i
"s#tmp/zabbix_agentd.log#var/log/zabbix/zabbix_agentd.log#g"
/etc/zabbix/zabbix_agentd.conf
shell#sed
-i
"#UnsafeUserParameters=0#aUnsafeUserParameters=1\n"
/etc/zabbix/zabbix_agentd.conf

Shell#egrep -v "(#|^$)"

/etc/zabbix/zabbix_agentd.conf

LogFile=/var/log/zabbix/zabbix_agentd.log
EnableRemoteCommands=0
Server=127.0.0.1,192.168.1.89
StartAgents=8
ServerActive=192.168.1.89:10051
Hostname=nat.kx1d.com
Timeout=30
Include=/etc/zabbix/zabbix_agentd.conf.d/
UnsafeUserParameters=1

Server ip server server


ServerActive server 10051
ip1,ip2 server

http://www.itnihao.com

14

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

4.3.7 apache
shell#cp -r ./frontends/php/ /var/www/html/zabbix
shell#chown -R apache.apache /var/www/html/zabbix

4.3.8 zabbix
zabbix
shell#chkconfig zabbix_server on
shell#chkconfig zabbix_agentd on
shell#service zabbix_server start
shell#service zabbix_agentd start

zabbix server
web

4.4

web zabbix

http://192.168.1.89/zabbix

http://www.itnihao.com

15

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

ip localhost
3306
zabbix
http://www.itnihao.com

16

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
zabbix
zabbix
test connection OK

Host ip
Name ip
http://www.itnihao.com

17

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

zabbix.conf.php apache
/var/www/html/zabbix apche.apache

chown -R apache.apache

/var/www/html/zabbix

http://www.itnihao.com

18

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

admin zabbix

4.5

agentd

4.5.1 linux
zabbix_server zabbix_agentd
linux
configure
GCCmake
() rpm

shell#groupadd
shell#useradd -g
shell#tar xf
Shell#cd

zabbix
zabbix

-g
-u

201
201

-m

zabbix

zabbix-2.0.8.tar.gz

zabbix-2.0.8

shell#./configure --prefix=/usr

--sysconfdir=/etc//zabbix

--enable-agent

shell#make
http://www.itnihao.com

19

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
shell#make
shell#mkdir
shell#chown
shell#cp

install
/var/log/zabbix
zabbix.zabbix
/var/log/zabbix

misc/init.d/fedora/core/zabbix_agentd

shell#chmod

/etc/init.d/

755 /etc/init.d/zabbix_agentd

shell#sed -i "s#BASEDIR=/usr/local#BASEDIR=/usr/#g" /etc/init.d/zabbix_agentd


shell#vim

/etc/services

zabbix-agent

10050/tcp

#Zabbix Agent

zabbix-agent

10050/udp

#Zabbix Agent

zabbix-trapper 10051/tcp

#Zabbix Trapper

zabbix-trapper 10051/udp

#Zabbix Trappe

shell#sedi
"s/Server\=127.0.0.1/Server\=127.0.0.1,192.168.1.89/g"
/etc/zabbix/zabbix_agentd.conf
shell#sed
-i
"s/ServerActive\=127.0.0.1/ServerActive\=192.168.1.89:10051/g"
/etc/zabbix/zabbix_agentd.conf
shell#sed
-i
"s#tmp/zabbix_agentd.log#var/log/zabbix/zabbix_agentd.log#g"
/etc/zabbix/zabbix_agentd.conf
shell#sed
-i
"#UnsafeUserParameters=0#aUnsafeUserParameters=1\n"
/etc/zabbix/zabbix_agentd.conf
shell#chkconfig zabbix_agentd on
shell#service zabbix_agentd start

4.5.1.1snmp
# snmpd
agentd snmp agentd
snmp
shell#yum -y install net-snmp
shell#mv /etc/snmpd/snmpd.conf

/etc/snmpd/snmpd.conf.bak

shell#vim /etc/snmpd/snmpd.conf
com2sec mynetwork 192.168.1.89 public_monitor
com2sec mynetwork 127.0.0.1 public
group MyROGroup v2c mynetwork
access MyROGroup "" any noauth prefix all none none
view all included .1 80
shell#chkconfig snmpd on
shell#service snmpd restart
http://www.itnihao.com

20

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

4.5.2 windows
http://www.zabbix.com/downloads/2.0.8/zabbix_agents_2.0.8.win.zip
C:\Program Files\

C:\Program Files\zabbix_agents_2.0.8.win\bin\win32>zabbix_agentd.exe --install -c


"C:\Program Files\zabbix_agents_2.0.8.win\conf\zabbix_agentd.win.conf"

64 64

http://www.itnihao.com

21

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

http://www.itnihao.com

22

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

zabbix_agentd.conf linux

http://www.itnihao.com

23

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

5.

Zabbix

http://ServerIP/zabbix zabbix
admin zabbix
zabbix zabbix

Host Groups->Hosts->Applications->Items->Triggers
->Actions->Medias->User Groups->Users

cacti
zabbix

5.1

Zabbix
Agentd
Snmp
Jmx
Ipmi

5.2

-- Hosts
Host Zabbix host
Configuration->Hosts->Create Host

http://www.itnihao.com

24

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

NameGroupsIP ,Link Templates


save
host agent unmonitor
Zabbix link
Templates

hosts Host Group


Configuration->Host Group->Create Host Group

http://www.itnihao.com

25

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

hostname

, UTF-8

:Agent, SNMP, JMX and IPMI


Add IP/DNS

ip

ip

DNS

DNS

zabbix IP
DNS

IP
DNS

IP
DNS

TCP zabbix 10050

zabbix zabbix
Monitored

Not monitored

http://www.itnihao.com

26

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

http://www.itnihao.com

27

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

5.3

Items key
Triggers
Graphs

key
/etc/passwd key

5.2.1key

#grep -v "#" /etc/zabbix/zabbix_agentd.conf|grep -v "^$"


LogFile=/var/log/zabbix/zabbix_agentd.log

EnableRemoteCommands=0

Server=127.0.0.1,192.168.1.254.200

# ip key

http://www.itnihao.com

28

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
StartAgents=8

ServerActive=192.168.1.254:10051

# ip

Hostname=zabbixtest.itnihao.cn

server
Timeout=30

Include=/etc/zabbix/zabbix_agentd.conf.d/

UnsafeUserParameters=1

# key

#cat /etc/zabbix/zabbix_agentd.conf.d/count_line_passwd.conf
UserParameter=count.line.passwd,wc -l /etc/passwd|awk '{print $1}'

#service zabbix_agentd restart


Key
#zabbix_get -s 127.0.0.1 -k count.line.passwd

key
zabbix_get

Key

http://www.itnihao.com

29

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

5.2.2web

http://www.itnihao.com

30

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

--------

-------

----------

--------------------------------------------------------------------

key key

triggers
Graphs

http://www.itnihao.com

31

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

-----------

http://www.itnihao.com

--

32

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

http://www.itnihao.com

33

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

grahps
Monitor---grahps--group--host-grahps

5.4

key

key .
key User parameters
https://www.zabbix.com/documentation/2.0/manual/config/items/userparameters
Key
UserParameter=<key>,<command>

/etc/zabbix/zabbix_agentd.conf
UserParameter=get.os.type,head -1 /etc/issue
zabbix_agentd
#service zabbix_agentd
restart
key
#zabbix_get -s 127.0.0.1 -k get.os.type

UserParameter
/etc/zabbix/zabbix_agentd.conf
Include=/etc/zabbix/zabbix_agentd.conf.d/
UserParameter \ ' ` * ? [ ] { } ~ $ ! & ; ( ) < > | # @

/etc/zabbix/zabbix_agentd.conf
UnsafeUserParameters=1
key
;
;
;
;
http://www.itnihao.com

34

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
;
.

2.
UserParameter=wc[*],grep -c "$2" $1
$2,$1 key
#zabbix_get -s
127.0.0.1 -k wc[/etc/passwd,root]
/etc/passwd $1,root $2, key grep -c root

/etc/passwd

[]

icmpping[,,200,,500]

5.5

Items
2.0 zabbix Agent, SNMP, JMX, and IPMI 4
Agentd items key
Item
Configuration->Hosts host items

items item items templates

item
Items

http://www.itnihao.com

35

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

item Satus /
template template
items hosts link to template items
item create item

key zabbix_agentd.conf

http://www.itnihao.com

36

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
key select

item
http://www.zabbix.com/documentation/2.0/manual/config/items

5.6

Triggers

5.6.1 Triggers
Trigger Items triggers actions
trigger item item trigger
trigger trigger
Configuration->Hosts->Triggers trigger trigger
template trigger template
trigger
trigger create trigger

Expression itemSeverity trigger

Zabbix trigger last value </>/=/#/N(


), maximal value for period of time (),

http://www.itnihao.com

37

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
http://www.zabbix.com/documentation/2.0/manual/config/triggers

5.6.2
http://www.linuxmr.com/2012/zabbix2_0614/161.html

{<server>:<key>.<function>(<parameter>)}<operator><constant>
1function

2function parameter
argument
argument
FUNCTION CALL

MEANING

sum(600)

600

sum(#5)

last hash n 3,
7, 2, 6, 5last(#2) 7last(#5) 5
last0
avg, count, last, minand max avg(1h,1d) 1
1
'5m''300s'
'15''86400s'
3

PRIORITY

OPERATOR

DEFINITION

division

Multiplication

Arithmetical minus

Arithmetical plus

http://www.itnihao.com

38

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
Less than:

<

>

&

Logical AND

10

Logical OR

A<B (A<=B-0.000001)
More than.:
A>B (A>=B+0.000001)
Not equal.:
A#B (A<=B-0.000001) |(A>=B+0.000001)
Is equal). :
A=B (A>B-0.000001) & (A<B+0.000001)

www.zabbix.com
{www.zabbix.com:system.cpu.load[all,avg1].last(0)}>5
'{www.zabbix.com:system.cpu.load[all,avg1]'
'www.linuxmr.com''system.cpu.load[all,avg1]'
'last()''>5' www.linuxmr.com
5 PROBLEM

www.zabbix.com
{www.zabbix.com:system.cpu.load[all,avg1].last(0)}>5|{www.zabbix.
com:system.cpu.load[all,avg1].min(10m)}>2
5102

/etc/passwd
diff
{www.zabbix.com:vfs.file.cksum[/etc/passwd].diff(0)}>0
/etc/passwd checksum
/etc/passwd, /etc/inetd.conf, /kernel

http://www.itnihao.com

39

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

min
{www.linuxmr.com:net.if.in[eth0,bytes].min(5m)}>100K
5 eth0 100KB

SMTP

{smtp1.linuxmr.com:net.tcp.service[smtp].last(0)}=0&{smtp2.linuxm
r.com:net.tcp.service[smtp].last(0)}=0
SMTP smtp1.linuxmr.com smtp2.linuxmr.com

zabbix
str():
{zabbix.linuxmr.com:agent.version.str("beta8")}=1
zabbix beta8

{zabbix.linuxmr.com:icmpping.count(30m,0)}>5
zabbix.linuxmr.com 30 5

nodata
{zabbix.linuxmr.com:tick.nodata(3m)}=1
'tick''Zabbix trapper'tick
zabbix_sender 180
http://www.itnihao.com

40

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
PROBLEM

CPU
time
{zabbix:system.cpu.load[all,avg1].min(5m)}>2&{zabbix:system.cpu.l
oad[all,avg1].time(0)}>000000&{zabbix:system.cpu.load[all,avg1].t
ime(0)}<060000
(00:00-06:00)

zabbix
fuzzytime():
{MySQL_DB:system.localtime.fuzzytime(10)}=0
MySQL_DB zabbix server 10 PROBLEM

20 PROBLEM 15

({TRIGGER.VALUE}=0&{server:temp.last(0)}>20)|
({TRIGGER.VALUE}=1&{server:temp.last(0)}>15)
{TRIGGER.VALUE}

http://www.itnihao.com

41

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

{count.line.passwd:count.line.passwd.last(#3,300)}#35
&{count.line.passwd:count.line.passwd.last(#1,300)}#35
300 1 3 35
http://pengyao.org/zabbix-triggers-functions.html
Zabbix

2013-05-06 by pengyao

https://www.zabbix.com/documentation/2.0/manual/appendix/triggers/functi
ons

: pengyao

abschange

:
: float, int, str, text, log
: . 0

1
avg

: #num
: float, int

http://www.itnihao.com

42

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

: .

(#,#55)
(time shift),
avg(3600,86400), Zabbix 1.8.2
change

:
: float, int, str, text, log
: . 01

count

: #num
: float, int, str, text, log
:

#(pattern)
(operator)(time shift).
(iteeger)(float)0.0000001
(operators):
eq:
ne:
gt:
ge:
lt:
le:
like:
eq(), ne, gt, ge, lt, le stringtextlog
like(), eq, ne
:
count(600): 10
count(600,12): 1012
count(600,12,"gt"): 1012
http://www.itnihao.com

43

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
count(#10,12,"gt"): 1012
count(600,12,"gt",86400): 241012
count(600,,,86400): 2410
#num Zabbix 1.6.1, time shift Zabbix 1.8.2

date

:
: (any)
: ( YYYYMMDD), 20031025

dayofmonth

:
: (any)
: (:1-31) Zabbix 1.8.5

dayofweek

:
: (any)
: (:1-7) 17

delta

: #num
: float, int
: (max()-min())

. Zabbix 1.8.2
time_shift.
diff

:
: float, int, str, text, log
: 1 0

fuzzytime

:
: float, int
: 1 Zabbix Server N , 0.

system.localtime Zabbix server .


http://www.itnihao.com

44

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
iregexp

: #num

: #num

: str, log, text


: regexp

last
: float, int, str, text, log
: #num N #num

#num
:
last(0) last(#1)
last(#3) ****3()
**time_shift**
last(0,86400)
history Zabbix
#num Zabbix 1.6.2, timeshift 1.8.2, avg()

logeventid

: string
: log
: Event ID .

,POSIX . 01 Zabbix 1.8.5


.
logseverity

:
: log
: (log severity). 0

N ( Windows event logs). Zabbix Windows


event log Information .
logsource

: string

http://www.itnihao.com

45

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

: log
: . 0

1 Windows event logs . logsource["VMWare Server"]


max

: #num
: float, int
: .

(#). Zabbix 1.8.2 time_shift


avg().
min

: #num
: float, int
: .

(#). Zabbix 1.8.2 time_shift


avg().
nodata

:
: any
: 1(30), 0

.
now

:
: any
: Epoch(197011 00:00:00 UTC)

prev

:
: float, int, str, text, log
: last(#2)

regexp

: string, #num
: str, log, text
: POSIX ,

. 1
0.

http://www.itnihao.com

46

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
str

: string, #num
: str, log, text
:

1
0.
strlen

: #num
: str, log, text
: (), last . strlen(0)

strlen(#1),strlen(#3), strlen(0,86400)
. Zabbix 1.8.4
sum

: #num
: float, int
: .

(#). Zabbix 1.8.2 time_shift


avg
time

:
: any

: HHMMSS123055

zabbbix
SEVERITY

classified

DEFINITION

Not
Unknown severity

Information For information purposes

COLOUR
Grey
Light green

Warning

Be warned

Yellow444444

Average

Average problem

Orange

High

Something important has


Red
happened

Disaster

Disaster. Financial losses, etcBright red

http://www.itnihao.com

47

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

5.7

Actions

Action action
Configuration->Actions->Create Action Action

Event source:
triggers triggers action
Discovery:
Auto registration
Escalations
Subject Message zabbix
{{HOSTNAME}:{TRIGGER.KEY}.last(0)}:
http://www.zabbix.com/documentation/2.0/manual/config/macros/usermacros
Recovery Message
Conditionstrigger
Operation media user

http://www.zabbix.com/documentation/2.0/manual/config/notifications/action
3.27
http://www.itnihao.com

48

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

5.8

Medias

Media Zabbix Media Email/SMS/Jabber/Script


Administrator->Media Type
Email SMTP

type

Email
Script
SMS server modem
Jabber linux , Jabber

5.9

Users

Administrator->Users
User Group zabbix

media

http://www.itnihao.com

49

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

http://www.itnihao.com

50

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

Type
Send to

http://www.itnihao.com

51

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

5.10 WEB Monitorings


Web Monitoring web web
web
zabbix web web monitoring
Configuration->web->Create Scenario Scenario( host
scenariozabbix items hosts )

http://www.itnihao.com

52

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

Application scenario application


Namescenario
Basic authentication
Update intervals
Agent web

Status active
Variables steps

Stepsweb add Login step


index.php

http://www.itnihao.com

53

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

URL web (:)


Post:&
Timeout
Required,
Status codes:
step Monitoring->web

scenario zabbix server items items


triggers web scenario
Configuration->hosts-> scenario host trigger create trigger
select items items items host items
http://www.itnihao.com

54

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
trigger items

items step 3 itemDownload Speed/Response


Code/Response Time, scenario test.fail item trigger
Login trigger 400

scenario step trigger 0 scenario


step step step

http://www.itnihao.com

55

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

web monitoring
Web monitoring

5.11 Graphs
Zabbix Graphs item items

configuration->hosts host graphscreate graphs

http://www.itnihao.com

56

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

Graph type
Y
add items items item

graphs monitoring->graphs
monitoring->last data host item graph

5.12 Screens
Screen host
hosts , graphsmapsserver infos zabbix

configuration->screen->creat screen screen


change

http://www.itnihao.com

57

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

change

http://www.itnihao.com

58

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

monitoring-screen

http://www.itnihao.com

59

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

5.13 Maps
configration-maps, create maps
import map
crate maps save

http://www.itnihao.com

60

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

http://www.itnihao.com

61

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
link

5.14 MySQL
Zabbix MySQL
1 agentd
#vim
/etc/zabbix/zabbix_agentd.conf
UnsafeUserParameters=1
UserParameter=mysql.ping,mysqladmin -uroot -pharry ping|grep alive|wc -l
host agentd
#service zabbix_agentd restart
2 items
web mysql host link template_APP_MySQL host
items MySQL trigger
zabbix mysql mysqladmin mysql

mysql zabbix

zabbix wiki mysql


:http://www.zabbix.com/wiki/howto/monitor/db/mysql/extensive_mysql_monitoring_including
_replication

5.15 SNMP
Zabbix snmp configration hosts snmp
snmp .

5.16
zabbix
agent zabbix server graph
UserParameters
http://www.zabbix.com/documentation/2.0/manual/config/items/userparameters

/etc/zabbix/zabbix_agentd.conf
UnsafeUserParameters=1 0
UserParameter=key,command
key,command
key item

http://www.itnihao.com

62

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

zabbix_agentd.conf zabbix_agentd

ping.ping1
zabbix_get

mysql
#vim /etc/zabbix/zabbix_agentd.conf
UnsafeUserParameters=1
UserParameter=mysql.ping_test[*],mysqladmin -u$1 -p$2 ping|grep alive|wc -l
#service zabbix_agentd restart
zabbix_get

host 192.168.1.89

http://www.itnihao.com

63

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

Items-create Itmes
key mysql.ping_test[root,harry]

http://www.itnihao.com

64

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

graphs---create graph

ADD Items mysql.ping_test--save,

http://www.itnihao.com

65

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

5.17 Templates

template
Configuration->Host Groups->Template->Create Template

Items---create Items-

cteate Items

http://www.itnihao.com

66

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

graph--create graph--

5.18 Reports
zabbix
http://www.itnihao.com

67

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
Status of zabbix: zabbix

Avaliability report

Most busy triggers top 100 triggers


Bar report
test1 server free memory swap free

http://www.itnihao.com

68

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

5.19 Macros
Macros triggeractions
Macros
macros
http://www.zabbix.com/documentation/2.0/manual/config/macros
macros action {{Hostname}:{trigger.key}.last(0)}
Zabbix macros host template macros
:
{macroname}=macrovalue
zabbix zabbix
host link
template zabbix

5.20
zabbix zabbix

http://www.itnihao.com

69

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
http://www.zabbix.com/documentation/2.0/manual/discovery
4 zabbix -

5.21 Inventory
Inventory
host Use profileMAC
Use extended profile

inventory inventory->hosts . OCS

5.22 Export/Import XML


Zabbix XML
XML
cacti
configuration->Templates>Export/Import->Export,Preview
host export xml
http://www.itnihao.com

70

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

5.23 Maintenance
Nagios Schedule downtime for this host Nagios
downtime zabbxi

http://www.itnihao.com

71

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

Action

http://www.itnihao.com

72

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

5.24 Proxy
zabbix ---Proxies

zabbix Proxies zabbix Proxies


zabbix ProxiesProxies zabbix

zabbix Proxies

zabbix

http://www.itnihao.com

73

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
Proxies TCP

zabbix ProxiesProxies zabbix

Proxiesproxy
ProxyLocalBuffer ProxyOfflineBuffer

zabbix ProxiesProxies

Supported by
Function
proxy
Items
Zabbix agent checks

Yes

Zabbix agent checks (active) Yes 1


Simple checks

Yes

Trapper items

Yes

SNMP checks

Yes

SNMP traps

Yes

IPMI checks

Yes

JMX checks

Yes

Log file monitoring

Yes

Internal checks

No

SSH checks

Yes

Telnet checks

Yes

External checks

Yes

Built-in web monitoring

Yes

Network discovery

Yes

Low-level discovery

Yes

Calculating triggers

No

Processing events

No

Sending alerts

No

Remote commands

No

http://www.itnihao.com

74

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

agent zabbix server ip


Proxies ServerActive

zabix

Adding proxies

zabbix

-> DM
proxies
Create proxy

Hostname

proxy name

proxy mode Active - zabbix


- zabbix
hosts

Monitored by proxy

http://www.linuxmr.com/2012/zabbix2_0817/265.html

5.25 zabbix ( postfix )


zabbix
http://www.itnihao.com

75

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
Host Groups->Hosts->Applications->Items->Triggers
->Actions->Medias->User Groups->Users

itemstriggers

5.22.1 meida types

zabbix web ------Administration--------Media types--------Create Media Type()


Create Media Type

Parameter

Description

Description

Media

Type

Email

SMTP server

SMTP

SMTP helo

SMTP helo ,.

SMTP email

email

Create Media Type

( postfix(sendmail)postfix
127.0.0.1)

http://www.itnihao.com

76

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

https://www.zabbix.com/documentation/2.0/manual/web_interface/frontend_sections/administration/mediatypes

5.22.2 actions
1. zabbix"Configation" >> "Actions">>
"Create Actions" Name mysql_baojing Action Operations"
"New""Operation Type""Send message""Send Message to"
Send only to" mysql_baojing
2. save
Zabbix -----Configation-------Actions------------Create Actions------

Action

http://www.itnihao.com

77

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

Name

action

Default operation step duration

Default subject

Default message

Recovery message

Enabled

action

Recovery message

Conditions

http://www.itnihao.com

78

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

Type of calculation and


Conditions

or

PROBLEM
New condition

add

https://www.zabbix.com/documentation/2.0/manual/web_interface/frontend_sections/configuration/actions

5.22.3 zabbix
zabbix====Adimistration=====Users======Admin
Media""Add"
Type "Email"Send to Add
"Save"

http://www.itnihao.com

79

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

http://www.itnihao.com

80

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

add
url

5.26 ( mail.py )
mail.py --

lihuipeng http://lihuipeng.blog.51cto.com/3064864/1066915
1Zabbix create media type

http://www.itnihao.com

81

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
zabbix
cat /etc/zabbix/alertscripts/zabbix_sendmail.py

#!/usr/bin/python
#coding:utf-8
import smtplib
from email.mime.text import MIMEText
import sys
mail_host = 'smtp.163.com'
mail_user = 'monitor_itnihao'
mail_pass = 'my_password'
mail_postfix = '163.com'
def send_mail(to_list,subject,content):
me = mail_user+"<"+mail_user+"@"+mail_postfix+">"
msg = MIMEText(content)
msg['Subject'] = subject
msg['From'] = me
msg['to'] = to_list
try:
s = smtplib.SMTP()
s.connect(mail_host)
s.login(mail_user,mail_pass)
s.sendmail(me,to_list,msg.as_string())
s.close()
return True
except Exception,e:
print str(e)
return False
if __name__ == "__main__":
send_mail(sys.argv[1], sys.argv[2], sys.argv[3])

2create action

http://www.itnihao.com

82

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

http://www.itnihao.com

83

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

3zabbix_server
mkdir -p /etc/zabbix/alertscripts/

zabbix_server.conf
AlertScriptsPath=/etc/zabbix/alertscripts/

#
http://lihuipeng.blog.51cto.com/3064864/1066915

5.27

1000

1. IDC web cdn

http://www.itnihao.com

84

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
2. 5
10 30

3.
4. A AB

5.

5.27.1

Action
Action action

http://www.itnihao.com

85

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

http://www.itnihao.com

86

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

(
)

5.27.2

http://www.itnihao.com

87

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

{Template OS Linux:agent.ping.nodata(5m)}=1&{Template OS Linux:agent.ping.last(#3,5m)}=1


{Template OS Linux:agent.ping.nodata(10m)}=1&{Template OS Linux:agent.ping.last(#3,10m)}=1
{Template OS Linux:agent.ping.nodata(15m)}=1&{Template OS Linux:agent.ping.last(#3,15m)}=1
{Template OS Linux:agent.ping.nodata(30m)}=1&{Template OS Linux:agent.ping.last(#3,30m)}=1

http://www.itnihao.com

88

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
2

5.27.3

1-7,0000-24:00

5.27.4
{Template OS Linux:agent.ping.nodata(5m)}=1&{Template OS Linux:agent.ping.last(#3,5m)}=1

5.27.5

5.28
5.28.1
Agend Graphs
system.users.num( Graphs )

http://www.itnihao.com

89

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

5.28.2

{Template OS Linux:proc.num[,,run].last(0)}>30 30

http://www.itnihao.com

90

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

5.28.3
5.28.4 Snmp
snmp

5.28.5

http://www.itnihao.com

91

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

(1) export ZABBIX_WEB=/var/www/html/zabbix/


(2)wget

https://www.zabbix.org/pootle/export/Zabbix-2.0/zh_CN/LC_MESSAGES/frontend.po

-O

${ZABBIX_WEB}/locale/zh_CN/LC_MESSAGES/frontend.po
(3)cd ${ZABBIX_WEB}/locale/ && ./make_mo.sh .

(4)
2.
windows /var/www/html/zabbix/fonts ()

5.29 Zabbix 4

Agentd
http://www.itnihao.com

92

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
Snmp
Jmx
Ipmi
zabbix

zabbix 4

http://www.itnihao.com

93

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

5.30 zabbix_--agentd
Agentd zabbix

5.31 zabbix_---SNMP
Snmp

5.32 zabbix_---IPMI
Ipmi
ipmi
Ipmi
Intelligent Platform Management Interface Intel
IPMI

IPMI

Ipmi
IPMI
IPMI
IPMI

ipmi
Zabbix ipmi

Zabbix ipmi

2 intel

http://www.itnihao.com

94

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

host
ipmi
# yum install OpenIPMI ipmitool
# service ipmi start

http://www.itnihao.com

95

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

IPMI :
# ipmitool lan set 1 ipaddr 10.10.10.10
# ipmitool lan set 1 netmask 255.255.255.0
# ipmitool lan set 1 defgw ipaddr 10.10.10.1
# ipmitool lan print 1

# ipmitool lan set 1 access on

# ipmitool user set name 10 sensor


# ipmitool user set password 10 sensor

http://www.itnihao.com

96

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
# ipmitool user enable 10
# ipmitool user priv 10 2 1
# ipmitool user list 1

ipmitool -H 10.10.10.10

-Usensor -L USER sensor list

http://www.itnihao.com

97

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

http://www.itnihao.com

98

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

save

itmes

http://www.itnihao.com

99

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

http://www.itnihao.com

100

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

Availability 1 1

http://www.itnihao.com

101

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

zabbix IPMI pollers


ipmi zabbix_server
# sed -i '/# StartIPMIPollers=0/aStartIPMIPollers=5' zabbix_server.conf
# service zabbix-server restart
ipmitool
ipmitool -I lan -H
ipmitool -I lan -H
ipmitool -I lan -H
ipmitool -I lan -H
ipmitool -I lan -H

-U root -P
-U root -P
-U root -P
-U root -P
-U root -P

http://www.itnihao.com

power off ()
power soft ()
power on ()
power reset () //.
power status ()

102

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

key key

5.33 zabbix_---JMX

zabbix_java

--enable-java javajava-devel
#yum install java java-devel

zabbix-java-gateway

#./configure

--enable-java --prefix=/usr

make && make install


zabbix_server
grep '=' /etc/zabbix/zabbix_java_gateway.conf
LISTEN_IP="0.0.0.0"
LISTEN_PORT=10052
PID_FILE="/var/run/zabbix/zabbix_java.pid"
START_POLLERS=50
egrep -v "(^#|^$)" /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/var/lib/mysql/mysql.sock
JavaGateway=127.0.0.1
JavaGatewayPort=10052
StartJavaPollers=1
ExternalScripts=/etc/zabbix/externalscripts

http://www.itnihao.com

103

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

tomcat
vim /usr/sbin/tomcat6
export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote"
export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.port=10053"
export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.authenticate=false"
export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.ssl=false"
#service tomcat6 stop
#service tomcat6 start

#wget http://crawler.archive.org/cmdline-jmxclient/cmdline-jmxclient-0.10.3.jar
#java -jar

cmdline-jmxclient-0.10.3.jar -

10.10.10.10:10053 java.lang:type=Memory NonHeapMemoryUsage

Web JMX

tomcat

http://www.itnihao.com

104

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

Weblogic
weblogic

export JAVA_OPTIONS="${JAVA_OPTIONS} -Dcom.sun.management.jmxremote"


export JAVA_OPTIONS="${JAVA_OPTIONS} -Dcom.sun.management.jmxremote.port=10053"
export JAVA_OPTIONS="${JAVA_OPTIONS} -Dcom.sun.management.jmxremote.authenticate=false"
export JAVA_OPTIONS="${JAVA_OPTIONS} -Dcom.sun.management.jmxremote.ssl=false"

weblogic

http://www.itnihao.com

105

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

host jmx 10053

6.

Zabbix -
zabbix

zabbix zabbix
zabbix 2 2
2 zabbix 2
cacti nagios

6.1

https://www.zabbix.com/documentation/2.0/manual/discovery/network_discovery/rule

http://www.itnihao.com

106

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

4.1.1

Names
Discovery by proxy
IP rangeip
Delay 3600
Checks: ICMPzabbix agentd
Device uniqueness criteria ip
Enabled

http://www.itnihao.com

107

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

6.1

Discovery,

Name Action

http://www.itnihao.com

108

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

Discovery rule Discovery rule

http://www.itnihao.com

109

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

add

6.2

low-level discovery
--- zabbix web url

url http://itnihao.blog.51cto.com url 200

url url zabbix


+mail

zabbix discovery

/etc/zabbix/zabbix_agentd.conf
/etc/zabbix/scripts/web_site_code_status
/etc/zabbix/scripts/WEB.txt
/etc/zabbix/zabbix_agentd.conf.d/web_site_discovery.conf

http://www.itnihao.com

110

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

6.2.1 zabbix
1.

#########cat /etc/zabbix/zabbix_agentd.conf|grep -v "^#"|grep -v "^$"##########

## N
Include=/etc/zabbix/zabbix_agentd.conf.d/ #
UnsafeUserParameters=1
# key

6.2.2
Low-level discovery json shell shell
perlpython
######################cat /etc/zabbix/scripts/web_site_code_status#############
#!/bin/bash
# function:monitor tcp connect status
# License: GPL
# mail:itnihao@qq.com
# version:1.0 date:2012-12-09
source /etc/bashrc >/dev/null 2>&1
source /etc/profile
>/dev/null 2>&1

from

zabbix

#/usr/bin/curl -o /dev/null -s -w %{http_code} http://$1/


WEB_SITE_discovery () {
WEB_SITE=($(cat
WEB.txt|grep -v "^#"))
printf '{\n'
printf '\t"data":[\n'
for((i=0;i<${#WEB_SITE[@]};++i))
{
num=$(echo $((${#WEB_SITE[@]}-1)))
if [ "$i" != ${num} ];
then
printf "\t\t{ \n"
printf "\t\t\t\"{#SITENAME}\":\"${WEB_SITE[$i]}\"},\n"
else
printf
"\t\t{ \n"
printf
"\t\t\t\"{#SITENAME}\
":\"${WEB_SITE[$num]}\"}]}\n"
fi
}
}
http://www.itnihao.com

111

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
web_site_code () {
/usr/bin/curl -o /dev/null
}
case "$1" in
web_site_discovery)
WEB_SITE_discovery
;;
web_site_code)
web_site_code $2
;;
*)
echo "Usage:$0
;;
esac

-s

-w

%{http_code}

{web_site_discovery|web_site_code

http://$1

[URL]}"

python
#!/usr/bin/env python
# coding=utf8
# Last modified: 2013-04-12 14:47
# Author: itnihao
# Mail: itnihao@qq.com
import os
import json
r=open('WEB.txt','r').read().split()
devices = []
for devpath in r:
device = os.path.basename(devpath)
devices += [{'{#SITENAME}':device}]

http://www.itnihao.com

112

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
print json.dumps({'data':devices},sort_keys=True,indent=7,separators=(',',':'))

6.2.3 key
#########cat /etc/zabbix/zabbix_agentd.conf.d/web_site_discovery.conf ###########
UserParameter=web.site.discovery,/etc/zabbix/scripts/web_site_code_status web_site_discovery
UserParameter=web.site.code[*],/etc/zabbix/scripts/web_site_code_status web_site_code $1

######### cat /etc/zabbix/scripts/WEB.txt###########


www.qq.com
www.baidu.com
www.sina.com.cn

zabbix_get -s 127.0.0.1 -k web.site.discovery

zabbix_get -s 127.0.0.1 -k web.site.code[www.qq.com]


200
OK

http://www.itnihao.com

113

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

6.2.4 web low-level discovery

http://www.itnihao.com

114

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

http://www.itnihao.com

115

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

http://www.itnihao.com

116

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

1000 url

https://www.zabbix.com/documentation/2.0/manual/discovery/low_level_discovery

7.

zabbix

7.1

Zabbix

7.2

zabbix_server.conf

7.3

zabbix_agend.conf

7.4

Zabbix

7.5

zabix

http://blog.sina.com.cn/s/blog_704836f40101g0fb.html

http://www.itnihao.com

117

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
1. Zabbix
Zabbix NVPS()
Zabbix dashboard

4 CPU6GB RAID10(),Zabbix
1M ,15000
2.

zabbix item:

Administration -> Queue

zabbix item

nodata() false

3. Zabbix

Min(),max(),avg()

Last(),nodata()

(SNMP,,Passive )

Trapping(active )

http://www.itnihao.com

118

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

4. Zabbix
zabbix
zabbix[wcache,values,all]
zabbix[queue,1m]

----1 item

zabbix ( BUSY )
zabbix[process,type,mode,state]
:
type: trapper,discoverer,escalator,alerter,etc
mode: avg,count,min,max
state: busy,idel

http://www.itnihao.com

119

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

5.Zabbix

zabbix ()

MySQL

Zabbix
6.Zabbix
a.
NVPS 3000
Dell PowerEdge R610

http://www.itnihao.com

120

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
CPU: Intel Xeon L5520 2.27GHz (16 cores)
Memory: 24GB RAM
Disks: 6x SAS 10k RAID10

b. table , my.cnf
innodb_file_per_table=1
c. percona MySQL
d. Houerkeeper
Houserkeeper,zabbix_server.conf
DisableHousekeeper=1

step 1.
ALTER TABLE `acknowledges` DROP PRIMARY KEY, ADD KEY `acknowledgedid`
(`acknowledgeid`);
ALTER TABLE `alerts` DROP PRIMARY KEY, ADD KEY `alertid` (`alertid`);
ALTER TABLE `auditlog` DROP PRIMARY KEY, ADD KEY `auditid` (`auditid`);
ALTER TABLE `events` DROP PRIMARY KEY, ADD KEY `eventid` (`eventid`);
ALTER TABLE `service_alarms` DROP PRIMARY KEY, ADD KEY `servicealarmid`
(`servicealarmid`);
ALTER TABLE `history_log` DROP PRIMARY KEY, ADD PRIMARY KEY (`itemid`,`id`,`clock`);
ALTER TABLE `history_log` DROP KEY `history_log_2`;
ALTER TABLE `history_text` DROP PRIMARY KEY, ADD PRIMARY KEY
(`itemid`,`id`,`clock`);
ALTER TABLE `history_text` DROP KEY `history_text_2`;

step2.
events 2011-52011-12

http://www.itnihao.com

121

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

ALTER TABLE `events` PARTITION BY RANGE( clock ) (


PARTITION p201105 VALUES LESS THAN (UNIX_TIMESTAMP("2011-06-01 00:00:00")),
PARTITION p201106 VALUES LESS THAN (UNIX_TIMESTAMP("2011-07-01 00:00:00")),
PARTITION p201107 VALUES LESS THAN (UNIX_TIMESTAMP("2011-08-01 00:00:00")),
PARTITION p201108 VALUES LESS THAN (UNIX_TIMESTAMP("2011-09-01 00:00:00")),
PARTITION p201109 VALUES LESS THAN (UNIX_TIMESTAMP("2011-10-01 00:00:00")),
PARTITION p201110 VALUES LESS THAN (UNIX_TIMESTAMP("2011-11-01 00:00:00")),
PARTITION p201111 VALUES LESS THAN (UNIX_TIMESTAMP("2011-12-01 00:00:00")),
PARTITION p201112 VALUES LESS THAN (UNIX_TIMESTAMP("2012-01-01 00:00:00"))
);
step3.

history_uint 5.155.22

ALTER TABLE `history_uint` PARTITION BY RANGE( clock ) (


PARTITION p20110515 VALUES LESS THAN (UNIX_TIMESTAMP("2011-05-16 00:00:00")),
PARTITION p20110516 VALUES LESS THAN (UNIX_TIMESTAMP("2011-05-17 00:00:00")),
PARTITION p20110517 VALUES LESS THAN (UNIX_TIMESTAMP("2011-05-18 00:00:00")),
PARTITION p20110518 VALUES LESS THAN (UNIX_TIMESTAMP("2011-05-19 00:00:00")),
PARTITION p20110519 VALUES LESS THAN (UNIX_TIMESTAMP("2011-05-20 00:00:00")),
PARTITION p20110520 VALUES LESS THAN (UNIX_TIMESTAMP("2011-05-21 00:00:00")),
PARTITION p20110521 VALUES LESS THAN (UNIX_TIMESTAMP("2011-05-22 00:00:00")),
PARTITION p20110522 VALUES LESS THAN (UNIX_TIMESTAMP("2011-05-23 00:00:00"))
);

ALTER TABLE `history_uint` ADD PARTITION (


PARTITION p20110523 VALUES LESS THAN (UNIX_TIMESTAMP("2011-05-24 00:00:00"))
);

( Housekeepeing)
ALTER TABLE `history_uint` DROP PARTITION p20110515;

step4.
step3 history
drop ,3,
@mindays

http://www.itnihao.com

122

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
cron
mysql -B -h localhost -u zabbix -pPASSWORD zabbix -e "CALL
create_zabbix_partitions();"
:
https://github.com/xsbr/zabbixzone/blob/master/zabbix-mysql-autopartitioning.s
ql

DELIMITER //
DROP PROCEDURE IF EXISTS `zabbix`.`create_zabbix_partitions` //
CREATE PROCEDURE `zabbix`.`create_zabbix_partitions` ()
BEGIN
CALL zabbix.create_next_partitions("zabbix","history");
CALL zabbix.create_next_partitions("zabbix","history_log");
CALL zabbix.create_next_partitions("zabbix","history_str");
CALL zabbix.create_next_partitions("zabbix","history_text");
CALL zabbix.create_next_partitions("zabbix","history_uint");
CALL zabbix.drop_old_partitions("zabbix","history");
CALL zabbix.drop_old_partitions("zabbix","history_log");
CALL zabbix.drop_old_partitions("zabbix","history_str");
CALL zabbix.drop_old_partitions("zabbix","history_text");
CALL zabbix.drop_old_partitions("zabbix","history_uint");
END //
DROP PROCEDURE IF EXISTS `zabbix`.`create_next_partitions` //
CREATE PROCEDURE `zabbix`.`create_next_partitions` (SCHEMANAME varchar(64),
TABLENAME varchar(64))
BEGIN
DECLARE NEXTCLOCK timestamp;
DECLARE PARTITIONNAME varchar(16);
DECLARE CLOCK int;
SET @totaldays = 7;
SET @i = 1;
createloop: LOOP
SET NEXTCLOCK = DATE_ADD(NOW(),INTERVAL @i DAY);
SET PARTITIONNAME = DATE_FORMAT( NEXTCLOCK, 'p%Y%m%d' );
SET CLOCK = UNIX_TIMESTAMP(DATE_FORMAT(DATE_ADD( NEXTCLOCK ,INTERVAL 1
DAY),'%Y-%m-%d 00:00:00'));
CALL zabbix.create_partition( SCHEMANAME, TABLENAME, PARTITIONNAME, CLOCK );
SET @i=@i+1;
IF @i > @totaldays THEN

http://www.itnihao.com

123

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
LEAVE createloop;
END IF;
END LOOP;
END //
DROP PROCEDURE IF EXISTS `zabbix`.`drop_old_partitions` //
CREATE PROCEDURE `zabbix`.`drop_old_partitions` (SCHEMANAME varchar(64),
TABLENAME varchar(64))
BEGIN
DECLARE OLDCLOCK timestamp;
DECLARE PARTITIONNAME varchar(16);
DECLARE CLOCK int;
SET @mindays = 3;
SET @maxdays = @mindays+4;
SET @i = @maxdays;
droploop: LOOP
SET OLDCLOCK = DATE_SUB(NOW(),INTERVAL @i DAY);
SET PARTITIONNAME = DATE_FORMAT( OLDCLOCK, 'p%Y%m%d' );
CALL zabbix.drop_partition( SCHEMANAME, TABLENAME, PARTITIONNAME );
SET @i=@i-1;
IF @i <= @mindays THEN
LEAVE droploop;
END IF;
END LOOP;
END //
DROP PROCEDURE IF EXISTS `zabbix`.`create_partition` //
CREATE PROCEDURE `zabbix`.`create_partition` (SCHEMANAME varchar(64), TABLENAME
varchar(64), PARTITIONNAME varchar(64), CLOCK int)
BEGIN
DECLARE RETROWS int;
SELECT COUNT(1) INTO RETROWS
FROM `information_schema`.`partitions`
WHERE `table_schema` = SCHEMANAME AND `table_name` = TABLENAME AND
`partition_name` = PARTITIONNAME;
IF RETROWS = 0 THEN
SELECT CONCAT( "create_partition(", SCHEMANAME, ",", TABLENAME, ",", PARTITIONNAME,
",", CLOCK, ")" ) AS msg;
SET @sql = CONCAT( 'ALTER TABLE `', SCHEMANAME, '`.`', TABLENAME, '`',
' ADD PARTITION (PARTITION ', PARTITIONNAME, ' VALUES LESS THAN (', CLOCK, '));' );
PREPARE STMT FROM @sql;
EXECUTE STMT;

http://www.itnihao.com

124

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
DEALLOCATE PREPARE STMT;
END IF;
END //
DROP PROCEDURE IF EXISTS `zabbix`.`drop_partition` //
CREATE PROCEDURE `zabbix`.`drop_partition` (SCHEMANAME varchar(64), TABLENAME
varchar(64), PARTITIONNAME varchar(64))
BEGIN
DECLARE RETROWS int;
SELECT COUNT(1) INTO RETROWS
FROM `information_schema`.`partitions`
WHERE `table_schema` = SCHEMANAME AND `table_name` = TABLENAME AND
`partition_name` = PARTITIONNAME;
IF RETROWS = 1 THEN
SELECT CONCAT( "drop_partition(", SCHEMANAME, ",", TABLENAME, ",", PARTITIONNAME,
")" ) AS msg;
SET @sql = CONCAT( 'ALTER TABLE `', SCHEMANAME, '`.`', TABLENAME, '`',
' DROP PARTITION ', PARTITIONNAME, ';' );
PREPARE STMT FROM @sql;
EXECUTE STMT;
DEALLOCATE PREPARE STMT;
END IF;
END //
DELIMITER ;
e. tmpfs

mkdir /tmp/mysqltmp
/etc/fstab:

tmfs /tmp/mysqltmp tmpfs


rw,uid=mysql,gid=mysql,size=1G,nr_inodes=10k,mode=0700
my.cnf

00

tmpdir=/tmp/mysqltmp
f. buffer pool
Innodb 70%~80%
my.cnf
innodb_buffer_pool_size=14G
innodb O_DIRECT buffer_pool
innodb_flush_method=O_DIRECT

http://www.itnihao.com

125

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
my.cnf24G:

g. log
zabbix MySQL log flush

,
my.cnf
innodb_log_file_size=64M

http://www.itnihao.com

126

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
h.
my.cnf
log_slow_queries=/var/log/mysql.slow.log
i. thread_cache_size
show global status Threads_created per Connection hit rate
4,3228483 Connections 5840 Threads_created,hit rate
99.2%
Threads_created
j. MySQL
query_cache_limit=1M
query_cache_size=128M
tmp_table_size=256M
max_heap_table_size=256M
table_cache=256
max_connections = 300
innodb_flush_log_at_trx_commit=2
join_buffer_size=256k
read_buffer_size=256k
read_rnd_buffer_size=256k

7. zabbix ,zabbix_server.conf
StartPollers=90
StartPingers=10
StartPollersUnreacheable=80
StartIPMIPollers=10
StartTrappers=20
StartDBSyncers=8

LogSlowQueries=1000
:
http://www.slideshare.net/xsbr/alexei-vladishev-zabbixperformancetuning
http://zabbixzone.com/zabbix/mysql-performance-tips-for-zabbix/
http://zabbixzone.com/zabbix/partitioning-tables/
http://linux-knowledgebase.com/en/Tip_of_the_day/March/Performance_Tuning_
for_Zabbix
http://sysadminnotebook.blogspot.jp/2011/08/performance-tuning-mysql-for-zab
bix.html

http://www.itnihao.com

127

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

8.

easy Update on Custom Scripts


http://zabbixzone.com/zabbix/easy-update-on-custom-scripts/
Every time that you need to add or change an UserParameter on zabbix_agentd.conf you
need to restart the agent. Its easy if you have less than 10 servers, but could be a trouble if you
have more than 30 servers.

Automation Tools like CFEngine and Puppet do this work well done, but
unfortunately they arent used in many companies.
But its possible using a Dynamic UserParameter:
1) add two lines on zabbix_agentd.conf and restart the agent:
UserParameter=custom.getvalue[*],/etc/zabbix/zabbix_agentd/custom_getvalue $1 $2 $3 $4
$5
UserParameter=custom.updatescript,/etc/zabbix/zabbix_agentd/custom_updatescript

2) create the script file /etc/zabbix/zabbix_agentd/custom_getvalue


#!/bin/bash
ACTION=$1
PARAM1=$2
PARAM2=$3
PARAM3=$4
PARAM4=$5
case ${ACTION} in
# key: custom.getvalue[samplescript1,arg]
samplescript1)
/bin/echo This is a test - ${PARAM1}
;;
# key: custom.getvalue[samplescript2,arg1,arg2]
samplescript2)
/bin/echo This is another test - ${PARAM1} ${PARAM2}
;;

http://www.itnihao.com

128

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
*)
/bin/echo ZBX_NOTSUPPORTED
;;
esac

Dont forget to set execute permission:


1

chmod 0755 /etc/zabbix/zabbix_agentd/custom_getvalue

Now when you need create a new script, you must update this script and restart is
unnecessary.
Remote Updates
Finally, lets create a script to update custom_getvalue script remotely. Before
make sure to publish yourcustom_getvalue script on a WebServer.
Create the file /etc/zabbix/zabbix_agentd/custom_updatescript:
1 #!/bin/bash
2 /usr/bin/wget "http://yourdomain.com/zabbix/custom_getvalue" -O
/etc/zabbix/zabbix_agentd/custom_getvalue -o /dev/null

Dont forget to set execute permission:


1

chmod 0755 /etc/zabbix/zabbix_agentd/custom_updatescript

Remote updates can be done from Zabbix Server/Proxy using zabbix_get utility:
1

zabbix_get -s hostserver.yourdomain.com -k custom.updatescript

Its a contribution from laneovcc:


in my way i config zabbix-agent.conf to include a UserParameter.conf then use
system.run[wget
http://server/UserParameter.conf
-O
/path/to/UserParameter.conf ] to update the UserParameter.conf and
system.run[services zabbix-agentd restart] to restart the agent

9.

zabbix rpm
Rpmbuild spec
rpm
#
%define zabbix_group zabbix
%define zabbix_user zabbix
Name:

zabbix

Version:

2.0.6

Release:

2%{?dist}.zbx

Summary:
Vendor:

zabbix monitor
itnihao@qq.com

http://www.itnihao.com

129

ZABBIX
----- zabbix

QQ 972322817 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.6/zabbix-2.0.6.
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
http://www.itnihao.com

130

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
Summary:
Group:

Zabbix Agent
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:
Group:

Zabbix Proxy
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

http://www.itnihao.com

131

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
%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
--mandir=/usr/share/man

--prefix=/usr/local
--enable-proxy

--sysconfdir=/etc/zabbix

--libdir=/usr/lib

--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}
http://www.itnihao.com

132

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
%{__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@PIDFILE=/tmp@PIDFILE=/var/run/zabbix@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@PIDFILE=/tmp@PIDFILE=/var/run/zabbix@g"

$RPM_BUILD_ROOT%{_initrddir}/zabbix_agentd
%{__sed}

-i

"s@BASEDIR=/usr/local@BASEDIR=/usr@g"

$RPM_BUILD_ROOT%{_initrddir}/zabbix_proxy
%{__sed}

-i

"s@PIDFILE=/tmp@PIDFILE=/var/run/zabbix@g"

http://www.itnihao.com

133

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
$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\n' \
-e '/# Include.*zabbix_agentd.conf.d\//aInclude=\/etc\/zabbix\/zabbix_agentd.conf.d\/\n'
http://www.itnihao.com

134

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
\
-e '/StartAgents=3/aStartAgents=5\n' \
-e 's|# LogFileSize=.*|LogFileSize=0|g' \
-e 's|Server=127.0.0.1$|Server=127.0.0.1,10.10.10.1,60.191.140.200|g' \
-e
's|ServerActive=127.0.0.1$|ServerActive=127.0.0.1:10051,10.10.10.1:10051,60.191.140.200:1005
1|g' \
-e 's|# EnableRemoteCommands=0|EnableRemoteCommands=1|g' \
-e 's|# LogRemoteCommands=0|LogRemoteCommands=1|g' \
-e 's|LogFileSize=0|LogFileSize=10|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\n' \
-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\n' \
-e 's|# DBSocket=/tmp/mysql.sock|DBSocket=%{_sharedstatedir}/mysql/mysql.sock|g' \
-e

's|#

ExternalScripts=\${datadir}/zabbix/externalscripts|ExternalScripts=%{_sysconfdir}/%{name}/ext
ernalscripts|' \
-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' \
http://www.itnihao.com

135

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
-e 's|# LogFileSize=.*|LogFileSize=0|g' \
-e 's|^DBUser=root|DBUser=zabbix|g' \
-e '/# DBPassword=/aDBPassword=zabbix\n' \
-e 's|# DBSocket=/tmp/mysql.sock|DBSocket=%{_sharedstatedir}/mysql/mysql.sock|g' \
-e

's|#

ExternalScripts=\${datadir}/zabbix/externalscripts|ExternalScripts=%{_sysconfdir}/%{name}/ext
ernalscripts|' \
-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,-)
http://www.itnihao.com

136

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
%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}
http://www.itnihao.com

137

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
#%{_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"

&&

http://www.itnihao.com

cp

%{_datadir}/%{name}/conf/zabbix-web.conf
138

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
/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"
sed

-i

"s#max_execution_time

/etc/php.ini

30#max_execution_time

300#g"

/etc/php.ini
sed

-i

"s#post_max_size

sed

-i

"s#max_input_time

sed

-i

"s#memory_limit

8M#post_max_size

32M#g"

/etc/php.ini
=

60#max_input_time

300#g"

/etc/php.ini
=

128M#memory_limit

128M#g"

/etc/php.ini
sed -i "/;mbstring.func_overload = 0/ambstring.func_overload = 2\n" /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
http://www.itnihao.com

139

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
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
http://www.itnihao.com

140

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
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
* Mon Feb 18 2013 changed file for agentd<itnihao@qq.com>
http://www.itnihao.com

141

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com
- 2.0.5
* Fri Jan 25 2013

First version is build ok <itnihao@qq.com>

- 2.0.4

http://www.itnihao.com

142

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

http://www.itnihao.com

143

ZABBIX
----- zabbix

QQ 972322817 itnihao@qq.com

http://www.itnihao.com

144

You might also like