部署zabbix监控mysql

1)安装LAMP环境

[root@localhost ~]# yum -y installmysql-server http php

2)安装zabbix web所需要的依赖包

[root@localhost ~]# yum -y installmysql-dev gcc net-snmp-devel curl-devel perl-DBI php-gd php-mysql php-bcmathphp-mbstring php-xml

安装Fping

[root@localhost zabbix]# wget http://www.fping.org/dist/fping-3.13.tar.gz

[root@localhost zabbix]# tar xffping-3.13.tar.gz

[root@localhost zabbix]# cd fping-3.13

[root@localhost fping-3.13]# ./configure

[root@localhost fping-3.13]# make&& make install

3)创建Zabbix运行的用户

[root@localhost fping-3.13]# groupaddzabbix

[root@localhost fping-3.13]# useradd -gzabbix zabbix

[root@localhost fping-3.13]# chownroot:zabbix /usr/local/sbin/fping

[root@localhost fping-3.13]# chmod 4710/usr/local/sbin/fping

4)安装zabbix server

[root@localhost zabbix]# wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.2/zabbix-3.0.2.tar.gz

[root@localhost zabbix]# tar xfzabbix-3.0.2.tar.gz

[root@localhost zabbix]# cd zabbix-3.0.2

[root@localhost zabbix-3.0.2]# ./configure--prefix=/usr/local/zabbix --enable-server --enable-agent --enable-proxy--with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl

[root@localhost zabbix-3.0.2]# make

[root@localhost zabbix-3.0.2]# make install

 

Zabbix server 配置与启动

1)创建Zabbix数据库和Mysql用户

mysql> create schema zabbix characterset utf8;

Query OK, 1 row affected (0.00 sec)

 

mysql> create user"zabbix"@"%" identified by "123456";

Query OK, 0 rows affected (0.00 sec)

 

mysql> grant all on zabbix.* to"zabbix"@"%";

Query OK, 0 rows affected (0.00 sec)

 

mysql> grant all on zabbix.* to"zabbix"@localhost identified by "123456";

 

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

 

2)导入zabbix数据库初始数据

[root@localhost zabbix-3.0.2]# cddatabase/mysql/

[root@localhost mysql]# ll

总用量 3012

-rw-r--r-- 1 1000 1000  990351 4  20 18:01 data.sql

-rw-r--r-- 1 1000 1000 1978341 4  20 17:51 images.sql

-rw-r--r-- 1 1000 1000  113197 4  20 18:01 schema.sql

[root@localhost mysql]#

[root@localhost mysql]# mysql -u zabbix -p zabbix  <schema.sql

[root@localhost mysql]# mysql -u zabbix -p zabbix  <images.sql

[root@localhost mysql]# mysql -u zabbix -p zabbix  <data.sql

 

3)配置zabbix配置文件

编辑zabbix server 的配置文件,修改以下参数:

[root@localhost mysql]# vim/usr/local/zabbix/etc/zabbix_server.conf

[root@localhost ~]# cat  /usr/local/zabbix/etc/zabbix_server.conf |egrep -v "^#|^$"

ListenPort=10051

LogFile=/usr/local/zabbix/logs/zabbix_server.log

PidFile=/usr/local/zabbix/logs/zabbix_server.pid

DBHost=127.0.0.1

DBName=zabbix

DBUser=zabbix

        DBPassword=123456

        DBSocket=/var/lib/mysql/mysql.sock

        DBPort=3306

Timeout=4

        FpingLocation=/usr/local/sbin/fping

LogSlowQueries=3000

[root@localhost ~]#

 

4)配置zabbix服务

从安装目录复制zabbix_server脚本并编辑

[root@localhost ~]# cd zabbix/zabbix-3.0.2

[root@localhost zabbix-3.0.2]# cpmisc/init.d/fedora/core5/zabbix_server /etc/init.d/

[root@localhost zabbix-3.0.2]# mkdir/usr/local/zabbix/logs

[root@localhost zabbix-3.0.2]# chown -Rzabbix.zabbix /usr/local/zabbix

[root@localhost zabbix-3.0.2]# vim/etc/init.d/zabbix_server

[root@localhost zabbix-3.0.2]# cat  /etc/init.d/zabbix_server

ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_server"

CONF_FILE="/usr/local/zabbix/etc/zabbix_server.conf"

 

5)开启zabbix安全限制

调整防火墙规则(开放端口10051):

