设为首页 收藏本站
查看: 844|回复: 0

[经验分享] 运维监控平台之zabbix详解1

[复制链接]

尚未签到

发表于 2019-1-25 09:29:18 | 显示全部楼层 |阅读模式
  

  本来是想一篇文章介绍完的,写着写着发现篇幅太长,所以决定还是分两篇来介绍,本次软件所用的版本信息如下(基于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编译
[root@centos02 tools]# wget  http://cn2.php.net/distributions/php-5.6.24.tar.gz
[root@centos02 tools]# tar xf php-5.6.24.tar.gz
[root@centos02 tools]# cd php-5.6.24
[root@centos02 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  

  编译过程截图如下

[root@centos02 application]# ln -s /application/mysql/lib/libmysqlclient.so.18  /usr/lib64/
[root@centos02 application]# touch ext/phar/phar.phar
[root@centos02 application]# 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/
[PEAR] Archive_Tar    - installed: 1.4.0
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.3.0
[PEAR] 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/  


[root@centos02 php-5.6.24]# ln -s /application/php5.6.24/ /application/php
[root@centos02 php-5.6.24]# cp php.ini-production /application/php/lib/php.ini
[root@centos02 php-5.6.24]# cd /application/php/etc/
[root@centos02 etc]# cp php-fpm.conf.default php-fpm.conf
[root@centos02 etc]# cat php-fpm.conf
[global]
[www]
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
[root@centos02 etc]# /application/php/sbin/php-fpm
nginx配置如下
[root@centos02 etc]# cat /application/nginx/conf/nginx.conf
worker_processes  2;
events {
    worker_connections  1024;
}
http {
log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  www.martin.com martin.com;
        location / {
            root   html/www;
            index  index.php index.html index.htm;
        }
         
        location ~ .*\.(php|php5)?$ {
            root  html/www;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
               }
         access_log  logs/access_www.log  main;        
   }
    server {
        listen       80;
        server_name  bbs.martin.com;
        location / {
            root   html/bbs;
            index  index.php index.html index.htm;
        }
            
        location ~ .*\.(php|php5)?$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
               }
         access_log  logs/access_bbs.log  main;      
    }
###status
   server{
      listen 80;
      server_name status.martin.org;
      location / {
      stub_status on;
      access_log off;
        }
   }
}  

  

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


  

  

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

  curl 7.19.7  系统默认版本,升级该软件版本,否则后面邮件功能会有问题
[root@centos02 application]# 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...                ########################################### [100%]
   1:city-fan.org-release   ########################################### [100%]
[root@centos02 application]#  yum install libcurl -y
[root@centos02 application]# 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依赖包
[root@centos02 zabbix-3.0.4]#  yum -y install mysql-devel libxml2-devel net-snmp-devel libcurl-devel     
[root@centos02 tools]# wget http://ncu.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.4/zabbix-3.0.4.tar.gz
[root@centos02 tools]# tar xf zabbix-3.0.4.tar.gz
[root@centos02 tools]# cd zabbix-3.0.4
[root@centos02 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!                  *
*                                  *
***********************************************************  


  

  [root@centos02 zabbix-3.0.4]# make install
  


由于zabbix启动脚本路径默认指向的是/usr/local/sbin路径,因此,需要提前建立软链接
[root@centos02 zabbix-3.0.4]# ln -s /application/zabbix-server/sbin/* /usr/local/sbin/
[root@centos02 zabbix-3.0.4]# ln -s /application/zabbix-server/bin/* /usr/local/bin/
生成zabbix的web文件
[root@centos02 zabbix-3.0.4]# mkdir /application/nginx/html/zabbix
[root@centos02 zabbix-3.0.4]# cp -a /tools/zabbix-3.0.4/frontends/php/* /application/nginx/html/zabbix/
手动创建zabbix数据库及授权
[root@centos02 zabbix-3.0.4]# 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)  


导入zabbix数据库文件
[root@centos02 mysql]# pwd
/tools/zabbix-3.0.4/database/mysql
[root@centos02 mysql]# mysql -uzabbix -pzabbix zabbix < schema.sql
[root@centos02 mysql]# mysql -uzabbix -pzabbix zabbix < images.sql
[root@centos02 mysql]# mysql -uzabbix -pzabbix zabbix < data.sql

配置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配置文件如下
[root@centos02 mysql]# cat /application/nginx/conf/nginx.conf
worker_processes  2;
events {
    worker_connections  1024;
}
http {
log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  www.martin.com martin.com;
        location / {
            root   html/zabbix;
            index  index.php index.html index.htm;
        }
         
        location ~ .*\.(php|php5)?$ {
            root  html/zabbix;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
               }
         access_log  logs/access_zabbix.log  main;        
   }
    server {
        listen       80;
        server_name  bbs.martin.com;
        location / {
            root   html/bbs;
            index  index.php index.html index.htm;
        }
            
        location ~ .*\.(php|php5)?$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
               }
         access_log  logs/access_bbs.log  main;      
    }
###status
   server{
      listen 80;
      server_name status.martin.org;
      location / {
      stub_status on;
      access_log off;
        }
   }
}
[root@centos02 mysql]# /application/nginx/sbin/nginx -s reload
[root@centos02 mysql]# useradd -s /sbin/nologin -M zabbix
[root@centos02 mysql]# /etc/init.d/zabbix_server start   
Starting zabbix_server:                                    [  OK  ]
[root@centos02 mysql]# /application/php/sbin/php-fpm   
[root@centos02 init.d]# /application/zabbix-server/sbin/zabbix_server -c /application/zabbix-server/etc/zabbix_server.conf  

  

  浏览器访问http://www.martin.com/

  


  


  


  




  

  用户名/密码 默认是  Admin/zabbix

  再来看下中文界面


安装agent
[root@centos02 tools]# wget  http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm      
[root@centos02 tools]# rpm -ivh zabbix-release-3.0-1.el6.noarch.rpm
Preparing...                ########################################### [100%]
   1:zabbix-release         ########################################### [100%]
[root@centos02 tools]# yum -y install zabbix-agent
[root@centos02 tools]# /etc/init.d/zabbix-agent start    启动agent
Starting Zabbix agent:                                     [  OK  ]  


  

  按照图示步骤启用主机监控即可

  这次我们简单介绍到这里,下篇我们正式开始介绍zabbix监控
  





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-667280-1-1.html 上篇帖子: Zabbix监控特定程序的详细步骤 下篇帖子: LNMP环境搭建ZABBIX3.0
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表