部署zabbix监控mysql
(1)安装LAMP环境
[[email protected] ~]# yum -y installmysql-server http php
(2)安装zabbix web所需要的依赖包
[[email protected] ~]# yum -y installmysql-dev gcc net-snmp-devel curl-devel perl-DBI php-gd php-mysql php-bcmathphp-mbstring php-xml
安装Fping:
[[email protected] zabbix]# wget http://www.fping.org/dist/fping-3.13.tar.gz
[[email protected] zabbix]# tar xffping-3.13.tar.gz
[[email protected] zabbix]# cd fping-3.13
[[email protected] fping-3.13]# ./configure
[[email protected] fping-3.13]# make&& make install
(3)创建Zabbix运行的用户
[[email protected] fping-3.13]# groupaddzabbix
[[email protected] fping-3.13]# useradd -gzabbix zabbix
[[email protected] fping-3.13]# chownroot:zabbix /usr/local/sbin/fping
[[email protected] fping-3.13]# chmod 4710/usr/local/sbin/fping
(4)安装zabbix server:
[[email protected] zabbix]# wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.2/zabbix-3.0.2.tar.gz
[[email protected] zabbix]# tar xfzabbix-3.0.2.tar.gz
[[email protected] zabbix]# cd zabbix-3.0.2
[[email protected] 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
[[email protected] zabbix-3.0.2]# make
[[email protected] 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数据库初始数据
[[email protected] zabbix-3.0.2]# cddatabase/mysql/
[[email protected] 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
[[email protected] mysql]#
[[email protected] mysql]# mysql zabbix <schema.sql
[[email protected] mysql]# mysql zabbix <images.sql
[[email protected] mysql]# mysql zabbix <data.sql
(3)配置zabbix配置文件
编辑zabbix server 的配置文件,修改以下参数:
[[email protected] mysql]# vim/usr/local/zabbix/etc/zabbix_server.conf
[[email protected] ~]# 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
[[email protected] ~]#
(4)配置zabbix服务
从安装目录复制zabbix_server脚本并编辑
[[email protected] ~]# cd zabbix/zabbix-3.0.2
[[email protected] zabbix-3.0.2]# cpmisc/init.d/fedora/core5/zabbix_server /etc/init.d/
[[email protected] zabbix-3.0.2]# mkdir/usr/local/zabbix/logs
[[email protected] zabbix-3.0.2]# chown -Rzabbix.zabbix /usr/local/zabbix
[[email protected] zabbix-3.0.2]# vim/etc/init.d/zabbix_server
[[email protected] 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):
[[email protected] zabbix]# iptables -A INPUT-p tcp -m tcp --dport 10051 -j ACCEPT
[[email protected] zabbix]# service iptablessave
iptables:将防火墙规则保存到/etc/sysconfig/iptables: [确定]
(6)启动zabbix server
[[email protected] zabbix]# servicezabbix_server start
正在启动 Zabbix Server: [确定]
[[email protected] zabbix]#
(7)关闭zabbix server
[[email protected] zabbix]# servicezabbix_server stop
停止 Zabbix Server: [确定]
[[email protected] zabbix]#
(8)配置zabbix server开机自启动:
[[email protected] zabbix]# chkconfig --addzabbix_server
[[email protected] zabbix]# chkconfig --level35 zabbix_server on
[[email protected] zabbix]#
配置zabbix Web服务端
(1) 将zabbix web 文件复制到Apache web 目录中
在安装目录将frontends复制到指定的web root 目录下:
[[email protected] zabbix]# cd zabbix-3.0.2
[[email protected] zabbix-3.0.2]# cp -rafrontends/php/* /var/www/html/
(2) Apache的配置
[[email protected] ~]# vim/etc/httpd/conf/httpd.conf
ServerName192.168.1.214:80
(3) PHP配置
[[email protected] ~]# 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 安装
[[email protected] ~]# /etc/init.d/httpdrestart
停止 httpd: [确定]
正在启动 httpd: [确定]
[[email protected] ~]#
# 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.gz把web端拷贝到网站根目录下。
欢迎界面:
PHP字符串函数重载必须禁用
[[email protected] ~]# vim /etc/php.ini
mbstring.func_overload= 1
[[email protected] ~]# /etc/init.d/httpdrestart
停止 httpd: [确定]
正在启动 httpd: [确定]
[[email protected] ~]#
重新检查:
填写数据库信息:
出现错误:
[问题原因] Zabbix的数据库版本不对(因为导入的是Zabbix-3.2中的sql)
确认后重新导入一下Zabbix数据库的sql 这里先不导入,再把3.0.2的web在拷贝到web 根目录下,修改刚才报错的index.php,如果不可以在重新导入。
实验了下不行还得重新导入数据的。要替换的文件太多。
[[email protected] zabbix]# cd zabbix-2.4.8
[[email protected] zabbix-2.4.8]# cddatabase/mysql/
[[email protected] mysql]# ls
data.sql images.sql schema.sql
[[email protected] mysql]# mysql -uzabbix -p123456 zabbix < schema.sql
[[email protected] mysql]# mysql -uzabbix -p123456 zabbix < images.sql
[[email protected] mysql]# mysql -uzabbix -p123456 zabbix < data.sql
[[email protected] mysql]#
手动复制zabbix.conf.php到/var/www/html/zabbix/conf即可
[[email protected] html]# cpconf/zabbix.conf.php.example conf/zabbix.conf.php
zabbix.conf.php 文件格式内容如下: