54432 发表于 2014-6-27 17:08:27

zabbix 安装和基础监控

Zabbix安装和监控
系统环境

# cat /etc/redhat-release

CentOSrelease 6.3 (Final)

#uname -a

Linux zabbix2.6.32-279.el6.x86_64 #1 SMP Fri Jun 22 12:19:21 UTC 2012 x86_64 x86_64 x86_64GNU/Linux


Yum安装nginx、php、mysql
配置nginx yum源,php和mysql默认就用centos的源

# vi /etc/yum.repos.d/nginx.repo   ###这个需要自己创建



name=nginxrepo

baseurl=http://nginx.org/packages/centos/$releasever/$basearch/

gpgcheck=0

enabled=1

wq###保存并退出


yum 安装lnmp环境

yum -yinstall gcc gcc-c++ mysql mysql-server yum -y install libjpeg* php-imapphp-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcryptphp-bcmath php-mhash libmcrypt libmcrypt-devel php-fpmphp-devel php-mysql php-mysqli php-pdo php-opcache php-gd nginx mysql mysql-server mysql-connector-odbc
设置mysql、php-fpm、nginx开机自启动以及启动

# chkconfig mysql on

# chkconfig php-fpm on

# chkconfig nginx on

# netstat –lnt         ###检查是否启动

ActiveInternet connections (only servers)

Proto Recv-QSend-Q Local Address            Foreign Address            State   

tcp      0   0 127.0.0.1:9000             0.0.0.0:*                   LISTEN   

tcp      0   0 0.0.0.0:3306               0.0.0.0:*                   LISTEN      

tcp      0   0 0.0.0.0:80               0.0.0.0:*                   LISTEN   
配置nginx支持php

1.修改/etc/php-fpm.d/www.conf的配置文件

sed -i's/user = apache/user = nginx/g' /etc/php-fpm.d/www.conf

sed -i's/group = apache/group = nginx/g' /etc/php-fpm.d/www.conf

sed -i's/;rlimit_files = 1024/rlimit_files = 51200/g' /etc/php-fpm.d/www.conf

sed -i's/^pm.max_children.*/pm.max_children = 300/g' /etc/php-fpm.d/www.conf

2.修改nginx的配置文件

# more /etc/nginx/conf.d/default.conf

server {

    listen      80;

    server_name 192.168.250.119 ;



    #charset koi8-r;

    #access_log /var/log/nginx/log/host.access.log main;



    location / {

      root/usr/share/nginx/html;

      index index.php index.html index.htm;

    }



    #error_page 404            /404.html;



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

    #

    error_page500 502 503 504/50x.html;

    location = /50x.html {

      root/usr/share/nginx/html;

    }



    # proxy the PHP scripts to Apache listeningon 127.0.0.1:80

    #

    #location ~ \.php$ {

    #   proxy_pass   http://127.0.0.1;

    #}



    # pass the PHP scripts to FastCGI serverlistening on 127.0.0.1:9000

#

========================配置支持php==============================

    location ~ \.php$ {

      root         html;

      fastcgi_pass   127.0.0.1:9000;

      fastcgi_indexindex.php;

      fastcgi_paramSCRIPT_FILENAME/usr/share/nginx/html $fastcgi_script_name;

      include      fastcgi_params;

    }



    # deny access to .htaccess files, ifApache's document root

    # concurs with nginx's one

    #

    #location ~ /\.ht {

    #   denyall;

    #}

}

3.给站点目录授权

chown -Rnginx:nginx /usr/share/nginx/html/
重新加载nginx和重启php-fpm

# /etc/init.d/nginx reload

重新载入 nginx:                                           [确定]

# /etc/init.d/php-fpm restart

停止 php-fpm:                                             [确定]

正在启动 php-fpm:                                       [确定]
站点目录下创建php的测试页面

# more /usr/share/nginx/html/test.php   

<?php

phpinfo();

?>
浏览器访问一下是否支持php,看下图已经可以了

spacer.gif


安装zabbix
安装zabbix的yum源以及yum安装zabbix server和agent

#rpm -ivh http://repo.zabbix.com/zabbix/2.2/rhel/6/x86_64/zabbix-release-2.2-1.el6.noarch.rpm

yum–yinstall zabbix-server-mysql zabbix-web-mysql zabbix-agent zabbix-get
创建数据库并授权用户和设置密码

mysql>createdatabase zabbix character set utf8;

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

mysql>flushprivileges;
导入zabbix数据库

cd /usr/share/doc/ zabbix-server-mysql-2.2.0/create
# mysql -uroot zabbix < schema.sql###我这个数据库没密码,数据库有密码还需要写上密码
# mysql -uroot zabbix < images.sql
# mysql -uroot zabbix < data.sql
配置php安装文件

1.需要下载源码包,因为yum安装的包里面没有zabbix php的站点目录

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

# tar zxvf zabbix-2.2.3.tar.gz

# cd zabbix-2.2.3

3.复制php文件到站点目录下

[root@zabbixzabbix-2.2.3]# cp -r frontends/php/*/usr/share/nginx/html/
修改php.ini   (注意,这里必须修改,不然后面安装会提示环境不符)

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"s#memory_limit = 128M#memory_limit = 128M#g" /etc/php.ini

sed -i"/;mbstring.func_overload = 0/ambstring.func_overload = 2\n"/etc/php.ini
配置zabbix_server.conf 服务端文件

DBName=zabbix数据库名称

DBUser=zabbix数据库用户

DBPassword=zabbix数据库密码

sed -i"s/DBUser\=root/DBUser\=zabbix/g" /etc/zabbix/zabbix_server.conf

sed -i"/# DBPassword=/aDBPassword=zabbix\n" /etc/zabbix/zabbix_server.conf

sed -i"s#tmp/zabbix_server.log#var/log/zabbix/zabbix_server.log#g" /etc/zabbix/zabbix_server.conf
通过 web 页面配置 zabbix

在浏览器输入http://192.168.250.119/zabbix

spacer.gif

spacer.gif

spacer.gif

数据库 ip 为 localhost

端口为 3306

数据库名 zabbix

用户为 zabbix

密码为 zabbix

点击 test connection,如果没有问题,则会提示 OK,否则,需要检查数据库授权是否正确

spacer.gif

spacer.gif

spacer.gif

如果 此 处 提 示 文 件 zabbix.conf.php 无 法 创 建 ,有可能是nginx站点目录没有写入权限。



默认账户admin,密码zabbix

spacer.gif

到此为止server端已经全部安装完毕。


Zabbix安装客户端
之前安装server段的时候也把客户端安装上了,如下是命令

[root@zabbixzabbix-2.2.3]# yum -y installzabbix-agent
如下:abbix_agentd配置文件

# grep -v "#" /etc/zabbix/zabbix_agentd.conf|grep -v "^$"

PidFile=/var/run/zabbix/zabbix_agentd.pid

LogFile=/var/log/zabbix/zabbix_agentd.log

LogFileSize=0

Server=192.168.250.119                     #允许哪些 ip 访问本机

ServerActive=192.168.250.119                #被动监控,服务端的 ip

Hostname=192.168.250.119               #客户端的主机名

Include=/etc/zabbix/zabbix_agentd.d/          #配置文件
启动zabbix-agent并设置为开机自启动

# /etc/init.d/zabbix-agent start

StartingZabbix agent:                                     [确定]

# chkconfig zabbix-agent on



简单监控一台主机

spacer.gif

创建主机

spacer.gif



选择第一种方式来进行监控,也可以用snmp的方式去监控

spacer.gif



使用模版来进行监控,设置完成后点存档。

spacer.gif



等1分钟左右,server就能检测到了。

spacer.gif



简单的安装和监控就全部结束了。

没有域名写成自己服务器的地址即可

添加index.php

我这边变量有问题,我就直接写上绝对路径,写上nginx的站点目录

使用yum安装会把包下载到这个目录下



页: [1]
查看完整版本: zabbix 安装和基础监控