wtuyss 发表于 2019-1-25 09:29:18

运维监控平台之zabbix详解1

  

  本来是想一篇文章介绍完的,写着写着发现篇幅太长,所以决定还是分两篇来介绍,本次软件所用的版本信息如下(基于LNMP环境),操作系统centos6.7
  nginx-1.6.3.tar.gz
  php-5.6.24.tar.gz
  mysql-5.5.49-linux2.6-x86_64.tar.gz
  zabbix-3.0.4.tar.gz (zabbix-3以上版本之支持php5.4以上环境)
  

  LNMP环境搭建不再这里说明了,如果不懂的看本人之前写的nginx+php,这里简单介绍下php编译
# wgethttp://cn2.php.net/distributions/php-5.6.24.tar.gz
# tar xf php-5.6.24.tar.gz
# cd php-5.6.24
# ./configure \
> --prefix=/application/php5.6.24 \
> --with-mysql=/application/mysql \
>--with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd
> --with-iconv-dir=/usr/local/libiconv \
> --with-freetype-dir \
> --with-jpeg-dir \
> --with-png-dir \
> --with-zlib \
> --with-libxml-dir=/usr \
> --enable-xml \
> --disable-rpath \
> --enable-safe-mode \
> --enable-bcmath \
> --enable-shmop \
> --enable-sysvsem \
> --enable-inline-optimization \
> --with-curl \
> --with-curlwrappers \
> --enable-mbregex \
> --enable-fpm \
> --enable-mbstring \
> --with-mcrypt \
> --with-gd \
> --enable-gd-native-ttf \
> --with-openssl \
> --with-mhash \
> --enable-pcntl \
> --enable-sockets \
> --with-xmlrpc \
> --enable-zip \
> --enable-soap \
> --enable-short-tags \
> --enable-zend-multibyte \
> --enable-static \
> --with-xsl \
> --with-fpm-user=nginx \
> --with-fpm-group=nginx \
> --enable-ftp
>--with-gettext
Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:                                                         |
| This software is subject to the PHP License, available in this   |
| distribution in the file LICENSE.By continuing this installation |
| process, you are bound by the terms of this license agreement.   |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+
Thank you for using PHP.
config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
configure: WARNING: unrecognized options: --enable-safe-mode, --with-curlwrappers, --enable-zend-multibyte  

  编译过程截图如下
http://s3.运维网.com/wyfs02/M02/85/F7/wKiom1exMFzzAjH-AACk7OPZjuk643.png
# ln -s /application/mysql/lib/libmysqlclient.so.18/usr/lib64/
# touch ext/phar/phar.phar
# make && make install
Build complete.
Don't forget to run 'make test'.
Installing shared extensions:   /application/php5.6.24/lib/php/extensions/no-debug-non-zts-20131226/
Installing PHP CLI binary:      /application/php5.6.24/bin/
Installing PHP CLI man page:      /application/php5.6.24/php/man/man1/
Installing PHP FPM binary:      /application/php5.6.24/sbin/
Installing PHP FPM config:      /application/php5.6.24/etc/
Installing PHP FPM man page:      /application/php5.6.24/php/man/man8/
Installing PHP FPM status page:   /application/php5.6.24/php/php/fpm/
Installing PHP CGI binary:      /application/php5.6.24/bin/
Installing PHP CGI man page:      /application/php5.6.24/php/man/man1/
Installing build environment:   /application/php5.6.24/lib/php/build/
Installing header files:         /application/php5.6.24/include/php/
Installing helper programs:       /application/php5.6.24/bin/
program: phpize
program: php-config
Installing man pages:             /application/php5.6.24/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment:      /application/php5.6.24/lib/php/
Archive_Tar    - installed: 1.4.0
Console_Getopt - installed: 1.4.1
Structures_Graph- installed: 1.1.1
XML_Util       - installed: 1.3.0
PEAR         - installed: 1.10.1
Wrote PEAR system config file at: /application/php5.6.24/etc/pear.conf
You may want to add: /application/php5.6.24/lib/php to your php.ini include_path
/tools/php-5.6.24/build/shtool install -c ext/phar/phar.phar /application/php5.6.24/bin
ln -s -f phar.phar /application/php5.6.24/bin/phar
Installing PDO headers:         /application/php5.6.24/include/php/ext/pdo/  

http://s3.运维网.com/wyfs02/M00/85/F7/wKioL1exNY3SevdMAADiHhgb3-U268.png
# ln -s /application/php5.6.24/ /application/php
# cp php.ini-production /application/php/lib/php.ini
# cd /application/php/etc/
# cp php-fpm.conf.default php-fpm.conf
# cat php-fpm.conf


