公司的监控系统是单纯用nagios+nrpe实现的,并不支持分布式。现在公司需要实现监控系统改造,由于nagios分布式在搭建和配置等诸多方面都比较繁杂,在此通过文档等了解到zabbix的诸多好的功能和特性,所以决定用zabbix来实现分布式。不多说,先看看zabbix server端和zabbix agent端的安装与配置、监控的基本实现。
一、服务端安装(版本是2.2.5)
1.确保编译环境
# yum -y install make gcc gcc-c++
2.安装和配置LAMP(yum或者源码包安装)
# yum -y install httpd mysql mysql-server mysql-devel php php-gd php-xml php-mysql php-mbstring php-bcmath perl-DBI curl libcurl-devel net-snmp net-snmp-devel libssh2 libssh2-devel # vim /etc/httpd/conf/httpd.conf #添加 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps #在DirectoryIndex中添加index.php <IfModule dir_module> DirectoryIndex index.php index.html </IfModule> # service httpd restart
3.下载zabbix安装包
# mkdir -pv pkgs/builds # pkgs为安装包存放目录,builds为安装包解压后存放的目录 # cd pkgs/ # wget http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/2.2.5/zabbix-2.2.5.tar.gz/download # tar xf zabbix-2.2.5.tar.gz -C builds/
4.添加zabbix用户
# useradd zabbix # echo "zabbix" | passwd --stdin zabbix
5.创建数据库(使用mysql数据库)、用户与导入表
mysql> create database zabbix character set utf8; mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix'; mysql> grant all privileges on zabbix.* to zabbix@'%' identified by 'zabbix'; mysql> flush privileges; # mysql -uzabbix -pzabbix -hlocalhost zabbix < database/mysql/schema.sql # mysql -uzabbix -pzabbix -hlocalhost zabbix < database/mysql/p_w_picpaths.sql # mysql -uzabbix -pzabbix -hlocalhost zabbix < database/mysql/data.sql
6.编译安装zabbix
# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-ssh2 # make install
7.创建和修改服务启动脚本文件
# cp misc/init.d/fedora/core/zabbix_server /etc/init.d/ # cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/ # sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_server # sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_agentd
8.修改zabbix配置文件
# sed -i 's/^DBUser=.*$/DBUser=zabbix/g' /usr/local/zabbix/etc/zabbix_server.conf # sed -i 's/^.*DBPassword=.*$/DBPassword=zabbix/g' /usr/local/zabbix/etc/zabbix_server.conf
9.配置php
# vim /etc/php.ini max_input_time = 600 max_execution_time = 300 date.timezone = Asia/Shanghai post_max_size = 32M memory_limit = 128M mbstring.func_overload = 2
10.添加服务端口
cat >>/etc/services <<EOF zabbix-agent 10050/tcp Zabbix Agent zabbix-agent 10050/udp Zabbix Agent zabbix-trapper 10051/tcp Zabbix Trapper zabbix-trapper 10051/udp Zabbix Trapper EOF
11.复制web interface到www目录下面
# cp -R /root/pkgs/builds/zabbix-2.2.5/frontends/php /var/www/html/zabbix
12.配置随机启动
# chkconfig --add zabbix_server # chkconfig zabbix_server on
13.启动zabbix server服务
# service zabbix_server start
确认好web服务器配置并开启,就输入http://ip/zabbix来进行web的安装
二、web页面配置
1.查看那个配置项不符合就解决,然后下一步
2.输入数据库连接信息
3.输入zabbix server信息(可不填)
4.之前操作的汇总呈现
5.先下载这个文件,然后在传到服务器里,给予执行权限;之后点retry
6.没有问题就可以选择finish,会跳出登陆页面,默认账号为admin,密码zabbix
7.登陆后的页面呈现
三、zabbix agent安装、配置、基本监控实现
1.添加zabbix用户
# groupadd zabbix # useradd -g zabbix zabbix
2.确保编译环境
# yum -y install make gcc gcc-c++
3.安装所需要的依赖包
# yum -y install curl curl-devel net-snmp net-snmp-devel libssh2 libssh2-devel
4.zabbix agent安装
# ./configure --prefix=/usr/local/zabbix --enable-agent --with-net-snmp --with-libcurl --with-ssh2 # make install
5.创建和修改配置启动脚本
# cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/ # sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_agentd
6.配置zabbix_agentd.conf文件
Server=192.168.244.133 #该ip为zabbix_server的IP ServerActive=192.168.244.133 #该ip为zabbix_server的IP Hostname=192.168.244.136 #hostname可以为字符串,但是要保证zabbix_server能够解析
7.添加服务端口
cat >>/etc/services <<EOF zabbix-agent 10050/tcp Zabbix Agent zabbix-agent 10050/udp Zabbix Agent zabbix-trapper 10051/tcp Zabbix Trapper zabbix-trapper 10051/udp Zabbix Trapper EOF
8.配置随机启动
# chkconfig --add zabbix_agentd # chkconfig zabbix_agentd on
9.启动zabbix agent进程
# service zabbix_agentd start Starting zabbix_agentd: [ OK ] # netstat -nltp | grep zabbix tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 1953/zabbix_agentd
8.在zabbix server的web页面中添加被监控主机
Configuration --> Host --> Create host --> 填写主机信息 --> save
9.添加监控项目,这里用监控主机网卡流量做为示例
10.保存以后等待几分钟,然后在Monitoring --> Latest data --> host中查看刚才添加的监控服务变化情况走势图
以上就是zabbix server和zabbix agent安装、配置、监控的基本实现了,刚开始学习zabbix的朋友快去试一试吧~
转载于:https://blog.51cto.com/gzguitar/1542176