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负荷
- 内存使用
- 磁盘使用
- 网络状况
- 端口监视
- 日志监视
一.安装LNMP环境
参考:http://pvbutler.blog.51cto.com/7662323/1845685
二.Zabbix服务端安装
[[email protected]_Server Tools]# tar zxvf zabbix-3.0.4.tar.gz [[email protected]_Server Tools]# cd zabbix-3.0.4/database/mysql/ [[email protected]_Server mysql]# ls data.sql images.sql schema.sql [[email protected]_Server mysql]# mysql -u root -pZabbix mysql> create database zabbix character set utf8; #创建数据库zabbix,并且数据库编码使用utf8 Query OK, 1 row affected (0.00 sec) mysql> insert into mysql.user(Host,User,Password) values(‘localhost‘,‘zabbix‘,password(‘zabbix‘)); ERROR 1364 (HY000): Field ‘ssl_cipher‘ doesn‘t have a default value mysql> quit; [[email protected]_Server mysql]# vim /app/mysql/my.cnf #sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 指定了严格模式,为了安全,严格模式禁止通过insert 这种形式直接修改mysql库中的user表进行添加新用户 sql_mode=NO_ENGINE_SUBSTITUTION #将配置文件中的STRICT_TRANS_TABLES删掉 [[email protected]_Server mysql]# service mysqld restart [[email protected]_Server mysql]# mysql -u root -pZabbix mysql> insert into mysql.user(Host,User,Password) values(‘localhost‘,‘zabbix‘,password(‘zabbix‘)); #新建账户zabbix,密码zabbix Query OK, 1 row affected, 3 warnings (0.00 sec) mysql> flush privileges; #刷新系统授权表 Query OK, 0 rows affected (0.00 sec) mysql> grant all on zabbix.* to ‘zabbix‘@‘localhost‘ identified by ‘zabbix‘ with grant option; #允许账户zabbix能从本机连接到数据库zabbix Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> use zabbix; #进入数据库,按照顺序进行导入,否则会出错。 Database changed mysql> source /usr/local/Tools/zabbix-3.0.4/database/mysql/schema.sql ... Query OK, 0 rows affected (0.05 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> source /usr/local/Tools/zabbix-3.0.4/database/mysql/images.sql ... Query OK, 1 row affected (0.01 sec) mysql> source /usr/local/Tools/zabbix-3.0.4/database/mysql/data.sql ... Query OK, 1 row affected (0.00 sec) Query OK, 0 rows affected (0.01 sec) mysql> exit; Bye [[email protected]_Server mysql]# ln -s /usr/lib64/mysql/libmysqlclient.so.16.0.0 /usr/lib64/mysql/libmysqlclient.so #32位系统为/usr/lib/mysql,注意系统版本同,文件版本可能不一样,这里是16.0.0 [[email protected]_Server mysql]# ln -s /usr/lib64/mysql/libmysqlclient_r.so.16.0.0 /usr/lib64/mysql/libmysqlclient_r.so [[email protected]_Server mysql]# cd /usr/local/Tools/zabbix-3.0.4 [[email protected]_Server zabbix-3.0.4]# groupadd zabbix [[email protected]_Server zabbix-3.0.4]# useradd -g zabbix zabbix -s /sbin/nologin [[email protected]_Server zabbix-3.0.4]# yum -y install mysql-devel mysql-community-devel unixODBC-devel libssh2-devel OpenIPMI-devel net-snmp-devel curl-devel net-snmp-libs net-snmp-utils [[email protected]_Server zabbix-3.0.4]# chkconfig snmpd on [[email protected]_Server zabbix-3.0.4]# ./configure --prefix=/app/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-unixodbc --with-ssh2 --with-openipmi --with-openssl [[email protected]_Server zabbix-3.0.4]# make && make install [[email protected]_Server zabbix-3.0.4]# cp /usr/local/Tools/zabbix-3.0.4/misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server [[email protected]_Server zabbix-3.0.4]# cp /usr/local/Tools/zabbix-3.0.4/misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd [[email protected]_Server zabbix-3.0.4]# chmod +x /etc/rc.d/init.d/zabbix_* [[email protected]_Server zabbix-3.0.4]# chkconfig zabbix_server on [[email protected]_Server zabbix-3.0.4]# chkconfig zabbix_agentd on [[email protected]_Server zabbix-3.0.4]# vim /app/zabbix/etc/zabbix_agentd.conf BASEDIR=/app/zabbix [[email protected]_Server zabbix-3.0.4]# vim /etc/rc.d/init.d/zabbix_agentd BASEDIR=/app/zabbix [[email protected]_Server zabbix-3.0.4]# cp /app/zabbix/etc/zabbix_server.conf{,bak} [[email protected]_Server zabbix-3.0.4]# ln -s /app/zabbix/sbin/* /usr/local/sbin/ [[email protected]_Server zabbix-3.0.4]# ln -s /app/zabbix/bin/* /usr/local/bin/ [[email protected]_Server zabbix-3.0.4]# vim /app/zabbix/etc/zabbix_server.conf LogFile=/app/zabbix/logs/zabbix_server.log PidFile=/app/zabbix/pid/zabbix_server.pid DBName=zabbix DBUser=zabbix DBPassword=zabbix ListenIP=localhost CacheSize=1024M #根据服务器性能修改,太小后面会报out of memory AlertScriptsPath=/app/zabbix/alertscripts #zabbix运行脚本存放目录 [[email protected]_Server zabbix-3.0.4]# cp /app/zabbix/etc/zabbix_agentd.conf{,bak} [[email protected]_Server zabbix-3.0.4]# vim /app/zabbix/etc/zabbix_agentd.conf LogFile=/app/zabbix/logs/zabbix_agentd.log Include=/app/zabbix/etc/zabbix_agentd.conf.d/ UnsafeUserParameters=1 #启用自定义key [[email protected]_Server zabbix-3.0.4]# mkdir -p /app/zabbix/logs [[email protected]_Server zabbix-3.0.4]# touch /app/zabbix/logs/zabbix_agentd.log [[email protected]_Server zabbix-3.0.4]# touch /app/zabbix/logs/zabbix_server.log [[email protected]_Server zabbix-3.0.4]# mkdir /app/zabbix/pid [[email protected]_Server zabbix-3.0.4]# touch /app/zabbix/pid/zabbix_server.pid [[email protected]_Server zabbix-3.0.4]# chmod 766 /app/zabbix/pid/* [[email protected]_Server zabbix-3.0.4]# chmod 766 /app/zabbix/logs/*
如果没有mysql_config,需要安装yum install mysql-devel
配置web站点
[[email protected]_Server zabbix-3.0.4]# rm -rf /app/nginx/html/* [[email protected]_Server zabbix-3.0.4]# cp -r /usr/local/Tools/zabbix-3.0.4/frontends/php/* /app/nginx/html/ [[email protected]_Server zabbix-3.0.4]# chown www.www -R /app/nginx/html/ [[email protected]_Server zabbix-3.0.4]# service zabbix_agentd start [[email protected]_Server zabbix-3.0.4]# service zabbix_agentd start [[email protected]_Server zabbix-3.0.4]# tail /app/zabbix/logs/zabbix_server.log 21858:20160906:072015.723 Ez Texting notifications: YES 21858:20160906:072015.724 ODBC: YES 21858:20160906:072015.724 SSH2 support: YES 21858:20160906:072015.724 IPv6 support: YES 21858:20160906:072015.724 TLS support: YES 21858:20160906:072015.724 ****************************** 21858:20160906:072015.724 using configuration file: /app/zabbix/etc/zabbix_server.conf 21858:20160906:072015.730 current database version (mandatory/optional): 03000000/03000000 21858:20160906:072015.730 required mandatory version: 03000000 21858:20160906:072015.735 listener failed: cannot resolve address [[localhost]:10051]: [-2] Name or service not known [[email protected]_Server zabbix-3.0.4]# vim /app/zabbix/etc/zabbix_server.conf #ListenIP=localhost ListenIP=127.0.0.1 [[email protected]_Server logs]# service zabbix_server start [[email protected]_Server logs]# netstat -ntlp |grep zabbix tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 22490/zabbix_agentd tcp 0 0 127.0.0.1:10051 0.0.0.0:* LISTEN 22419/zabbix_server tcp 0 0 :::10050 :::* LISTEN 22490/zabbix_agentd [[email protected]_Server logs]#
修改php配置文件参数
[[email protected]_Server zabbix-3.0.4]# cp /app/php/etc/php.ini{,bak} [[email protected]_Server zabbix-3.0.4]# vim /app/php/etc/php.ini post_max_size = 16M max_execution_time = 300 max_input_time = 300 [[email protected]_Server zabbix-3.0.4]# cp /app/php/etc/php-fpm.conf{,bak} [[email protected]_Server zabbix-3.0.4]# vim /app/php/etc/php-fpm.conf request_terminate_timeout = 300 [[email protected]_Server zabbix-3.0.4]# service php-fpm restart
安装web
在浏览器里直接输入IP地址http://192.168.100.176安装
下一步,提示:PHP option "always_populate_raw_post_data" must be set to "-1"
修改php.ini中always_populate_raw_post_data = -1
[[email protected]_Server conf]# vim /app/php/etc/php.ini always_populate_raw_post_data = -1 [[email protected]_Server conf]# service php-fpm restart
刷新页面,下一步
配置MySQL数据库信息
Database:MySQL
Database host:localhost
Database port:0 use default port 3306
Database name:zabbix
User:zabbix
Password:zabbix
直接下一步
检查一下设置情况,没问题直接Next
默认Username: Admin、Password: zabbix