[root@localhost zabbix]# iptables -A INPUT-p tcp -m tcp --dport 10051 -j ACCEPT

[root@localhost zabbix]# service iptablessave

iptables:将防火墙规则保存到/etc/sysconfig/iptables     [确定]

6)启动zabbix server

[root@localhost zabbix]# servicezabbix_server start

正在启动 Zabbix Server                                  [确定]

[root@localhost zabbix]#

7)关闭zabbix server

[root@localhost zabbix]# servicezabbix_server stop

停止 Zabbix Server                                       [确定]

[root@localhost zabbix]#

8)配置zabbix server开机自启动:

[root@localhost zabbix]# chkconfig --addzabbix_server       

[root@localhost zabbix]# chkconfig --level35 zabbix_server  on 

[root@localhost zabbix]#

 

配置zabbix Web服务端

(1)      zabbix web 文件复制到Apache web 目录中

在安装目录将frontends复制到指定的web root 目录下:

[root@localhost zabbix]# cd zabbix-3.0.2

[root@localhost zabbix-3.0.2]# cp -rafrontends/php/*  /var/www/html/

 

(2)      Apache的配置

[root@localhost ~]# vim/etc/httpd/conf/httpd.conf

         ServerName192.168.1.214:80

 

(3)      PHP配置

[root@localhost ~]# vim /etc/php.ini

         date.timezone= Asia/Shanghai

         memory_limit= 128M

         post_max_size= 16M

         max_execution_time= 300

         max_input_time= 300

         session.auto_start= 0

         mbstring.func_overload= 1

PHP string function overloading must be disabled. PHP字符串函数重载必须禁用。)

 

(4)      zabbix web 安装

[root@localhost ~]# /etc/init.d/httpdrestart

停止 httpd                                              [确定]

正在启动 httpd                                           [确定]

[root@localhost ~]#

# wget http://iweb.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.4.8/zabbix-2.4.8.tar.gz

安装zabbix-3.0.2.tar.gz web端有问题报错“PHP Parseerror:  syntax error, unexpected '[' in/var/www/html/index.php on line 29  从新下载zabbix-2.4.8.tar.gzweb端拷贝到网站根目录下。

欢迎界面:

wKioL1cwUm3xiHs8AAIPVE_Vumk860.png

PHP字符串函数重载必须禁用

wKioL1cwUojyCTUPAAHw--L9ze4850.png

[root@localhost ~]# vim /etc/php.ini 

         mbstring.func_overload= 1

[root@localhost ~]# /etc/init.d/httpdrestart     

停止 httpd                                              [确定]

正在启动 httpd                                           [确定]

[root@localhost ~]#

重新检查:

wKiom1cwUczS4U6TAAGVPRmRyJ8399.png

填写数据库信息:

wKiom1cwUd-zhGfUAAGDe4yUaSU154.png

出现错误:

[问题原因] Zabbix数据库版本不对(因为导入的是Zabbix-3.2中的sql)

确认后重新导入一下Zabbix数据库的sql 这里先不导入,再把3.0.2web在拷贝到web 根目录下,修改刚才报错的index.php,如果不可以在重新导入。

实验了下不行还得重新导入数据的。要替换的文件太多。

wKioL1cwUtHgzJxhAAGl2hImhsA795.png

[root@localhost zabbix]# cd zabbix-2.4.8

[root@localhost zabbix-2.4.8]# cddatabase/mysql/

[root@localhost mysql]# ls

data.sql images.sql  schema.sql

[root@localhost mysql]# mysql  -uzabbix -p123456 zabbix < schema.sql

[root@localhost mysql]# mysql  -uzabbix -p123456 zabbix < images.sql

[root@localhost mysql]# mysql  -uzabbix -p123456 zabbix < data.sql

[root@localhost mysql]#

wKiom1cwUhPAFtKIAAGfK72wQ0I996.png

wKiom1cwUhTCmVajAAErIYGeoc8394.png

wKiom1cwUhaj_Ev4AAGBZIVTaRQ960.png



手动复制zabbix.conf.php/var/www/html/zabbix/conf即可

[root@localhost html]# cpconf/zabbix.conf.php.example conf/zabbix.conf.php

zabbix.conf.php 文件格式内容如下:



wKioL1cwUyWAJbv3AABZzgIsfxc841.png

wKioL1cwUyeiL-JAAAGAr8isXJE959.png