user = nginx
group = nginx
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
# /application/php/sbin/php-fpm
nginx配置如下
# cat /application/nginx/conf/nginx.conf
worker_processes2;
events {
    worker_connections1024;
}
http {
log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    include       mime.types;
    default_typeapplication/octet-stream;
    sendfile      on;
    keepalive_timeout65;
    server {
      listen       80;
      server_namewww.martin.com martin.com;
      location / {
            root   html/www;
            indexindex.php index.html index.htm;
      }
         
      location ~ .*\.(php|php5)?$ {
            roothtml/www;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
               }
         access_loglogs/access_www.logmain;      
   }
    server {
      listen       80;
      server_namebbs.martin.com;
      location / {
            root   html/bbs;
            indexindex.php index.html index.htm;
      }
            
      location ~ .*\.(php|php5)?$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
               }
         access_loglogs/access_bbs.logmain;      
    }
###status
   server{
      listen 80;
      server_name status.martin.org;
      location / {
      stub_status on;
      access_log off;
      }
   }
}  

  

  浏览器访问测试    (www.martin.com---172.16.80.117)

http://s5.运维网.com/wyfs02/M01/85/F7/wKioL1exN3OCKthKAAF0c9xhEj8606.png
  

  

  至此整个LNMP环境准备完成,zabbix(在LNMP环境下)选择源码编译安装
  

  curl 7.19.7系统默认版本,升级该软件版本,否则后面邮件功能会有问题
# rpm -Uvh http://www.city-fan.org/ftp/contrib/yum-repo/rhel6/x86_64/city-fan.org-release-1-13.rhel6.noarch.rpm
Retrieving http://www.city-fan.org/ftp/contrib/yum-repo/rhel6/x86_64/city-fan.org-release-1-13.rhel6.noarch.rpm
warning: /var/tmp/rpm-tmp.jSwm5A: Header V3 DSA/SHA1 Signature, key ID b56a8bac: NOKEY
Preparing...                ###########################################
   1:city-fan.org-release   ###########################################
#yum install libcurl -y
# curl -V   再次查看版本
curl 7.50.1 (x86_64-redhat-linux-gnu) libcurl/7.50.1 OpenSSL/1.0.1e zlib/1.2.3 c-ares/1.11.0 libidn/1.18 libssh2/1.7.0 nghttp2/1.6.0
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz HTTP2 UnixSockets Metalink
安装zabbix依赖包
#yum -y install mysql-devel libxml2-devel net-snmp-devel libcurl-devel   
# wget http://ncu.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.4/zabbix-3.0.4.tar.gz
# tar xf zabbix-3.0.4.tar.gz
# cd zabbix-3.0.4
#./configure --prefix=/application/zabbix-server --enable-server --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --enable-agent --enable-proxy
Enable server:         yes
Server details:
    With database:         MySQL
    WEB Monitoring:      cURL
    Native Jabber:         no
    SNMP:                  yes
    IPMI:                  no
    SSH:                   no
    TLS:                   no
    ODBC:                  no
    Linker flags:             -L/usr/lib64/mysql      -L/usr/lib64      -rdynamic
    Libraries:               -lmysqlclient      -lxml2    -lnetsnmp      -lcurl -lm -ldl -lrt-lresolv
Enable proxy:          yes
Proxy details:
    With database:         MySQL
    WEB Monitoring:      cURL
    SNMP:                  yes
    IPMI:                  no
    SSH:                   no
    TLS:                   no
    ODBC:                  no
    Linker flags:             -L/usr/lib64/mysql       -L/usr/lib64      -rdynamic
    Libraries:               -lmysqlclient   -lxml2    -lnetsnmp      -lcurl -lm -ldl -lrt-lresolv
Enable agent:          yes
Agent details:
    TLS:                   no
    Linker flags:            -rdynamic
    Libraries:               -lcurl -lm -ldl -lrt-lresolv
Enable Java gateway:   no
LDAP support:          no
IPv6 support:          no
***********************************************************
*            Now run 'make install'                     *
*                                                         *
*            Thank you for using Zabbix!                  *
*                                  *
***********************************************************  

http://s1.运维网.com/wyfs02/M00/85/F8/wKiom1exOt6zMV8jAACF4_c-jNM910.png
  

  # make install
  

http://s4.运维网.com/wyfs02/M02/85/F8/wKiom1exO0nRYIwfAADVL0k25Ag946.png
由于zabbix启动脚本路径默认指向的是/usr/local/sbin路径,因此,需要提前建立软链接
# ln -s /application/zabbix-server/sbin/* /usr/local/sbin/
# ln -s /application/zabbix-server/bin/* /usr/local/bin/
生成zabbix的web文件
# mkdir /application/nginx/html/zabbix
# cp -a /tools/zabbix-3.0.4/frontends/php/* /application/nginx/html/zabbix/
手动创建zabbix数据库及授权
# mysql -uroot -p123456
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.49-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database zabbix default charset utf8;
Query OK, 1 row affected (0.16 sec)
mysql> grant all on zabbix.* to zabbix@'localhost' identified by 'zabbix';
Query OK, 0 rows affected (0.16 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.19 sec)  

