zabbix 网络监控 -- 服务端的配置

zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。

zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供柔软的通知机制以让系统管理员快速定位/解决存在的各种问题。

zabbix由2部分构成,zabbix server与可选组件zabbix agent。

zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux, Solaris, HP-UX, AIX, Free BSD, Open BSD, OS X等平台上。

zabbix agent需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集。zabbix agent可以运行在Linux ,Solaris, HP-UX, AIX, Free BSD, Open BSD, OS X, Tru64/OSF1, Windows NT4.0, Windows 2000/2003/XP/Vista)等系统之上。

zabbix server可以单独监视远程服务器的服务状态;同时也可以与zabbix agent配合,可以轮询zabbix agent主动接收监视数据(trapping方式),同时还可被动接收zabbix agent发送的数据(trapping方式)。另外zabbix server还支持SNMP (v1,v2),可以与SNMP软件(例如:net-snmp)等配合使用。

服务端安装zabbix_server,zabbix_agentd两个服务,客户端只需安装zabbix_agentd一个服务,监控原理其实就是zabbix_agentd服务将从系统中获取的相关数据传送给zabbix_server服务,然后zabbix_server服务将数据以PHP页面显示出来

zabbix的主要特点:   
- 安装与配置简单,学习成本低
- 支持多语言(包括中文)   
- 免费开源   
- 自动发现服务器与网络设备   
- 分布式监视以及WEB集中管理功能   
- 可以无agent监视   
- 用户安全认证和柔软的授权方式   
- 通过WEB界面设置或查看监视结果   
- email等通知功能等等   

Zabbix主要功能:    
- CPU负荷   
- 内存使用   
- 磁盘使用   
- 网络状况   
- 端口监视   
- 日志监视



zabbix服务端部署:


1.配置前先关闭iptables和SELINUX,避免安装过程中报错。


[root@localhost tw]# service iptables stop

iptables: Flushing firewall rules: [  OK  ]
iptables: Setting chains to policy ACCEPT: filter [  OK  ]
iptables: Unloading modules: [  OK  ]

[root@localhost tw]# chkconfig iptables off

[root@localhost tw]# getenforce
Disabled


2.安装LAMP环境

yum install -y httpd mysql mysql-server mysql-devel php php-mysql php-common php-mbstring php-gd php-odbc php-xml php-pear


3.下载zabbix-2.2.6.tar.gz

wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.2.6/zabbix-2.2.6.tar.gz


4.安装zabbix所需的组件(server,agent)

yum install -y curl curl-devel net-snmp net-snmp-devel perl-DBI


5.创建用户账号(server,agent)

[root@localhost tw]#useradd zabbix

[root@localhost tw]#usermod -s /sbin/nologin zabbix



6.创建zabbix数据库并导入zabbix数据库(server)

[root@localhost tw]#tar zxf zabbix-2.2.6.tar.gz

[root@localhost tw]#mysqladmin -u root password 123456
 (确认MySQL已启动,启动命令:/etc/rc.d/init.d/mysqld start(stop、status))

[root@localhost tw] mysql -p123456

下面为写入数据库的数据,手动写入:

mysql> create database zabbix;

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

mysql> use zabbix;

mysql> source /usr/zabbix-2.2.6/database/mysql/schema.sql(注意路径/usr)

mysql> source /usr/zabbix-2.2.6/database/mysql/images.sql

mysql> source /usr/zabbix-2.2.6/database/mysql/data.sql

mysql> exit


7.编译安装,如果是客户端安装选择--enable-agent就行了。

[root@localhost tw]#cd zabbix-2.2.6

[root@localhost zabbix-2.2.6]# ./configure --with-mysql --with-net-snmp --with-libcurl --enable-server --enable-agent --enable-proxy --

prefix=/usr/local/zabbix (安装路径可以修改,建议使用默认路径)


8.编辑配置文件

[root@localhost zabbix-2.2.6]#cd /usr/local/zabbix/etc

[root@localhost etc]# cp zabbix_server.conf zabbix_server.conf.bak

[root@localhost etc]# cp zabbix_agentd.conf  zabbix_agentd.conf.bak

[root@localhost etc]# vi zabbix_server.conf #服务端的配置
LogFile=/var/log/zabbix_server.log
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123456


[root@localhost etc]# vi  zabbix_agentd.conf #客户端配置(服务端不需要)
LogFile=/tmp/zabbix_agentd.log
Server=127.0.0.1
UnsafeUserParameters=1


[root@localhost etc]# touch /var/log/zabbix_server.log

[root@localhost etc]# touch /var/log/zabbix_agentd.log

[root@localhost etc]# chmod 777 /var/log/zabbix_*


9.启动服务(server,agent)

[root@localhost etc]cd /usr/zabbix-2.2.6

[root@localhost zabbix-2.2.6]# cp misc/init.d/tru64/zabbix_server  /etc/init.d/

[root@localhost zabbix-2.2.6]# cp misc/init.d/tru64/zabbix_agentd  /etc/init.d/

[root@localhost zabbix-2.2.6]# chmod +x /etc/init.d/zabbix_*     #添加服务

[root@localhost zabbix-2.2.6]# chkconfig --add zabbix_server

[root@localhost zabbix-2.2.6]# chkconfig --add zabbix_agentd     #设置服务器开机自动启动

注:执行chkconfig时如出现zabbix_server 服务不支持 chkconfig,编辑
zabbix_server和zabbix_agentd中开头添加以下内容即可

