1、zabbix簡介
zabbix是一個基于WEB界面的提供分布式系統監視以及網絡監視功能的企業級的開源解決方案。
zabbix由zabbix server與可選組件zabbix agent兩部門組成。
zabbix server可以通過SNMP,zabbix agent,ping,端口監視等方法提供對遠程服務器/網絡狀態的監視。
zabbix agent需要安裝在被監視的目標服務器上,它主要完成對硬件信息或與操作系統有關的內存,CPU等信息的收集。
zabbix的主要特點:
- 安裝與配置簡單,學習成本低
- 支持多語言(包括中文)
- 免費開源
- 自動發現服務器與網絡設備
- 分布式監視以及WEB集中管理功能
- 可以無agent監視
- 用戶安全認證和柔軟的授權方式
- 通過WEB界面設置或查看監視結果
- email等通知功能
等等
Zabbix主要功能:
- CPU負荷
- 內存使用
- 磁盤使用
- 網絡狀況
- 端口監視
- 日志監視
官方也提供了安裝資料:http://www.zabbix.com/wiki/howto/monitor
Zabbix的架構
2、zabbix 安裝
系統:CentOS release 6.5
內核:Linux agent 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
zabbix版本:zabbix-2.2.3
zabbix是有php語言開發,需要lnmp環境或者lamp
1.yum安裝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-mbstringphp-ldap php-pear php-xmlrpc php-bcmath mysql-connector-odbc mysql-devel libdbi-dbd-mysql net-snmp-devel curl-devel unixODBC-devel OpenIPMI-devel ja va-devel
2、配置LAMP使用環境, 編輯/etc/php.ini文件,修改以下內容
date.timezone = Asia/Shanghai
max_execution_time = 300
post_max_size = 32M
max_input_time = 300
memory_limit = 128M
mbstring.func_overload = 2
啟動httpd、mysqld服務
# chkconfig mysqld on
# chkconfig httpd on
# service mysqld start
# service httpd start
3.下載并安裝zabbix服務端
wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.2.3/zabbix-2.2.3.tar.gz
創建zabbix用戶
# groupadd zabbix
# useradd zabbix -g zabbix
安裝zabbix
# tar xf zabbix-2.2.3.tar.gz
# cd zabbix-2.2.3
# ./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
報錯如下:
checking for SSH2 support... no
configure: error: SSH2 library not found
解決辦法:
yum -y install libssh2-devel
上面一個報錯解決了,繼續./configure,又出現如下錯誤:
checking for LDAP support... no
configure: error: Invalid LDAP directory - unable to find ldap.h
解決辦法:
yum -y install openldap openldap-devel
make
make install
4.添加zabbix 到系統服務文件
# vi /etc/services(在rhel/centos系列中,下面的服務參數可以不用添加,默認已經有了)
zabbix-agent 10050/tcp # Zabbix Agent
zabbix-agent 10050/udp # Zabbix Agent
zabbix-trapper 10051/tcp # Zabbix Trapper
zabbix-trapper 10051/udp # Zabbix Trapper
5.導入zabbix數據庫
[root@zabbix zabbix-2.2.3]# mysqladmin -uroot password 'abc123,'
[root@zabbix zabbix-2.2.3]# mysqladmin -uroot password 'abc123,'
[root@zabbix zabbix-2.2.3]# mysql -uroot -p
mysql> create database zabbix character set utf8;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
mysql> flush privileges;
測試下連接是否正常
[root@zabbix zabbix-2.2.3]# mysql -uzabbix -pzabbix zabbix
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
導入數據庫文件
[root@zabbix zabbix-2.2.3]# mysql -uzabbix -pzabbix zabbix < ./database/mysql/schema.sql
[root@zabbix zabbix-2.2.3]# mysql -uzabbix -pzabbix zabbix < ./database/mysql/images.sql
[root@zabbix zabbix-2.2.3]# mysql -uzabbix -pzabbix zabbix < ./database/mysql/data.sql
6.創建zabbix日志目錄
# mkdir /var/log/zabbix
# chown zabbix.zabbix /var/log/zabbix
7.設置zabbix啟動腳本
[root@zabbix zabbix-2.2.3]# cp misc/init.d/fedora/core/zabbix_* /etc/init.d/
[root@zabbix zabbix-2.2.3]# chmod 755 /etc/init.d/zabbix_*
[root@zabbix zabbix-2.2.3]# sed -i "s#BASEDIR=/usr/local#BASEDIR=/usr/#" /etc/init.d/zabbix_server
[root@zabbix zabbix-2.2.3]# sed -i "s#BASEDIR=/usr/local#BASEDIR=/usr/#" /etc/init.d/zabbix_agentd
8.編輯/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
修改完成后可通過以下命令進行查看:
grep -Ev "(#|^$)" /etc/zabbix/zabbix_server.conf
9.編輯/etc/zabbix/zabbix_agentd.conf文件,修改以下參數
LogFile=/var/log/zabbix/zabbix_agentd.log
EnableRemoteCommands=0
Server=127.0.0.1,172.16.10.72 #zabbix服務端IP
StartAgents=8
ServerActive=172.16.10.72:10051
Hostname=Zabbix server
Timeout=30
Include=/etc/zabbix/zabbix_agentd.conf.d/
UnsafeUserParameters=1
修改完成后可通過以下命令進行查看:
grep -Ev "(#|^$)" /etc/zabbix/zabbix_agentd.conf
10.拷貝zabbix網頁文件到apache目錄
[root@zabbix zabbix-2.2.3]# cp -r ./frontends/php/ /var/www/html/zabbix
[root@zabbix zabbix-2.2.3]# chown -R apache.apache /var/www/html/zabbix
11.開啟zabbix服務
root@zabbix zabbix-2.2.3]# chkconfig zabbix_server on
[root@zabbix zabbix-2.2.3]# chkconfig zabbix_agentd on
[root@zabbix zabbix-2.2.3]# service zabbix_server start
Starting zabbix_server: [ OK ]
[root@zabbix zabbix-2.2.3]# service zabbix_agentd start
Starting zabbix_agentd: [ OK ]
#查看zabbix服務是否啟動
[root@zabbix zabbix-2.2.3]# netstat -antpl|grep zabbix
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 22542/zabbix_agentd
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 22473/zabbix_server
tcp 0 0 :::10050 :::* LISTEN 22542/zabbix_agentd
tcp 0 0 :::10051 :::* LISTEN 22473/zabbix_server
12.通過web頁面配置zabbix
service iptables stop #暫時關閉防火墻
打開瀏覽器,訪問:http://172.16.100.16/zabbix,不出意外,會看到如下頁面
點擊next,進入下一步
解決方法:
yum install php-mbstring
service httpd restart
到此web頁面配置完畢,已經到了登陸界面,zabbix的默認登陸賬號是admin,密碼是zabbix
登錄后發現一個報錯:zabbbix server is not running:the information displayed may not be current
經過排查,發現是selinux惹的禍
解決辦法:關閉selinux
setenforce 0
查看10051端口是否開啟,如未啟動
/etc/init.d/zabbix_server start
開啟后10051端口又自動關閉,查看日志
cat /var/log/zabbix/zabbix_server.log
報錯連接數據庫失敗
是由于連接到數據庫的數量比較多,mysql 默認的連接數是100,一般設置到500~1000比較合適,我們可以調大這個值:修改/etc/my.cnf這個文件,在[mysqld]中新增max_connections=1000
然后重啟mysql和zabbix_server zabbix_agent
刷新頁面
添加中文支持,默認是沒有中文選項
原來zabbix默認把對中文的支持給關閉了,我們需要修改zabbix的php源文件. 修改站點根目錄下include/locales.inc.php文件.
更改為
重啟zabbix服務
監控圖形出現亂碼
1.從windows下控制面板->字體->選擇一種中文字庫例如“楷體” 【復制-粘貼出來,然后拷貝到zabbix服務器上】
將這個文件拷貝到zabbix的數據目錄的fonts目錄下
之前部署的zabbix數據目錄是/var/www/html/zabbix/fonts
[root@Zabbix-server fonts]# pwd /var/www/html/zabbix/fonts
[root@Zabbix-server fonts]#ls
將上面從windows的“控制面板”----“字體”里下載下來的simkai.ttf文件拷貝到這里。并且將之前的字體文件DejaVuSans.ttf移動到別處
[root@Zabbix-server fonts]# ls simkai.ttf
然后,接著修改代碼include/defines.inc.php文件中的字體配置,將里面關于字體設置從DejaVuSans替換成simkai
———————————————分割線—————————————————
本文參考:http://www.cnblogs.com/Eivll0m/p/3807604.html
常見報錯 :https://www.iyunv.com/thread-25966-1-1.html
在linux系統中,幾乎所有運行的服務都會產生相對就的日志(log),所運行的程序在出錯時都會有錯誤提示,即使沒有任何提示也可以通過“echo $”來查看運行是否成功。使用zabbix已經有一段時間了,整理一下遇到過的問題和解決的方法以。
zabbix的日志存放在/tmp下,服務器端對應的日志是zabbix_server.log,被監控端對應的日志是zabbix_agentd.log.
一,zabbix服務是否已經開啟成功
查看系統是否已經有zabbix進程正在運行 # ps aux |grep zabbix 查看系統是否已監聽zabbix server和zabbix agent所使用的10050、10051端口 # netstat -nplut |grep zabbix 如果沒有,則開啟:#/etc/init.d/zabbix_server_ctl start #/etc/init.d/zabbix_agent_ctl start特別需要注意的是:每次修改完配置文件之后都需要重新啟動對應的zabbix server或者zabbix agentd。
部分運行腳本在做restart時無法關閉zabbix導致服務無法重新啟動,可用kill的命令把zabbix相關的進程殺掉再啟動。
二、zabbix_server.log出現的提示
2009:20121023:193549.354 Sending list of active checks to [192.168.30.3] failed: host [CentOS-3] not found
這是因為zabbix_agentd.conf配置文件中的Hostname與web中的主機名對應。
三、網頁中了出現的錯誤
(1)
Get value from agent failed: cannot connect to [[192.168.30.2]:10050]: [111] Connection refused
192.168.30.2是我的zabbix server服務器,本身也有監控自己本身的agent功能。出現這種錯誤是因為忘記在zabbix服務器開戶zabbix_agentd。在Last 20 issues中也有提示
Last 20 issues
Host
Issue
Last change
Age
Ack
Actions
Zabbix server
Server Zabbix server is unreachable
23 Oct 2012 18:42:14
6m 57s
No
解決方法:開啟zabbix_agentd即可。
(2)
Get value from agent failed: cannot connect to [[192.168.30.3]:10050]: [113] No route to host
看提示“No route to host”,與網絡連接有關。排除的方法如下:
a)查看192.168.30.3這臺機器是否已開機
b)在zabbix server端向這臺機器ping,看網絡是否通
c)用telnet 登錄10050和10051端口,看該主機是否允許這兩個端口通訊
d)查看iptables防火墻規則是否攔截10050、10051端口
(3)
網頁中不停地有以下紅色提示:
zabbix server is not running: the information displayed may not be current.
zabbix 遇到上面的問題
可以從以下幾個方面入手檢查,當然先查日志,如果不想查日志,先檢查下面幾項是否正常
selinux是否關閉。
zabbix web目錄下面 $ZBX_SERVER 是否為ip,如果是localhost,ping下localhost是否能解析。
3.查看php的fsockopen模塊是否啟用。
zabbix server is running | No.
查看/tmp/zabbix_server.log和/tmp/zabbix_agent.log無任何異常。看zabbix_server和zabbix_agent進程、端口都正常……幾翻google以后并嘗試,終于得到了解決!
http://www.zabbix.com/forum/showthread.php?t=23878&page=3 這里面有說到zabbix受selinux的影響而已有這種錯誤提示。
http://www.zabbix.com/forum/showthread.php?t=25321 這里面說到了修改hostname為IP的做法。
我具體的做法是:
①查看selinux產生的log,確實有錯誤提示:
tail -f /var/log/audit/audit.log
type=AVC msg=audit(1351863204.990:32): avc: denied { name_connect } for pid=1575 comm="httpd" dest=10051 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:port_t:s0 tclass=tcp_socket
type=SYSCALL msg=audit(1351863204.990:32): arch=40000003 syscall=102 success=no exit=-13 a0=3 a1=bfd494b0 a2=b76b0ad8 a3=d items=0 ppid=1434 pid=1575 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)
②然后讓selinux允許它通過
setsebool -P httpd_can_network_connect on③編輯zabbix.conf.php文件,把$ZBX_SERVER的值改為本機的IP地址
$ZBX_SERVER = '192.168.30.2'; #######用IP代替hostname
④OK
四、
tail /tmp/zabbix_server.log 顯示
50952:20141012:195519.884 One child process died (PID:51233,exitcode/signal:255). Exiting ...
表示一個子進程死掉,是一個zabbix內存溢出錯誤 (此錯誤同樣會造成上面紅色的閃爍)
更正:
vim /etc/zabbix/zabbix_server.conf
CacheSize=512M
修改此值后OK
五、 tail /tmp/zabbix_server.log 顯示
2552:20141012:211700.552 [Z3001] connection to database 'zabbix' failed: [1040] Too many connections
是由于連接到數據庫的數量比較多,mysql 默認的連接數是100,一般設置到500~1000比較合適,我們可以調大這個值:修改/etc/my.cnf這個文件,在[mysqld]中新增max_connections=1000
然后重啟mysql和zabbix_server zabbix_agent
用戶自定義腳本監控:
a)
有時候用戶自定義的腳本運行的時間可能比較長,如超過10秒的20秒的。這時在執行zabbix_agentd -p 或者zabbix_agentd -t時就可能出現“Alarm clock”,從而得不到想要的結果。這是因為zabbix agentd配置文件中定義Timeout時間默認為3秒,腳本運行取結果的時間超過了3秒就會出現這種情況。
解決方法:編輯配置文件/etc/zabbix/zabbix_agentd.conf,找到"Timeout"把它定義為30秒或小于30秒。
b)
對a中的情況還需要注意對zabbix服務器端的配置,如我自己定義的腳本
UserParameter=ping.avgtime,ping 192.168.30.2 -c 10 -w 29 |grep 'avg' |awk -F "/" '{print $5}' 對192.168.30.2 ping 10取平均值,-w參數是對ping限定時間為29秒這個腳本運行的大概時間為10秒左右,此時在agent端雖然可以用zabbix_agentd -t得到結果,但是在zabbix服務器端日志會不斷的出現
1762:20121023:191941.360 resuming Zabbix agent checks on host [Zabbix server]: connection restored
1761:20121023:191952.149 Zabbix agent item [ping.avgtime] on host [CentOS-3] failed: first network error, wait for 15 seconds
1762:20121023:192010.610 Zabbix agent item [ping.avgtime] on host [CentOS-3] failed: another network error, wait for 15 seconds
1762:20121023:192028.628 Zabbix agent item [ping.avgtime] on host [CentOS-3] failed: another network error, wait for 15 seconds
這樣的錯誤日志,并且在web端也沒有畫出圖來。
解決方法:
①編輯zabbix服務器端的配置文件/etc/zabbix/zabbix_server.conf找到"Timeout"把它定義為30秒或小于30秒。
②如果還有類似提示則應該是zabbix服務器的內存設置得太小了,加大服務器內存便可。