http://s1.运维网.com/wyfs02/M00/85/F8/wKiom1exPR-ToQo3AABdqjNeR6I658.png
导入zabbix数据库文件
# pwd
/tools/zabbix-3.0.4/database/mysql
# mysql -uzabbix -pzabbix zabbix < schema.sql
# mysql -uzabbix -pzabbix zabbix < images.sql
# mysql -uzabbix -pzabbix zabbix < data.sqlhttp://s4.运维网.com/wyfs02/M01/85/F8/wKioL1exPgGQ8DkOAAAUOnE7jVc927.png
配置zabbix server端
修改zabbix配置文件,配置zabbix_server
cd /usr/local/zabbix/etc
vi/usr/local/zabbix/etc/zabbix_server.conf
DBName=zabbix #数据库名称
DBUser=zabbix #数据库用户名
DBPassword=zabbix#数据库密码
ListenIP=localhost #数据库ip地址
DBSocket=/tmp/mysql.sock#这里填写mysql实际的socket位置查看/etc/my.cnf即可
AlertScriptsPath=/application/zabbix-server/share/zabbix/alertscripts#zabbix运行脚本存放目录
修改php.ini文件/application/php/lib/php.ini
post_max_size = 16M
max_execution_time = 300
memory_limit = 128M
max_input_time = 300
date.timezone = Asia/Shanghai
always_populate_raw_post_data = -1
extension=php_gettext.dll
修改nginx配置文件如下
# cat /application/nginx/conf/nginx.conf
worker_processes2;
events {
    worker_connections1024;
}
http {
log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    include       mime.types;
    default_typeapplication/octet-stream;
    sendfile      on;
    keepalive_timeout65;
    server {
      listen       80;
      server_namewww.martin.com martin.com;
      location / {
            root   html/zabbix;
            indexindex.php index.html index.htm;
      }
         
      location ~ .*\.(php|php5)?$ {
            roothtml/zabbix;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
               }
         access_loglogs/access_zabbix.logmain;      
   }
    server {
      listen       80;
      server_namebbs.martin.com;
      location / {
            root   html/bbs;
            indexindex.php index.html index.htm;
      }
            
      location ~ .*\.(php|php5)?$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
               }
         access_loglogs/access_bbs.logmain;      
    }
###status
   server{
      listen 80;
      server_name status.martin.org;
      location / {
      stub_status on;
      access_log off;
      }
   }
}
# /application/nginx/sbin/nginx -s reload
# useradd -s /sbin/nologin -M zabbix
# /etc/init.d/zabbix_server start   
Starting zabbix_server:                                    
# /application/php/sbin/php-fpm   
# /application/zabbix-server/sbin/zabbix_server -c /application/zabbix-server/etc/zabbix_server.conf  

  

  浏览器访问http://www.martin.com/
http://s5.运维网.com/wyfs02/M00/85/F8/wKiom1exTKDiSTfkAADBxm68aLU337.png
  

http://s5.运维网.com/wyfs02/M00/85/F9/wKioL1exYZqQIU9kAACkU1zhSm8692.png
  

http://s4.运维网.com/wyfs02/M02/85/F8/wKiom1exTh2xtkSTAACGa3XaDf8996.png
  

http://s4.运维网.com/wyfs02/M02/85/F9/wKioL1exYc3z9MnDAABoDUycOFw340.png
  

http://s1.运维网.com/wyfs02/M01/85/F9/wKioL1exYhODyrNYAACTInA_n8I471.png
http://s5.运维网.com/wyfs02/M00/85/FA/wKiom1exYiSxZM79AABpKJ_4vPI932.png
http://s4.运维网.com/wyfs02/M01/85/FA/wKiom1exYjngihWsAAAxtkZkwEE228.png
  

  用户名/密码 默认是Admin/zabbix
http://s4.运维网.com/wyfs02/M01/85/FA/wKiom1exaajh8xFmAAEr9jMm35U698.png
  再来看下中文界面
http://s4.运维网.com/wyfs02/M01/85/FA/wKioL1exahbTwm36AABzhLK3aH8278.png

安装agent
# wgethttp://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm      
# rpm -ivh zabbix-release-3.0-1.el6.noarch.rpm
Preparing...                ###########################################
   1:zabbix-release         ###########################################
# yum -y install zabbix-agent
# /etc/init.d/zabbix-agent start    启动agent
Starting Zabbix agent:                                       

http://s4.运维网.com/wyfs02/M00/85/FB/wKiom1exbkfxV5sRAACQ-tuzH0Y364.png
  

  按照图示步骤启用主机监控即可
http://s3.运维网.com/wyfs02/M01/85/FB/wKiom1excE6gaXyNAAEHX4TewBI581.png
  这次我们简单介绍到这里,下篇我们正式开始介绍zabbix监控
  




页: [1]
查看完整版本: 运维监控平台之zabbix详解1