ZABBIX安装部署

本文详细介绍了Zabbix 2.4.6在CentOS上的安装过程,包括lamp环境配置、zabbix-server的安装、数据库创建与数据导入、zabbix-web的配置、zabbix-agent的配置以及对MySQL的监控和SNMP协议的使用。通过这个教程,读者可以学习如何全面部署和配置Zabbix监控系统。
摘要由CSDN通过智能技术生成

Zabbix安装部署

一、           lamp或lnmp环境

关闭selinux

(1)centos下直接yum安装:

yum install mysql-server httpd php –y

(2)开启httpd、mysqld并设置开机启动

Service httpd start

Service mysqld start

Chkconfig httpd on

Chkconfig mysqld on

二、安装zabbix-server

(1)安装所需依赖

yum install mysql-devel gcc net-snmp-develcurl-devel perl-DBI php-gd php-mysql php-bcmath php-mbstring php-xml –y

(2)创建zabbix运行账户

Groupadd zabbix

Useradd –g zabbix zabbix

(3)安装zabbix-server

解压:

         Tar–zxf zabbix-2.4.6.tar.gz

编译安装:

   ./configure--prefix=/usr/local/zabbix --enable-server --enable-agent --enable-proxy--with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl &&make && make install

三、zabbix-server的配置与启动

(1)创建zabbix数据库和mysql用户

Mysql> createdatabase zabbix character set utf8;

Mysql> grantall privileges on zabbix.* to zabbix@localhost identified by '4651919';

Mysql> flushprivileges;

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

进入到zabbix解压后的目录cd/usr/src/zabbix-2.4.6/database/mysql/

         Mysql–uroot –p4651919 zabbix < schema.sql

         Mysql–uroot –p4651919 zabbix < images.sql

 

         Mysql–uroot –p4651919 zabbix < data.sql

(3)编辑zabbix配置文件

         Vi/usr/local/zabbix/etc/zabbix-server.conf

ListenPort=10051                                                                                        #zabbixserver监听端口

LogFile =/usr/local/zabbix/logs/zabbix_server.log                            #日志路径

PidFile =/usr/local/zabbix/logs/zabbix_server.pid                             #pid所在路径

DBHost = localhost                                                                                     #数据库所在ip

DBName = zabbix                                                                                        #数据库名字,默认为zabbix

DBUser = root                                                                                              #数据用户,默认是zabbix

DBPassword = 4651919                                                                             #默认数据库密码

DBPort = 3306                                                                                              #默认数据库端口

DBSocket = /tmp/mysql.sock                                                                   #sock文件所在目录

(4)配置zabbix服务

从安装目录复制zabbix相关脚本

cp/root/zabbix-2.6.0/misc/init.d/fedora/core5/zabbix_* /etc/init.d

chmod +x /etc/init.d/zabbix_*

mkdir -p /usr/local/zabbix/logs

chown -R zabbix.zabbix /usr/local/zabbix/

vi /etc/init.d/zabbix_server

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

 

Vi /etc/services

Zabbix-agent 10050/tcp

Zabbix-agent 10050/udp

Zabbix-trapper 10051/tcp

Zabbix-trapper 10051/udp

(5)设置防火墙规则(开放10051端口)

Iptables –I INPUT –p tcp –dport 10051 –jACCEPT

Service iptables save

(6)启动zabbix_server

/etc/init.d/zabbix_server start

(7)停止zabbix_server

/etc/init.d/zabbix_server stop

(8)配置zabbix_server开机启动

Chkconfig –add zabbix_server

Chkconfig –level 35 zabbix_server on

四、配置zabbixweb

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

Cd /usr/src/zabbix-2.4.6

