运维监控平台之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编译 [root@centos02tools]#wgethttp://cn2.php.net/distributions/php-5.6.24.tar.gz [root@centos02tools]#tarxfphp-5.6.24.tar.gz [root@centos02tools]#cdphp-5.6.24 [root@centos02php-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 Generatingfiles configure:creating./config.status creatingmain/internal_functions.c creatingmain/internal_functions_cli.c +--------------------------------------------------------------------+ |License:| |ThissoftwareissubjecttothePHPLicense,availableinthis| |distributioninthefileLICENSE.Bycontinuingthisinstallation| |process,youareboundbythetermsofthislicenseagreement.| |Ifyoudonotagreewiththetermsofthislicense,youmustabort| |theinstallationprocessatthispoint.| +--------------------------------------------------------------------+ ThankyouforusingPHP. config.status:creatingphp5.spec config.status:creatingmain/build-defs.h config.status:creatingscripts/phpize config.status:creatingscripts/man1/phpize.1 config.status:creatingscripts/php-config config.status:creatingscripts/man1/php-config.1 config.status:creatingsapi/cli/php.1 config.status:creatingsapi/fpm/php-fpm.conf config.status:creatingsapi/fpm/init.d.php-fpm config.status:creatingsapi/fpm/php-fpm.service config.status:creatingsapi/fpm/php-fpm.8 config.status:creatingsapi/fpm/status.html config.status:creatingsapi/cgi/php-cgi.1 config.status:creatingext/phar/phar.1 config.status:creatingext/phar/phar.phar.1 config.status:creatingmain/php_config.h config.status:executingdefaultcommands configure:WARNING:unrecognizedoptions:--enable-safe-mode,--with-curlwrappers,--enable-zend-multibyte 编译过程截图如下 [root@centos02application]#ln-s/application/mysql/lib/libmysqlclient.so.18/usr/lib64/ [root@centos02application]#touchext/phar/phar.phar [root@centos02application]#make&&makeinstall Buildcomplete. Don'tforgettorun'maketest'. Installingsharedextensions:/application/php5.6.24/lib/php/extensions/no-debug-non-zts-20131226/ InstallingPHPCLIbinary:/application/php5.6.24/bin/ InstallingPHPCLImanpage:/application/php5.6.24/php/man/man1/ InstallingPHPFPMbinary:/application/php5.6.24/sbin/ InstallingPHPFPMconfig:/application/php5.6.24/etc/ InstallingPHPFPMmanpage:/application/php5.6.24/php/man/man8/ InstallingPHPFPMstatuspage:/application/php5.6.24/php/php/fpm/ InstallingPHPCGIbinary:/application/php5.6.24/bin/ InstallingPHPCGImanpage:/application/php5.6.24/php/man/man1/ Installingbuildenvironment:/application/php5.6.24/lib/php/build/ Installingheaderfiles:/application/php5.6.24/include/php/ Installinghelperprograms:/application/php5.6.24/bin/ program:phpize program:php-config Installingmanpages:/application/php5.6.24/php/man/man1/ page:phpize.1 page:php-config.1 InstallingPEARenvironment:/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 WrotePEARsystemconfigfileat:/application/php5.6.24/etc/pear.conf Youmaywanttoadd:/application/php5.6.24/lib/phptoyourphp.iniinclude_path /tools/php-5.6.24/build/shtoolinstall-cext/phar/phar.phar/application/php5.6.24/bin ln-s-fphar.phar/application/php5.6.24/bin/phar InstallingPDOheaders:/application/php5.6.24/include/php/ext/pdo/ [root@centos02php-5.6.24]#ln-s/application/php5.6.24//application/php [root@centos02php-5.6.24]#cpphp.ini-production/application/php/lib/php.ini [root@centos02php-5.6.24]#cd/application/php/etc/ [root@centos02etc]#cpphp-fpm.conf.defaultphp-fpm.conf [root@centos02etc]#catphp-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@centos02etc]#/application/php/sbin/php-fpm nginx配置如下 [root@centos02etc]#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"'; includemime.types; default_typeapplication/octet-stream; sendfileon; keepalive_timeout65; server{ listen80; server_namewww.martin.commartin.com; location/{ roothtml/www; indexindex.phpindex.htmlindex.htm; } location~.*\.(php|php5)?${ roothtml/www; fastcgi_pass127.0.0.1:9000; fastcgi_indexindex.php; includefastcgi.conf; } access_loglogs/access_www.logmain; } server{ listen80; server_namebbs.martin.com; location/{ roothtml/bbs; indexindex.phpindex.htmlindex.htm; } location~.*\.(php|php5)?${ fastcgi_pass127.0.0.1:9000; fastcgi_indexindex.php; includefastcgi.conf; } access_loglogs/access_bbs.logmain; } ###status server{ listen80; server_namestatus.martin.org; location/{ stub_statuson; access_logoff; } } } 浏览器访问测试 (www.martin.com---172.16.80.117) 至此整个LNMP环境准备完成,zabbix(在LNMP环境下)选择源码编译安装 curl 7.19.7 系统默认版本,升级该软件版本,否则后面邮件功能会有问题 [root@centos02application]#rpm-Uvhhttp://www.city-fan.org/ftp/contrib/yum-repo/rhel6/x86_64/city-fan.org-release-1-13.rhel6.noarch.rpm Retrievinghttp://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:HeaderV3DSA/SHA1Signature,keyIDb56a8bac:NOKEY Preparing...###########################################[100%] 1:city-fan.org-release###########################################[100%] [root@centos02application]#yuminstalllibcurl-y [root@centos02application]#curl-V再次查看版本 curl7.50.1(x86_64-redhat-linux-gnu)libcurl/7.50.1OpenSSL/1.0.1ezlib/1.2.3c-ares/1.11.0libidn/1.18libssh2/1.7.0nghttp2/1.6.0 Protocols:dictfileftpftpsgopherhttphttpsimapimapsldapldapspop3pop3srtspscpsftpsmbsmbssmtpsmtpstelnettftp Features:AsynchDNSIDNIPv6LargefileGSS-APIKerberosSPNEGONTLMNTLM_WBSSLlibzHTTP2UnixSocketsMetalink 安装zabbix依赖包 [root@centos02zabbix-3.0.4]#yum-yinstallmysql-devellibxml2-develnet-snmp-devellibcurl-devel [root@centos02tools]#wgethttp://ncu.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.4/zabbix-3.0.4.tar.gz [root@centos02tools]#tarxfzabbix-3.0.4.tar.gz [root@centos02tools]#cdzabbix-3.0.4 [root@centos02zabbix-3.0.4]#./configure--prefix=/application/zabbix-server--enable-server--with-mysql--with-net-snmp--with-libcurl--with-libxml2--enable-agent--enable-proxy Enableserver:yes Serverdetails: Withdatabase:MySQL WEBMonitoring:cURL NativeJabber:no SNMP:yes IPMI:no SSH:no TLS:no ODBC:no Linkerflags:-L/usr/lib64/mysql-L/usr/lib64-rdynamic Libraries:-lmysqlclient-lxml2-lnetsnmp-lcurl-lm-ldl-lrt-lresolv Enableproxy:yes Proxydetails: Withdatabase:MySQL WEBMonitoring:cURL SNMP:yes IPMI:no SSH:no TLS:no ODBC:no Linkerflags:-L/usr/lib64/mysql-L/usr/lib64-rdynamic Libraries:-lmysqlclient-lxml2-lnetsnmp-lcurl-lm-ldl-lrt-lresolv Enableagent:yes Agentdetails: TLS:no Linkerflags:-rdynamic Libraries:-lcurl-lm-ldl-lrt-lresolv EnableJavagateway:no LDAPsupport:no IPv6support:no *********************************************************** *Nowrun'makeinstall'* ** *ThankyouforusingZabbix!* *<http://www.zabbix.com>* *********************************************************** [root@centos02 zabbix-3.0.4]# make install 由于zabbix启动脚本路径默认指向的是/usr/local/sbin路径,因此,需要提前建立软链接 [root@centos02zabbix-3.0.4]#ln-s/application/zabbix-server/sbin/*/usr/local/sbin/ [root@centos02zabbix-3.0.4]#ln-s/application/zabbix-server/bin/*/usr/local/bin/ 生成zabbix的web文件 [root@centos02zabbix-3.0.4]#mkdir/application/nginx/html/zabbix [root@centos02zabbix-3.0.4]#cp-a/tools/zabbix-3.0.4/frontends/php/*/application/nginx/html/zabbix/ 手动创建zabbix数据库及授权 [root@centos02zabbix-3.0.4]#mysql-uroot-p123456 WelcometotheMySQLmonitor.Commandsendwith;or\g. YourMySQLconnectionidis4 Serverversion:5.5.49-logMySQLCommunityServer(GPL) Copyright(c)2000,2013,Oracleand/oritsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand/orits affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. mysql>createdatabasezabbixdefaultcharsetutf8; QueryOK,1rowaffected(0.16sec) mysql>grantallonzabbix.*tozabbix@'localhost'identifiedby'zabbix'; QueryOK,0rowsaffected(0.16sec) mysql>flushprivileges; QueryOK,0rowsaffected(0.19sec) 导入zabbix数据库文件 [root@centos02mysql]#pwd /tools/zabbix-3.0.4/database/mysql [root@centos02mysql]#mysql-uzabbix-pzabbixzabbix<schema.sql [root@centos02mysql]#mysql-uzabbix-pzabbixzabbix<p_w_picpaths.sql [root@centos02mysql]#mysql-uzabbix-pzabbixzabbix<data.sql 配置zabbixserver端 修改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@centos02mysql]#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"'; includemime.types; default_typeapplication/octet-stream; sendfileon; keepalive_timeout65; server{ listen80; server_namewww.martin.commartin.com; location/{ roothtml/zabbix; indexindex.phpindex.htmlindex.htm; } location~.*\.(php|php5)?${ roothtml/zabbix; fastcgi_pass127.0.0.1:9000; fastcgi_indexindex.php; includefastcgi.conf; } access_loglogs/access_zabbix.logmain; } server{ listen80; server_namebbs.martin.com; location/{ roothtml/bbs; indexindex.phpindex.htmlindex.htm; } location~.*\.(php|php5)?${ fastcgi_pass127.0.0.1:9000; fastcgi_indexindex.php; includefastcgi.conf; } access_loglogs/access_bbs.logmain; } ###status server{ listen80; server_namestatus.martin.org; location/{ stub_statuson; access_logoff; } } } [root@centos02mysql]#/application/nginx/sbin/nginx-sreload [root@centos02mysql]#useradd-s/sbin/nologin-Mzabbix [root@centos02mysql]#/etc/init.d/zabbix_serverstart Startingzabbix_server:[OK] [root@centos02mysql]#/application/php/sbin/php-fpm [root@centos02init.d]#/application/zabbix-server/sbin/zabbix_server-c/application/zabbix-server/etc/zabbix_server.conf 浏览器访问http://www.martin.com/ 用户名/密码 默认是 Admin/zabbix 再来看下中文界面 安装agent [root@centos02tools]#wgethttp://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm [root@centos02tools]#rpm-ivhzabbix-release-3.0-1.el6.noarch.rpm Preparing...###########################################[100%] 1:zabbix-release###########################################[100%] [root@centos02tools]#yum-yinstallzabbix-agent [root@centos02tools]#/etc/init.d/zabbix-agentstart启动agent StartingZabbixagent:[OK] 按照图示步骤启用主机监控即可 这次我们简单介绍到这里,下篇我们正式开始介绍zabbix监控