本来是想一篇文章介绍完的,写着写着发现篇幅太长,所以决定还是分两篇来介绍,本次软件所用的版本信息如下(基于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编译
[[email protected] tools]# wget http://cn2.php.net/distributions/php-5.6.24.tar.gz [[email protected] tools]# tar xf php-5.6.24.tar.gz [[email protected] tools]# cd php-5.6.24 [[email protected] 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
编译过程截图如下
[[email protected] application]# ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/ [[email protected] application]# touch ext/phar/phar.phar [[email protected] 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/
[[email protected] php-5.6.24]# ln -s /application/php5.6.24/ /application/php [[email protected] php-5.6.24]# cp php.ini-production /application/php/lib/php.ini [[email protected] php-5.6.24]# cd /application/php/etc/ [[email protected] etc]# cp php-fpm.conf.default php-fpm.conf [[email protected] 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 [[email protected] etc]# /application/php/sbin/php-fpm nginx配置如下 [[email protected] 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 系统默认版本,升级该软件版本,否则后面邮件功能会有问题
[[email protected] 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%] [[email protected] application]# yum install libcurl -y [[email protected] 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依赖包 [[email protected] zabbix-3.0.4]# yum -y install mysql-devel libxml2-devel net-snmp-devel libcurl-devel [[email protected] tools]# wget http://ncu.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.4/zabbix-3.0.4.tar.gz [[email protected] tools]# tar xf zabbix-3.0.4.tar.gz [[email protected] tools]# cd zabbix-3.0.4 [[email protected] 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://www.zabbix.com> * ***********************************************************
[[email protected] zabbix-3.0.4]# make install
由于zabbix启动脚本路径默认指向的是/usr/local/sbin路径,因此,需要提前建立软链接 [[email protected] zabbix-3.0.4]# ln -s /application/zabbix-server/sbin/* /usr/local/sbin/ [[email protected] zabbix-3.0.4]# ln -s /application/zabbix-server/bin/* /usr/local/bin/ 生成zabbix的web文件 [[email protected] zabbix-3.0.4]# mkdir /application/nginx/html/zabbix [[email protected] zabbix-3.0.4]# cp -a /tools/zabbix-3.0.4/frontends/php/* /application/nginx/html/zabbix/ 手动创建zabbix数据库及授权 [[email protected]s02 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 [email protected]‘localhost‘ identified by ‘zabbix‘; Query OK, 0 rows affected (0.16 sec) mysql> flush privileges; Query OK, 0 rows affected (0.19 sec)
导入zabbix数据库文件 [[email protected] mysql]# pwd /tools/zabbix-3.0.4/database/mysql [[email protected] mysql]# mysql -uzabbix -pzabbix zabbix < schema.sql [[email protected] mysql]# mysql -uzabbix -pzabbix zabbix < images.sql [[email protected] 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配置文件如下 [[email protected] 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; } } } [[email protected] mysql]# /application/nginx/sbin/nginx -s reload [[email protected] mysql]# useradd -s /sbin/nologin -M zabbix [[email protected] mysql]# /etc/init.d/zabbix_server start Starting zabbix_server: [ OK ] [[email protected] mysql]# /application/php/sbin/php-fpm [[email protected] init.d]# /application/zabbix-server/sbin/zabbix_server -c /application/zabbix-server/etc/zabbix_server.conf
用户名/密码 默认是 Admin/zabbix
再来看下中文界面
安装agent [[email protected] tools]# wget http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm [[email protected] tools]# rpm -ivh zabbix-release-3.0-1.el6.noarch.rpm Preparing... ########################################### [100%] 1:zabbix-release ########################################### [100%] [[email protected] tools]# yum -y install zabbix-agent [[email protected] tools]# /etc/init.d/zabbix-agent start 启动agent Starting Zabbix agent: [ OK ]
按照图示步骤启用主机监控即可
这次我们简单介绍到这里,下篇我们正式开始介绍zabbix监控
时间: 2024-10-06 14:41:24