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环境
参考:
二.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]# lsdata.sql p_w_picpaths.sql schema.sql [root@localhost mysql]# mysql -u root -pREDHATWelcome to the MySQL monitor. Commands end with ; or \g.mysql> create database zabbix character set utf8; #创建数据库zabbix,并且数据库编码使用utf8Query OK, 1 row affected (0.03 sec)mysql> insert into mysql.user(Host,User,Password) values('localhost','zabbix',password('123456')); #新建账户zabbix,密码123456Query 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能从本机连接到数据库zabbixQuery 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/p_w_picpaths.sqlmysql> source /app/zabbix-2.2.6/database/mysql/data.sqlmysql> exitBye[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/p_w_picpaths.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 directoryIn 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 ‘*’ tokendb.c:165: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ tokendb.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 oncedb.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 ‘*’ tokendb.c:1478: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ tokendb.c:1607: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘zbx_db_fetch’make[3]: *** [db.o] Error 1make[3]: Leaving directory `/app/zabbix-2.2.6/src/libs/zbxdb'make[2]: *** [all-recursive] Error 1make[2]: Leaving directory `/app/zabbix-2.2.6/src/libs'make[1]: *** [all-recursive] Error 1make[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_configchecking for main in -lmysqlclient ... noconfigure: 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.confLogFile=/app/zabbix/logs/zabbix_server.logPidFile=/app/zabbix/pid/zabbix_server.pidDBHost=localhostDBName=zabbix #数据库名称DBUser=zabbix #数据库用户名DBPassword=123456 #数据库密码ListenIP=127.0.0.1 #数据库ip地址CacheSize=512M #根据服务器性能修改,太小后面会报out of memoryAlertScriptsPath=/app/zabbix/alertscripts #zabbix运行脚本存放目录[root@localhost etc]# cp zabbix_agentd.conf zabbix_agentd.confbak[root@localhost etc]# vim zabbix_agentd.confInclude=/app/zabbix/etc/zabbix_agentd.conf.d/Server=127.0.0.1UnsafeUserParameters=1 #启用自定义keyLogFile=/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 Agentzabbix-agent 10050/udp # Zabbix Agentzabbix-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 startStarting zabbix_server: [ OK ][root@localhost core]# service zabbix_agentd startStarting zabbix_agentd: [ OK ][root@localhost core]#
修改php配置文件参数
[root@localhost core]# cp /etc/php.ini /etc/php.inibak2[root@localhost core]# vim /etc/php.inipost_max_size = 16Mmax_execution_time = 300max_input_time = 300[root@localhost core]# cp /etc/php-fpm.conf /etc/php-fpm.confbak[root@localhost core]# vim /etc/php-fpm.confrequest_terminate_timeout = 300[root@localhost core]# service php-fpm reloadReloading php-fpm: [ OK ][root@localhost core]#
安装web
在浏览器中打开:
(无法打开页面将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 #重新编译phpmake && 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 zabbixtcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 2026/zabbix_agentd [root@localhost src]# sestatusSELinux 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 -pmysql> 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> quitBye[root@localhost src]# service mysqld restartStopping mysqld: [ OK ]Starting mysqld: [ OK ][root@localhost src]# service nginx restartStopping nginx: [ OK ]Starting nginx: [ OK ][root@localhost src]# netstat -tunpl | grep zabbixtcp 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 --versionZabbix server v2.2.6 (revision 48483) (27 August 2014)Compilation time: Jan 10 2016 19:58:57[root@Zabbix ~]#