zabbix源码安装
Zabbix通过C/S模式采集数据,通过B/S模式在web端展示和配置。
被监控端:主机通过安装agent方式采集数据,网络设备通过SNMP方式采集数据
Server端:通过收集SNMP和agent发送的数据,写入MySQL数据库,再通过php+apache在web前端展示。
Zabbix运行条件:
Server:
Zabbix Server需运行在LAMP或LNMP环境下,对硬件要求低
Agent:
目前已有的agent基本支持市面常见的Linux、HPUX、Solaris、Sun、windows等
1.安装系统:CentOS 6.5 部署LAMP架构
2.源码包:官网下载zabbix-2.4.3.tar.gz
1.服务端环境准备
配置好yum源,确认已安装httpd,mysql-server,php
安装所需的依赖环境
# yum install mysql-devel gcc net-snmp-devel curl-devel perl-DBI php-gd php-mysql php-bcmath php-mbstring php-xml -y
增加zabbix用户和组
# groupadd zabbix
# useradd -g zabbix -m zabbix
下载zabbix-2.4.3.tar.gz解压
# tar zxvf zabbix-2.4.3.tar.gz
2.数据库准备
启动mysqld服务并进入mysql,创建zabbix库和用户
mysql> create database zabbix default charset utf8;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on zabbix.* to zabbix@'localhost'
-> identified by '123';
mysql> grant all on zabbix.* to zabbix@'127.0.0.1'
-> identified by '123';
导入zabbix基础数据到数据库,注意按顺序导入
# cd /root/zabbix-2.4.3/database/mysql/
# mysql -u zabbix -p123 zabbix < schema.sql
# mysql -u zabbix -p123 zabbix < images.sql
# mysql -u zabbix -p123 zabbix < data.sql
1.编译安装zabbix
进入zabbix-2.4.3
# ./configure --prefix=/usr/local/zabbix --enable-server --with-mysql --with-net-snmp --with-jabber --with-libcurl --with-openipmi --enable-agent
报错checking for IKSEMEL... No
configure: error: Jabber library not found
需要安装iksemel和iksemel-devel
下载安装iksemel-1.4-2.el6.x86_64.rpm和iksemel-devel-1.4-2.el6.x86_64.rpm
# rpm -ivh iksemel-1.4-2.el6.x86_64.rpm
# rpm -ivh iksemel-devel-1.4-2.el6.x86_64.rpm
报错 error: Failed dependencies:
gnutls-devel is needed by iksemel-devel-1.4-2.el6.x86_64
# yum install gnutls-devel
# rpm -ivh iksemel-devel-1.4-2.el6.x86_64.rpm
2.再次编译安装zabbix
# ./configure --prefix=/usr/local/zabbix --enable-server --with-mysql --with-net-snmp --with-jabber --with-libcurl --with-openipmi --enable-agent
报错checking for OPENIPMI support... no
configure: error: Invalid OPENIPMI directory - unable to find ipmiif.h
需要安装OpenIPMI和OpenIPMI-devel
Yum安装OpenIPMI并下载OpenIPMI-devel-2.0.16-14.el6.x86_64.rpm
# yum install OpenIPMI
# rpm -ivh OpenIPMI-devel-2.0.16-14.el6.x86_64.rpm
报错 error: Failed dependencies:
pkgconfig(ncurses) is needed by OpenIPMI-devel-2.0.16-14.el6.x86_64
# yum install ncurses-devel
# rpm -ivh OpenIPMI-devel-2.0.16-14.el6.x86_64.rpm
3.继续编译安装zabbix
# ./configure --prefix=/usr/local/zabbix --enable-server --with-mysql --with-net-snmp --with-jabber --with-libcurl --with-openipmi --enable-agent
***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* <http://www.zabbix.com> *
***********************************************************
依赖环境ok
# make && make install
拷贝zabbix web 文件到html目录下并改名
# cp -rf /root/zabbix-2.4.3/frontends/php /var/www/html/
# cd /var/www/html/ && mv php zabbix
# chown zabbix:zabbix /var/www/html/zabbix/
配置php相关参数
# vim /etc/php.ini
max_execution_time = 300
date.timezone = Asia/Shanghai
max_input_time = 600
启动apache
# service httpd start
配置zabbix server端
# vim /usr/local/zabbix/etc/zabbix_server.conf
DBHost=localhost ---数据库本机
DBName=zabbix ---数据库库名
DBUser=zabbix ---数据库账号
DBPassword=123 ---数据库密码
DBSocket=/var/lib/mysql/mysql.sock ---指定sock路径
ListenPort=10051 ---服务端监听端口
ListenIP=0.0.0.0 ---监听IP范围
启动服务
# cp /root/zabbix-2.4.3/misc/init.d/fedora/core/zabbix_server /etc/init.d/
# vim /etc/init.d/zabbix_server
BASEDIR=/usr/local/zabbix
# service zabbix_server start
查看启动端口
# lsof -i:10051
添加开机启动
# chkconfig --add zabbix_server
# chkconfig --level zabbix_server on
配置zabbix agent端
# vim /usr/local/zabbix/etc/zabbix_agentd.conf
Server=127.0.0.1 ---填写server端IP,server链接agent获取数据
ServerActive=127.0.0.1 ---填写server端IP,agent主动提交数据
Hostname=Zabbix server ---给agent设定一个名字,默认为Zabbix server
启动服务
#cp /root/zabbix-2.4.3/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
# vim /etc/init.d/zabbix_agentd
BASEDIR=/usr/local/zabbix
# service zabbix_agentd start
添加开机启动
# chkconfig --add zabbix_agentd
# chkconfig --level zabbix_agentd on
输入本机IP/zabbix地址进入web界面,点击next>>
http://192.168.1.238/zabbix
确认required全部ok,点击next>>
测试连接数据库ok,点击next>>
zabbix server信息,点击next>>
确认信息,点击next>>
点击下载配置文件,然后拷贝到提示目录下,点击retry,点击finish
登陆界面输入账号admin,密码zabbix进入
将zabbix-2.4.3.tar.gz拷贝到需要安装agent端的主机解压
# tar zxvf zabbix-2.4.3.tar.gz
编制安装agent端
# ./configure --prefix=/usr/local/zabbix --enable-agent
# make && make install
配置zabbix agent端
# vim /usr/local/zabbix/etc/zabbix_agentd.conf
Server=192.168.1.238 ---server端IP
ListenPort=10050 ---agent端端口
ServerActive=192.168.1.238 ---server端IP
Hostname=test237 ---定义agent端主机名字
启动服务
#cp /root/zabbix-2.4.3/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
# vim /etc/init.d/zabbix_agentd
BASEDIR=/usr/local/zabbix
# service zabbix_agentd start
查看启动端口添加开机启动
# lsof -i:10050
# chkconfig --add zabbix_agentd
# chkconfig --level zabbix_agentd on
zabbix server添加监控agent,点击configuration---host---create host
host name填写之前agent端配置文件设定的名字test237,groups选择
linux servers,IP地址填写agent端的IP 192.168.1.237,然后点击update
在templates项目选择添加template os linux模块,然后点击update
完成test237主机的监控,后续根据需求添加监控模块或自定义扩展