一.zabbix架構
1.zabbix的架構圖:
<a href="http://s3.51cto.com/wyfs02/M00/80/72/wKiom1dCAl7DXE2RAACe70_Xs3I557.png" target="_blank"></a>
2.zabbix的邏輯架構圖
<a href="http://s4.51cto.com/wyfs02/M01/80/72/wKiom1dCAzzxRn3YAABBt-Hv2H0497.png" target="_blank"></a>
3.zabbix 伺服器程序圖
<a href="http://s1.51cto.com/wyfs02/M00/80/70/wKioL1dB3A-jBOJ7AAB4mkeKUfg208.png" target="_blank"></a>
二.zabbix安裝
這裡以兩台機器為示例做介紹:
192.168.10.153(資料庫)
192.168.10.154(伺服器)
zabbix 安裝有兩種方法:(這裡我們采取yum 安裝的方式)
(1).編譯安裝:
同時安裝server和agent,并支援将資料放入mysql資料庫中,可使用類似如下配置指令:
./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl
如果僅安裝server,并支援将資料庫加入mysql資料中,可使用類似如下配置指令:
./configure --enable-server --with-mysql --with-net-snmp
如果僅安裝proxy,并支援将資料放入mysql資料中,可使用類似如下配置指令:
./configure --prefix=/usr enable-proxy --with-net-snmp --with-mysql --with-ssh2
如果僅安裝agent,可使用類似如下配置指令:
./configure --enable-agent
而後編譯安裝zabbix即可:
make install
(2).yum安裝:
下面我們來安裝zabbix:
1.安裝server端隻需要安裝下面的幾個包(比較新的版本,2.4.8)
zabbix-server-2.4.8-1.el6.x86_64.rpm zabbix-web-mysql-2.4.8-1.el6.noarch.rpm
zabbix-2.4.8-1.el6.x86_64.rpm zabbix-server-mysql-2.4.8-1.el6.x86_64.rpm
zabbix-get-2.4.8-1.el6.x86_64.rpm zabbix-web-2.4.8-1.el6.noarch.rpm
2.關閉selinux
vim /etc/selinux/config
SELINUX=disabled
setenforce 0
3.關閉防火牆
service iptables stop
chkconfig iptables off
4.安裝使用zabbix官方的yum源
[root@192 ~]# rpm -ivh zabbix-release-2.4-1.el6.noarch.rpm
warning:zabbix-release-2.4-1.el6.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID79ea5ed4: NOKEY
Preparing... ########################################### [100%]
1:zabbix-release ########################################### [100%]
5.配好zabbix的yum源以後,我們來看看yum源裡的zabbix版本(需要安裝的包已用藍色标注出來了)
[root@192 src]# yum list|grep zabbix
zabbix-release.noarch 2.4-1.el6 installed
fping.x86_64 2.4b2-16.el6 zabbix-non-supported
iksemel.x86_64 1.4-2.el6 zabbix-non-supported
iksemel-devel.x86_64 1.4-2.el6 zabbix-non-supported
iksemel-utils.x86_64 1.4-2.el6 zabbix-non-supported
libssh2.x86_64 1.4.2-2.el6 zabbix-non-supported
libssh2-devel.x86_64 1.4.2-2.el6 zabbix-non-supported
libssh2-docs.x86_64 1.2.2-7.el6 zabbix-non-supported
libssh2-docs.noarch 1.4.2-2.el6 zabbix-non-supported
2.72-2.el6 zabbix-non-supported
snmptt.noarch 1.4-1.el6 zabbix-non-supported
zabbix.x86_64 2.4.8-1.el6 zabbix
zabbix-agent.x86_64 2.4.8-1.el6 zabbix
zabbix-get.x86_64 2.4.8-1.el6 zabbix
zabbix-java-gateway.x86_64
2.4.8-1.el6 zabbix
zabbix-proxy.x86_64 2.4.8-1.el6 zabbix
zabbix-proxy-mysql.x86_64
zabbix-proxy-pgsql.x86_64
zabbix-proxy-sqlite3.x86_64
2.4.8-1.el6 zabbix
zabbix-sender.x86_64 2.4.8-1.el6 zabbix
zabbix-server-mysql.x86_64
zabbix-server-pgsql.x86_64
zabbix-web.noarch 2.4.8-1.el6 zabbix
zabbix-web-japanese.noarch
zabbix-web-mysql.noarch
zabbix-web-pgsql.noarch
2.4.8-1.el6 zabbix
注意:/etc/yum.repos.d下面要有兩個檔案
CentOS-Base.repo zabbix.repo
不然安裝的時候要報依賴性的錯誤
6.使用yum 安裝軟體
yum -y install zabbix.x86_64 zabbix-get.x86_64 zabbix-sender.x86_64 zabbix-server-mysql.x86_64 zabbix-web.noarch zabbix-web-mysql.noarch
7.初始化資料庫,在192.168.10.154(伺服器)上
檢視資料庫腳本位置。
[root@192 ~]# rpm -ql zabbix-server-mysql.x86_64 0:2.4.8-1.el6
/usr/share/doc/zabbix-server-mysql-2.4.8/create/data.sql
/usr/share/doc/zabbix-server-mysql-2.4.8/create/images.sql
/usr/share/doc/zabbix-server-mysql-2.4.8/create/schema.sql
8.在用戶端192.168.10.153(資料庫)的機器上,設定mysql的權限:
先給安裝好的mysql資料庫設定密碼并賦予權限
mysql> use mysql
Reading tableinformation for completion of table and column names
You can turn off thisfeature to get a quicker startup with -A
Database changed
mysql> update user set password=password("huaxia") where user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> flush privileges;
Query OK, 0 rowsaffected (0.00 sec)
mysql> quit
Bye
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'huaxia' WITH GRANT OPTION;#賦予所有IP位址都可以連接配接的權限
Query OK, 0 rows affected (0.00 sec)
9.在伺服器端192.168.10.154(伺服器)的機器上安裝mysql
yum install mysql
10.在用戶端192.168.10.153(資料庫)的機器上,建立資料庫zabbix
mysql> CREATE DATABASE zabbix;
Query OK, 1 row affected (0.01 sec)
11.在伺服器端192.168.10.154(伺服器)的機器上,導入sql檔案,
[root@192 ~]# mysql -uroot -phuaxia -h192.168.10.153 zabbix </usr/share/doc/zabbix-server-mysql-2.4.8/create/schema.sql
12.在用戶端192.168.10.153(資料庫)的機器上,檢視剛才導入的sql檔案。
mysql> use zabbix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
mysql> show tables;#如下面所示說明導入資料庫成功。
+-----------------------+
|Tables_in_zabbix |
| acknowledges |
| actions |
| alerts |
|application_template |
| applications |
| auditlog |
|auditlog_details |
| autoreg_host |
| conditions |
| config |
| dbversion |
| dchecks |
| dhosts |
| drules |
| dservices |
| escalations |
| events |
| expressions |
| functions |
| globalmacro |
| globalvars |
| graph_discovery |
| graph_theme |
| graphs |
| graphs_items |
| group_discovery |
| group_prototype |
| groups |
| history |
| history_log |
| history_str |
| history_text |
| history_uint |
| host_discovery |
| host_inventory |
| hostmacro |
| hosts |
| hosts_groups |
| hosts_templates |
| housekeeper |
| httpstep |
| httpstepitem |
| httptest |
| httptestitem |
| icon_map |
| icon_mapping |
| ids |
| images |
| interface |
|interface_discovery |
| item_condition |
| item_discovery |
| items |
|items_applications |
| maintenances |
|maintenances_groups |
|maintenances_hosts |
|maintenances_windows |
| mappings |
| media |
| media_type |
| opcommand |
| opcommand_grp |
| opcommand_hst |
| opconditions |
| operations |
| opgroup |
| opmessage |
| opmessage_grp |
| opmessage_usr |
| optemplate |
| profiles |
|proxy_autoreg_host |
| proxy_dhistory |
| proxy_history |
| regexps |
| rights |
| screens |
| screens_items |
| scripts |
| service_alarms |
| services |
| services_links |
| services_times |
| sessions |
| slides |
| slideshows |
| sysmap_element_url |
| sysmap_url |
| sysmaps |
|sysmaps_elements |
|sysmaps_link_triggers |
| sysmaps_links |
| timeperiods |
| trends |
| trends_uint |
| trigger_depends |
|trigger_discovery |
| triggers |
| user_history |
| users |
| users_groups |
| usrgrp |
| valuemaps |
104 rows in set (0.00sec)
13.在伺服器端192.168.10.154(伺服器)的機器上,
再導入下面所示的兩個sql檔案
[root@192 ~]# mysql -uroot -phuaxia -h192.168.10.153 zabbix </usr/share/doc/zabbix-server-mysql-2.4.8/create/images.sql
[root@192 ~]# mysql -uroot -phuaxia -h192.168.10.153 zabbix < /usr/share/doc/zabbix-server-mysql-2.4.8/create/data.sql
14.在用戶端192.168.10.153(資料庫)的機器上,授權zbxuser通路zabbix資料庫。
mysql> GRANT ALL ON zabbix.* TO 'zbxuser'@'%' IDENTIFIED BY 'huaxia';
Query OK, 0 rows affected (0.01 sec)
15.在伺服器端192.168.10.154(伺服器)的機器上配置zabbix_server。
[root@192 ~]# cd /etc/zabbix/
[root@192 zabbix]# ls
web zabbix_server.conf
[root@192 zabbix]# ls web
maintenance.inc.php
vim zabbix_server.conf
改下,把配置檔案的參數改為以下所示
DBHost=192.168.10.153#資料庫伺服器IP位址
DBUser=zbxuser#剛才在資料庫裡設定的zabbix資料庫使用者。
DBPassword=huaxia#剛才資料庫裡設定的密碼。
16.在伺服器端192.168.10.154(伺服器)的機器上啟動zabbix_server。
[root@192 zabbix]# ls /etc/rc.d/init.d#檢視啟動腳本
abrt-ccpp bluetooth haldaemon killall NetworkManager psacct rpcsvcgssd spice-vdagentd ypbind
abrtd certmonger halt lvm2-lvmetad nfs quota_nld rsyslog sshd zabbix-server
abrt-oops cpuspeed htcacheclean lvm2-monitor nfslock rdisc sandbox sssd
acpid crond httpd mdmonitor ntpd restorecond saslauthd sysstat
atd cups ip6tables messagebus ntpdate rngd single udev-post
auditd dnsmasq iptables netconsole oddjobd rpcbind smartd wdaemon
autofs firstboot irqbalance netfs portreserve rpcgssd snmpd winbind
blk-availability functions kdump network postfix rpcidmapd snmptrapd wpa_supplicant
[root@192 zabbix]#service zabbix-server start#啟動服務
Starting Zabbixserver: [确定]
[root@192 zabbix]# ss -tnlp#檢視zabbix啟動的程序數,看到zabbix啟動在10051端口上。
LISTEN 0 128 :::10051 :::* users:(("zabbix_server",7273,5),("zabbix_server",7274,5),("zabbix_server",7275,5),("zabbix_server",7276,5),("zabbix_server",7277,5),("zabbix_server",7278,5),("zabbix_server",7279,5),("zabbix_server",7280,5),("zabbix_server",7281,5),("zabbix_server",7282,5),("zabbix_server",7283,5),("zabbix_server",7284,5),("zabbix_server",7285,5),("zabbix_server",7286,5),("zabbix_server",7287,5),("zabbix_server",7288,5),("zabbix_server",7289,5),("zabbix_server",7290,5),("zabbix_server",7291,5),("zabbix_server",7292,5),("zabbix_server",7293,5),("zabbix_server",7294,5),("zabbix_server",7295,5),("zabbix_server",7296,5),("zabbix_server",7297,5),("zabbix_server",7298,5),("zabbix_server",7299,5))
LISTEN 0 128 *:10051 *:* users:(("zabbix_server",7273,4),("zabbix_server",7274,4),("zabbix_server",7275,4),("zabbix_server",7276,4),("zabbix_server",7277,4),("zabbix_server",7278,4),("zabbix_server",7279,4),("zabbix_server",7280,4),("zabbix_server",7281,4),("zabbix_server",7282,4),("zabbix_server",7283,4),("zabbix_server",7284,4),("zabbix_server",7285,4),("zabbix_server",7286,4),("zabbix_server",7287,4),("zabbix_server",7288,4),("zabbix_server",7289,4),("zabbix_server",7290,4),("zabbix_server",7291,4),("zabbix_server",7292,4),("zabbix_server",7293,4),("zabbix_server",7294,4),("zabbix_server",7295,4),("zabbix_server",7296,4),("zabbix_server",7297,4),("zabbix_server",7298,4),("zabbix_server",7299,4))
17.在伺服器端192.168.10.154(伺服器)的機器上檢視web接口配置。
注意:配置一般不用改
[root@192 zabbix]# ls /etc/httpd/conf.d/
mod_dnssd.conf php.conf README welcome.conf zabbix.conf
[root@192 zabbix]# cd /etc/httpd/
[root@192 httpd]# ls
conf conf.d logs modules run
[root@192 httpd]# cd conf.d/
[root@192 conf.d]# ls
mod_dnssd.conf php.conf README welcome.conf zabbix.conf
[root@192 conf.d]# cat zabbix.conf
Alias /zabbix /usr/share/zabbix#定義通路别名
<Directory"/usr/share/zabbix">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
<IfModule mod_php5.c>
php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
# php_value date.timezone Europe/Riga
</IfModule>
</Directory>
18.在伺服器端192.168.10.154(伺服器)的機器上,啟動http服務。
[root@192 ~]# service httpd start
正在啟動 httpd: [确定]
[root@192 ~]# ss -tnlp
LISTEN 0 128 :::80#80端口處于監聽狀态 :::* users:(("httpd",7492,4),("httpd",7495,4),("httpd",7496,4),("httpd",7497,4),("httpd",7498,4),("httpd",7499,4),("httpd",7500,4),("httpd",7501,4),("httpd",7502,4))
19.在伺服器端192.168.10.154(伺服器)的機器上,通路zabbix,在浏覽器中輸入網址http://192.168.10.154/zabbix,會出現如下圖所示的界面。注意:主機防火牆這裡要關閉,或者放開對80端口的通路權限。
vim /etc/php.ini#預設安裝php的配置檔案路徑
date.timezone= Asia/Shanghai#修改時區
[root@192 ~]# service httpd restart#
重新開機httpd服務
停止 httpd: [确定]
正在啟動 httpd: [确定]
再重新檢查下,說明配置正确,如下圖:
顯示如下圖所示的界面:
三.zabbix配置
這裡以一台客戶機做介紹:
192.168.10.116(客戶機)
一般需要安裝下面的幾個包:
zabbix-2.4.8-1.el6.x86_64、zabbix-agent-2.4.8-1.el6.x86_64、zabbix-sender-2.4.8-1.el6.x86_64
這裡我們使用yum安裝,至于配置yum的方法參照上面所示的伺服器端的配置,這裡不再詳述。
1.yum install zabbix.x86_64 zabbix-agent.x86_64zabbix-sender.x86_64
2.編輯配置檔案
[root@192 yum.repos.d]# cd /etc/zabbix/
zabbix_agentd.conf #主配置檔案
zabbix_agentd.d
[root@192 zabbix]# ls zabbix_agentd.d/
userparameter_mysql.conf#附加配置檔案
vim zabbix_agentd.conf#編輯配置檔案
隻需修改參數Server=192.168.10.154(zabbix伺服器位址),别的暫時不用管。
3.啟動服務
[root@192 zabbix]# ls /etc/init.d/#檢視啟動腳本
abrt-ccpp blk-availability firstboot iptables messagebus ntpd rdisc rsyslog spice-vdagentd wpa_supplicant
abrtd bluetooth functions irqbalance netconsole ntpdate restorecond sandbox sshd ypbind
abrt-oops certmonger haldaemon kdump netfs oddjobd rngd saslauthd sssd zabbix-agent
acpid cpuspeed halt killall network portreserve rpcbind single sysstat
atd crond htcacheclean lvm2-lvmetad NetworkManager postfix rpcgssd smartd udev-post
auditd cups httpd lvm2-monitor nfs psacct rpcidmapd snmpd wdaemon
autofs dnsmasq ip6tables mdmonitor nfslock quota_nld rpcsvcgssd snmptrapd winbind
service zabbix-agent start#啟動服務
[root@192 zabbix]# ss -tnlp#檢視程序和端口
LISTEN 0 128 :::10050 :::* users:(("zabbix_agentd",2372,5),("zabbix_agentd",2373,5),("zabbix_agentd",2374,5),("zabbix_agentd",2375,5),("zabbix_agentd",2376,5),("zabbix_agentd",2377,5))
LISTEN 0 128 *:10050 *:* users:(("zabbix_agentd",2372,4),("zabbix_agentd",2373,4),("zabbix_agentd",2374,4),("zabbix_agentd",2375,4),("zabbix_agentd",2376,4),("zabbix_agentd",2377,4))
監聽在10050端口上。
4.添加監控的主機
<a href="http://s3.51cto.com/wyfs02/M01/82/0D/wKioL1dJT6yB-4zIAACaSdtSFqI570.png-wh_500x0-wm_3-wmp_4-s_833806263.png" target="_blank"></a>
登入監控伺服器首頁面,"Configuration"選項裡的"host"菜單下,點選"Create host"按鈕。出現如下圖所示界面:
<a href="http://s5.51cto.com/wyfs02/M01/82/0D/wKioL1dJT-3TbVrVAABeAaZdIsw087.png-wh_500x0-wm_3-wmp_4-s_2727242813.png" target="_blank"></a>
在該對話框中輸入:
主機名、顯示名、組名、IP位址、端口等資訊
如下圖所示:
<a href="http://s5.51cto.com/wyfs02/M02/82/0E/wKiom1dJTzjA1SpxAABGi1U1s_w482.png-wh_500x0-wm_3-wmp_4-s_2109221655.png" target="_blank"></a>
添加完點選"add",顯示如下圖:
<a href="http://s5.51cto.com/wyfs02/M00/82/0D/wKioL1dJUG3RMTWyAACLMT21arc806.png-wh_500x0-wm_3-wmp_4-s_2694925590.png" target="_blank"></a>
說明主機已經在監控了。
再到"Dashboard"菜單下看看,如下圖所示:
<a href="http://s5.51cto.com/wyfs02/M01/82/0D/wKioL1dJUK7SHBcbAADZy10g8qo888.png-wh_500x0-wm_3-wmp_4-s_369781347.png" target="_blank"></a>
5.監控的主機上添加應用
1).定義一個項目,如下圖所示:
<a href="http://s3.51cto.com/wyfs02/M02/82/0D/wKioL1dJUVziJPfZAACYkpldaFQ075.png-wh_500x0-wm_3-wmp_4-s_3339076400.png" target="_blank"></a>
2).點選"Configuration"選項下面的"Host"按鈕,再點選"Items"選項,出現如下圖所示的圖形界面:
<a href="http://s2.51cto.com/wyfs02/M00/82/0E/wKiom1dJUPqQ391QAACCilUl2Fg240.png-wh_500x0-wm_3-wmp_4-s_129289807.png" target="_blank"></a>
3).點選"Create item"按鈕,出現如下圖所示的界面:
<a href="http://s4.51cto.com/wyfs02/M01/82/0E/wKiom1dJUS-BYlU8AACc_S-lYc8569.png-wh_500x0-wm_3-wmp_4-s_224696906.png" target="_blank"></a>
4).可以在裡面定義一些參數,這裡我們以監控網卡流量為例,配置在裡面的一些參數。
<a href="http://s1.51cto.com/wyfs02/M01/82/0D/wKioL1dJUnTwI_GfAACiO1gTQt0571.png-wh_500x0-wm_3-wmp_4-s_4185024145.png" target="_blank"></a>
5).配置完,點選"add"添加。
<a href="http://s5.51cto.com/wyfs02/M02/82/0D/wKioL1dJUrHhMKf_AACGJ_-uwvw231.png-wh_500x0-wm_3-wmp_4-s_3160401933.png" target="_blank"></a>
6).看到圖中所示參數的狀态,說明Item已啟用。
如下圖所示,應用和項目啟用的很明顯。
<a href="http://s5.51cto.com/wyfs02/M02/82/0E/wKiom1dJUh-STXhrAACMjSfU3pg610.png-wh_500x0-wm_3-wmp_4-s_3464057487.png" target="_blank"></a>
檢視"Dashboard",已看到有一個Item在啟用,如下圖所示:
<a href="http://s5.51cto.com/wyfs02/M02/82/0D/wKioL1dJU0TAiNksAADjCGyW-ZY259.png-wh_500x0-wm_3-wmp_4-s_4163182706.png" target="_blank"></a>
7).檢視剛采集到的資料,采集到的網卡流量的值清晰可見。如下圖所示:
<a href="http://s5.51cto.com/wyfs02/M01/82/0D/wKioL1dJU73RxRkwAACo6G-DUmo361.png-wh_500x0-wm_3-wmp_4-s_1674435755.png" target="_blank"></a>
8).點選"Graph",可以看到繪圖,如下圖所示:
<a href="http://s4.51cto.com/wyfs02/M02/82/0D/wKioL1dJVAuTPuu8AADkPV4iLxg509.png-wh_500x0-wm_3-wmp_4-s_4138649352.png" target="_blank"></a>
本文轉自伺服器運維部落格51CTO部落格,原文連結http://blog.51cto.com/shamereedwine/1776759如需轉載請自行聯系原作者
neijiade10000