zabbix簡介
zabbix是一個基於WEB界面的提供分佈式系統監視以及網絡監視功能的企業級的開源解決方案,由一個國外的團隊持續維護更新,軟件可以自由下載使用,運作團隊靠提供收費的技術支持贏利。zabbix由2部分構成,zabbix server與可選組件zabbix agent。zabbix server可以通過SNMP,zabbix agent,ping,端口監視等方法提供對遠程服務器/網絡狀態的監視,數據收集等功能。zabbix agent需要安裝在被監視的目標服務器上,它主要完成對硬件信息或與操作系統有關的內存,CPU等信息的收集。zabbix server可以單獨監視遠程服務器的服務狀態;同時也可以與zabbix agent配合,可以輪詢zabbix agent主動接收監視數據(trapping方式),同時還可被動接收zabbix agent發送的數據(trapping方式)。另外zabbix server還支持SNMP (v1,v2),可以與SNMP軟件(例如:net-snmp)等配合使用。
zabbix的主要特點:
- 安裝與配置簡單,學習成本低
- 支持多語言(包括中文)
- 免費開源
- 自動發現服務器與網絡設備
- 分佈式監視以及WEB集中管理功能
- 可以無agent監視
- 用戶安全認證和柔軟的授權方式
- 通過WEB界面設置或查看監視結果
- email等通知功能等等
Zabbix主要功能:
- CPU負荷
- 內存使用
- 磁盤使用
- 網絡狀況
- 端口監視
- 日誌監視
Zabbix安裝:
一.安裝LNMP環境
參考:http://pvbutler.blog.51cto.com/7662323/1733287
二.Zabbix服務端安裝
Server:10.15.44.18
zabbix下載、安裝編譯環境、組件
[root@localhost ~]# mkdir /app [root@localhost ~]# cd /app/ [root@localhost app]# wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.2.6/zabbix-2.2.6.tar.gz [root@localhost app]# yum -y install gcc gcc-c++ autoconf curl curl-devel net-snmp net-snmp-devel perl-DBI [root@localhost app]# tar zxvf zabbix-2.2.6.tar.gz [root@localhost app]# groupadd zabbix [root@localhost app]# useradd -s /sbin/nologin -g zabbix zabbix
創建、導入zabbix數據庫
[root@localhost app]# cd zabbix-2.2.6/database/mysql/ #進入mysql數據庫創建腳本目錄 [root@localhost mysql]# ls data.sql images.sql schema.sql [root@localhost mysql]# mysql -u root -pREDHAT Welcome to the MySQL monitor. Commands end with ; or \g. mysql> create database zabbix character set utf8; #創建數據庫zabbix,並且數據庫編碼使用utf8 Query OK, 1 row affected (0.03 sec) mysql> insert into mysql.user(Host,User,Password) values('localhost','zabbix',password('123456')); #新建賬戶zabbix,密碼123456 Query OK, 1 row affected, 3 warnings (0.02 sec) mysql> flush privileges; #刷新系統授權表 Query OK, 0 rows affected (0.00 sec) mysql> grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by '123456' with grant option; #允許賬戶zabbix能從本機連接到數據庫zabbix Query OK, 0 rows affected (0.02 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> use zabbix #進入數據庫,按照順序導入腳本文件到zabbix數據庫,否則會出錯。 mysql> source /app/zabbix-2.2.6/database/mysql/schema.sql mysql> source /app/zabbix-2.2.6/database/mysql/images.sql mysql> source /app/zabbix-2.2.6/database/mysql/data.sql mysql> exit Bye [root@localhost mysql]#
或者以下方式導入腳本到數據庫
[root@localhost mysql]# mysql -uzabbix -p123456 -hlocalhost zabbix < /app/zabbix-2.2.6/database/mysql/schema.sql [root@localhost mysql]# mysql -uzabbix -p123456 -hlocalhost zabbix < /app/zabbix-2.2.6/database/mysql/images.sql [root@localhost mysql]# mysql -uzabbix -p123456 -hlocalhost zabbix < /app/zabbix-2.2.6/database/mysql/data.sql
安裝zabbix
[root@localhost mysql]# cd /app/zabbix-2.2.6 [root@localhost zabbix-2.2.6]# ./configure --prefix=/app/zabbix --enable-server --enable-agent --with-net-snmp --with-libcurl --enable-proxy --with-mysql=/usr/bin/mysql_config [root@localhost zabbix-2.2.6]# make In file included from db.c:22: ../../../include/zbxdb.h:65:20: error: mysql.h: No such file or directory ../../../include/zbxdb.h:66:21: error: errmsg.h: No such file or directory ../../../include/zbxdb.h:67:27: error: mysqld_error.h: No such file or directory In file included from db.c:22: ../../../include/zbxdb.h:179: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token ../../../include/zbxdb.h:180: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token ../../../include/zbxdb.h:182: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘zbx_db_fetch’ db.c:38: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token db.c:165: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token db.c: In function ‘is_recoverable_mysql_error’: db.c:180: error: ‘conn’ undeclared (first use in this function) db.c:180: error: (Each undeclared identifier is reported only once db.c:180: error: for each function it appears in.) db.c:182: error: ‘CR_CONN_HOST_ERROR’ undeclared (first use in this function) db.c:183: error: ‘CR_SERVER_GONE_ERROR’ undeclared (first use in this function) db.c:184: error: ‘CR_CONNECTION_ERROR’ undeclared (first use in this function) db.c:185: error: ‘CR_SERVER_LOST’ undeclared (first use in this function) db.c:186: error: ‘CR_UNKNOWN_HOST’ undeclared (first use in this function) db.c:187: error: ‘ER_SERVER_SHUTDOWN’ undeclared (first use in this function) db.c:188: error: ‘ER_ACCESS_DENIED_ERROR’ undeclared (first use in this function) db.c:189: error: ‘ER_ILLEGAL_GRANT_FOR_TABLE’ undeclared (first use in this function) db.c:190: error: ‘ER_TABLEACCESS_DENIED_ERROR’ undeclared (first use in this function) db.c:191: error: ‘ER_UNKNOWN_ERROR’ undeclared (first use in this function) db.c: In function ‘zbx_db_connect’: db.c:294: error: ‘conn’ undeclared (first use in this function) db.c:296: error: ‘CLIENT_MULTI_STATEMENTS’ undeclared (first use in this function) db.c: In function ‘zbx_db_close’: db.c:559: error: ‘conn’ undeclared (first use in this function) db.c: In function ‘zbx_db_vexecute’: db.c:1019: error: ‘conn’ undeclared (first use in this function) db.c: At top level: db.c:1149: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token db.c:1478: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token db.c:1607: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘zbx_db_fetch’ make[3]: *** [db.o] Error 1 make[3]: Leaving directory `/app/zabbix-2.2.6/src/libs/zbxdb' make[2]: *** [all-recursive] Error 1 make[2]: Leaving directory `/app/zabbix-2.2.6/src/libs' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/app/zabbix-2.2.6/src' make: *** [all-recursive] Error 1 [root@localhost zabbix-2.2.6]# zabbix編譯時找不到mysql.h文件,需要安裝 mysql-devel包 root@localhost zabbix-2.2.6]# yum install mysql-devel -y [root@localhost zabbix-2.2.6]# make checking for mysql_config... /usr/bin/mysql_config checking for main in -lmysqlclient ... no configure: error: Not found mysqlclient library [root@localhost zabbix-2.2.6]# ln -s /usr/lib64/mysql/libmysqlclient.so.16.0.0 /usr/lib64/mysql/libmysqlclient.so #32位系統爲/usr/lib/mysql,注意系統版本同,文件版本可能不一樣,這裏是16.0.0 [root@localhost zabbix-2.2.6]# ln -s /usr/lib64/mysql/libmysqlclient_r.so.16.0.0 /usr/lib64/mysql/libmysqlclient_r.so [root@localhost zabbix-2.2.6]# make [root@localhost zabbix-2.2.6]# make install [root@localhost zabbix-2.2.6]# ln -s /app/zabbix/sbin/* /usr/local/sbin/ [root@localhost zabbix-2.2.6]# ln -s /app/zabbix/bin/* /usr/local/bin/
數據庫是編譯安裝的所以要把環境變量導出:export PATH=$PATH:/usr/local/mysql/bin >> /etc/profile && source /etc/profile
參數說明:
--prefix=/app/zabbix #zabbix的安裝目錄 -
-enable-server #作爲服務器端
--enable-agent #作爲客戶端
--with-mysql # 支持mysql zabbix也運行ladp,oracle,postgresql,sqlite3等數據庫
--with-net-snmp # 支持snmp
--with-libcurl # 是用來監控web頁面的
修改zabbix配置文件
[root@localhost zabbix-2.2.6]# cd /app/zabbix/etc/ [root@localhost etc]# cp zabbix_server.conf zabbix_server.confbak [root@localhost etc]# vim zabbix_server.conf LogFile=/app/zabbix/logs/zabbix_server.log PidFile=/app/zabbix/pid/zabbix_server.pid DBHost=localhost DBName=zabbix #數據庫名稱 DBUser=zabbix #數據庫用戶名 DBPassword=123456 #數據庫密碼 ListenIP=127.0.0.1 #數據庫ip地址 CacheSize=512M #根據服務器性能修改,太小後面會報out of memory AlertScriptsPath=/app/zabbix/alertscripts #zabbix運行腳本存放目錄 [root@localhost etc]# cp zabbix_agentd.conf zabbix_agentd.confbak [root@localhost etc]# vim zabbix_agentd.conf Include=/app/zabbix/etc/zabbix_agentd.conf.d/ Server=127.0.0.1 UnsafeUserParameters=1 #啓用自定義key LogFile=/app/zabbix/logs/zabbix_agentd.log [root@localhost etc]# mkdir ../logs [root@localhost etc]# touch ../logs/zabbix_server.log [root@localhost etc]# touch ../logs/zabbix_agentd.log [root@localhost etc]# mkdir ../pid [root@localhost etc]# touch ../pid/zabbix_server.pid [root@localhost etc]# mkdir alertscripts [root@localhost etc]# chmod 777 ../logs/zabbix_* [root@localhost etc]# chmod 777 ../pid/zabbix_server.pid
添加開機啓動腳本
[root@localhost etc]# cd /app/zabbix-2.2.6/misc/init.d/fedora/core/ [root@localhost core]# cp zabbix_server /etc/rc.d/init.d/zabbix_server [root@localhost core]# cp zabbix_agentd /etc/rc.d/init.d/zabbix_agentd [root@localhost core]# chmod +x /etc/rc.d/init.d/zabbix_* [root@localhost core]# chkconfig --add zabbix_server [root@localhost core]# chkconfig --add zabbix_agentd [root@localhost core]# chkconfig zabbix_server on [root@localhost core]# chkconfig zabbix_agentd on [root@localhost core]# vim /etc/rc.d/init.d/zabbix_server BASEDIR=/app/zabbix [root@localhost core]# vim /etc/rc.d/init.d/zabbix_agentd BASEDIR=/app/zabbix [root@localhost core]#
添加zabbix服務對應的端口
[root@localhost core]# cp /etc/services /etc/servicesbak [root@localhost core]# vim /etc/services #文末添加以下4行 zabbix-agent 10050/tcp # Zabbix Agent zabbix-agent 10050/udp # Zabbix Agent zabbix-trapper 10051/tcp # Zabbix Trapper zabbix-trapper 10051/udp # Zabbix Trapper [root@localhost core]#
配置web站點
/usr/share/nginx/html/爲Nginx默認站點目錄 nginx爲Nginx運行賬戶
[root@localhost core]# cp -r /app/zabbix-2.2.6/frontends/php /usr/share/nginx/html/zabbix [root@localhost core]# chown nginx:nginx -R /usr/share/nginx/html/zabbix/ [root@localhost core]# service zabbix_server start Starting zabbix_server: [ OK ] [root@localhost core]# service zabbix_agentd start Starting zabbix_agentd: [ OK ] [root@localhost core]#
修改php配置文件參數
[root@localhost core]# cp /etc/php.ini /etc/php.inibak2 [root@localhost core]# vim /etc/php.ini post_max_size = 16M max_execution_time = 300 max_input_time = 300 [root@localhost core]# cp /etc/php-fpm.conf /etc/php-fpm.confbak [root@localhost core]# vim /etc/php-fpm.conf request_terminate_timeout = 300 [root@localhost core]# service php-fpm reload Reloading php-fpm: [ OK ] [root@localhost core]#
安裝web
在瀏覽器中打開:http://10.15.44.18/zabbix/setup.php
(無法打開頁面將php.ini中的open_basedir註釋掉,或者修改成open_basedir = /usr/share/nginx/html/:/tmp/)
Next
檢查系統環境設置,必須全部都爲ok,才能繼續Next,如果php編譯安裝時沒有加載gettext這個模塊支持多語言可以到源碼php編譯目錄下去重新加載這個模塊。
cd /usr/local/src/php-5.3.0/ext/gettext /usr/local/php/bin/phpize #執行此命令 ./configure --with-php-config=/usr/local/php/bin/php-config #重新編譯php make && make install
配置MySQL數據庫信息
Database:MySQL
Database host:127.0.0.1
Database port:use default port
Database name:zabbix
User:zabbix
Password:123456
Test connection #測試數據庫連接是否正常,顯示ok表示通過
測試OK後點擊Next繼續
默認,Next
檢查一下設置情況,沒問題直接Next
下載配置文件,並把他放置在conf/ 目錄下,Finish 安裝完成
默認賬號:用戶名 admin 密碼 zabbix
注:如下報錯是因爲zabbix數據未導入MYSQL數據庫:
[root@localhost src]# netstat -tunpl | grep zabbix tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 2026/zabbix_agentd [root@localhost src]# sestatus SELinux status: disabled [root@localhost src]# tail -50f zabbix_server.log 2044:20160111:101348.978 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: YES) 2044:20160111:101348.978 Database is down. Reconnecting in 10 seconds. 2044:20160111:101358.978 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: YES) 2044:20160111:101358.978 Database is down. Reconnecting in 10 seconds. [root@localhost src]# mysql -u root -p mysql> grant all privileges on zabbix.* to zabbix@localhost identified by '123456'; Query OK, 0 rows affected (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye [root@localhost src]# service mysqld restart Stopping mysqld: [ OK ] Starting mysqld: [ OK ] [root@localhost src]# service nginx restart Stopping nginx: [ OK ] Starting nginx: [ OK ] [root@localhost src]# netstat -tunpl | grep zabbix tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 2026/zabbix_agentd tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 4383/zabbix_server [root@localhost src]#
查看zabbix的版本號:
[root@Zabbix ~]# zabbix_server --version Zabbix server v2.2.6 (revision 48483) (27 August 2014) Compilation time: Jan 10 2016 19:58:57 [root@Zabbix ~]#