(vi /etc/init.d/zabbix_agentd    

   #chkconfig:345 61 61)


(vi /etc/init.d/zabbix_server   
   #chkconfig:345 61 61)


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

[root@localhost zabbix-2.2.6]# chkconfig zabbix_agentd on

[root@localhost zabbix-2.2.6]# service zabbix_server start

Zabbix server started.


(如果自定义安装目录在/usr/local/zabbix下,需要执行命令:
  1、 cd /usr/local/zabbix/sbin
  2、cp zabbix_server /usr/local/sbin/
  3、cp zabbix_agentd /usr/local/sbin/)


[root@localhost zabbix-2.2.6]# service zabbix_agentd start
Zabbix agent started.

[root@localhost zabbix-2.2.6]# ps -ef |grep zabbix


zabbix    1803     1  0 08:21 ?        00:00:00

/usr/local/sbin/zabbix_agentd
zabbix    1805  1803  0 08:21 ?        00:00:00

/usr/local/sbin/zabbix_agentd
zabbix    1806  1803  0 08:21 ?        00:00:00

/usr/local/sbin/zabbix_agentd
zabbix    1807  1803  0 08:21 ?        00:00:00

/usr/local/sbin/zabbix_agentd
zabbix    1808  1803  0 08:21 ?        00:00:00

/usr/local/sbin/zabbix_agentd
zabbix    1814     1  0 08:21 ?        00:00:00

/usr/local/sbin/zabbix_server
root      2043  2006  0 08:23 pts/0    00:00:00 grep zabbix


[root@localhost zabbix-2.2.6]# netstat -lantp |grep 10050
tcp        0      0 0.0.0.0:10050               0.0.0.0:*                 

  LISTEN      59118/zabbix_agentd

[root@localhost zabbix-2.2.6]#netstat -lantp |grep 10051

tcp        0      0 0.0.0.0:10051               0.0.0.0:*                 

  LISTEN      58931/./zabbix_serv

tcp        0      0 127.0.0.1:10051             127.0.0.1:56376           

  TIME_WAIT   -    




10.安装zabbix web界面(httpd)

复制php文件,zabbix的终端程序是用php写的,因此需要一个支持php脚本解析的web服务器。然后将frontends/php下面的php文件拷贝到web服务器html文件目录下面。

[root@localhost zabbix-2.2.6]#cp  -r   /usr/zabbix-2.2.6/frontends/php  /var/www/html/zabbix
(cp: 无法获取"frontends/php" 的文件状态(stat): 没有那个文件或目录----解决:找到rontends/php路径即可)

[root@localhost zabbix-2.2.6]#/etc/init.d/httpd restart            #启动apache服务


11.安装zabbix web界面(nginx)


1.安装php

yum install -y php php-mysql php-gd libjpeg* php-imap php-ldap php-odbc

php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash

libmcrypt libmcrypt-devel php-fpm php-pecl*

2.安装nginx

[root@localhost]#wget http://nginx.org/download/nginx-1.9.9.tar.gz

[root@localhost]#tar zxf nginx-1.9.9.tar.gz

[root@localhost]#cd nginx-1.9.9

[root@localhost nginx-1.9.9]#./configure --user=www --group=www --

prefix=/usr/local/nginx --with-http_stub_status_module --with-

http_ssl_module --error-log-path=/data/logs/nginx/error.log --http-log-

path=/data/logs/nginx/access.log

[root@localhost nginx-1.9.9]#make && make install

3.配置nginx参数(修改成下列内容支持PHP)

[root@localhost zabbix-2.0.6]#cp -r frontends/php

/usr/local/nginx/html/zabbix

[root@localhost zabbix-2.0.6]#vi /usr/local/nginx/conf/nginx.conf

    server {

        listen       88;

        server_name  127.0.0.1;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;


        location / {

            root   html/zabbix;

            index  index.php index.htm index.html;

        }


        #error_page  404              /404.html;


        # redirect server error pages to the static page /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }


        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass   http://127.0.0.1;

        #}


        # pass the PHP scripts to FastCGI server listening on

127.0.0.1:9000

        #

        location ~ \.php$ {

            root           html/zabbix;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  $document_root

$fastcgi_script_name;

            include        fastcgi_params;

        }

4.启动

[root@localhost zabbix-2.2.6]#chown -R /usr/local/nginx

[root@localhost zabbix-2.2.6]#/usr/local/nginx/sbin/nginx           //启

动nginx

[root@localhost zabbix-2.2.6]#/etc/init.d/php-fpm start          //启动

php


特别注释:httpd与Nginx只需要安装其中一种即可,请选择安装



11.修改PHP参数

[root@localhost zabbix-2.2.6]# vi  /etc/php.ini

[Date]

; Defines the default timezone used by the date functions
;

http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = Asia/Shanghai    #修改一下时区

[root@localhost zabbix-2.2.6]# /etc/init.d/httpd  restart

12、安装前端


在浏览器里输入192.168.35.135/zabbix出现zabbix安装界面点击next





(下一步出现PHP bacmath  no   Fail错误


解决:[root@localhost zabbix-2.2.6]#yum install -y php-bcmath     #安装php-bcmath即可






这种情况下,是缺少LAMP环境,安装即可:

yum install -y httpd mysql mysql-server mysql-devel php php-mysql php-common php-mbstring php-gd php-odbc php-xml php-pear


其他报错,根据提示修改/etc/php.ini文件里的参数即可,然后next,配置如下

Database type:MySQL

Database host:localhost

Database port:3306

Database name:zabbix

user         :zabbix

Password     :123456


post_max_size = 16M
max_execution_time = 300
max_input_time = 300


点击Test connection出现OK继续next,配置如下


测试连接时若报错,添加如下命令:
# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock









下载配置文件,并把他放置在/usr/local/apache2/htdocs/zabbix/conf/ 目录下,点击next即可用登录;

默认用户:Admin

默认密码:zabbix


出现界面,部署成功。

显示简体中文界面,点击:右上角Profile,选择Chinese(zh_CN),保存即可。







發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章