cp -a frontends/php/* /var/www/html

(2)apache配置

Vi /etc/httpd/conf/httpd.conf

ServerName 10.0.0.107:80

(3)php配置,将/etc/php.ini配置使用sed命令修改如下:

sed -i "s/;date.timezone=/date.timezone = "Asia\/Shanghai/g"" /etc/php.ini

sed -i "s#max_execution_time =30#max_execution_time = 300#g" /etc/php.ini

sed -i "s#post_max_size =8M#post_max_size = 32M#g" /etc/php.ini

sed -i "s#max_input_time =60#max_input_time = 300#g" /etc/php.ini

sed -i "/;mbstring.func_overload =0/ambstring.func_overload = 2\n" /etc/php.ini

(4)重启apache

/etc/init.d/httpd restart

(5)在浏览器输入10.0.0.107进行安装

五、配置zabbix_agentd.conf文件

Vi/usr/local/zabbix/etc/zabbix/zabbix_agentd.conf

Server=127.0.0.1,10.0.0.107#此处增加服务端ip

Server active=10.0.0.107#此处修改为服务端ip

六、zabbixagent端配置

(1)增加用户和组

Groupadd zabbix

Useradd –g zabbix zabbix

(2)解压和安装

Tar –zxf zabbix-2.4.6.tar.gz

./configure –prefix=/usr/local/zabbix –enable-agent&& make && make install

Cp misc/init.d/fedora/core5/zabbix_agentd/etc/init.d

(3)配置zabbixagent

Server = 10.0.0.107#服务端ip

Server active = 10.0.0.107#服务端ip

Hostname=text#主机名自己给,后面可以根据主机名发现主机

(4)配置zabbixagent系统服务启动脚本

Vi /etc/init.d/zabbix_agentd

ZABBIX_BIN=”/usr/local/zabbix/sbin/zabbix_agentd”

(5)开启防火墙端口

Iptables –I INPUT –p tcp ---dport 10050 –jACCEPT

/etc/init.d/iptables save

(6)启动zabbixagent

/etc/init.d/zabbix_agentd start

(7)配置开机启动

Chkconfig –add zabbix_agentd

Chkconfig –level 35 zabbix_agentd on

七、zabbix监控mysql

(1)进入脚本目录编写脚本

vim /usr/local/jiaoben/mysql.sh

脚本:

#!/bin/bash

 

MYSQL_USER='root'

 

MYSQL_PWD='4651919'

 

MYSQL_HOST='127.0.0.1'

 

MYSQL_PORT='3306'

 

MYSQL_CONN="/usr/bin/mysqladmin-u${MYSQL_USER} -p${MYSQL_PWD} -h${MYSQL_HOST} -P${MYSQL_PORT}"

 

if [ $# -ne "1" ];then

   echo "arg error!"

fi

 

case $1 in

   Uptime)

       result=`${MYSQL_CONN} status|cut -f2 -d":"|cut -f1-d"T"`

       echo $result

       ;;

   Com_update)

       result=`${MYSQL_CONN} extended-status |grep -w"Com_update"|cut -d"|" -f3`

       echo $result

       ;;

   Slow_queries)

       result=`${MYSQL_CONN} status |cut -f5 -d":"|cut -f1-d"O"`

       echo $result

       ;;

   Com_select)

       result=`${MYSQL_CONN} extended-status |grep -w"Com_select"|cut -d"|" -f3`

       echo $result

                ;;

   Com_rollback)

       result=`${MYSQL_CONN} extended-status |grep -w"Com_rollback"|cut -d"|" -f3`

                echo $result

                ;;

   Questions)

       result=`${MYSQL_CONN} status|cut -f4 -d":"|cut -f1-d"S"`

                echo $result

                ;;

   Com_insert)

       result=`${MYSQL_CONN} extended-status |grep -w"Com_insert"|cut -d"|" -f3`

                echo $result

                ;;

   Com_delete)

       result=`${MYSQL_CONN} extended-status |grep -w"Com_delete"|cut -d"|" -f3`

                echo $result

                ;;

   Com_commit)

       result=`${MYSQL_CONN} extended-status |grep -w"Com_commit"|cut -d"|" -f3`

                echo $result

                ;;

   Bytes_sent)

       result=`${MYSQL_CONN} extended-status |grep -w "Bytes_sent"|cut -d"|" -f3`

                echo $result

                ;;

   Bytes_received)

       result=`${MYSQL_CONN} extended-status |grep -w"Bytes_received" |cut -d"|" -f3`

                echo $result

                ;;

   Com_begin)

       result=`${MYSQL_CONN} extended-status |grep -w "Com_begin"|cut-d"|" -f3`

                echo $result

                ;;

                       

       *)

       echo"Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin)"

       ;;

Esac

保存脚本。

(2)修改zabbix_agentd.conf

增加自定义key,在最后一行增加如下:

 

UserParameter=mysql.version,mysql -V

UserParameter=mysql.status[*],/usr/local/jiaoben/mysql.sh$1

UserParameter=mysql.ping,mysqladmin -uroot-p4651919 -P3306 -h127.0.0.1  ping | grep-c alive

(3)重启agent

/etc/init.d/zabbix_agentd restart

然后在web端连接mysql模板后即可监控

八、通过snmp协议监控

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值