概述

Zabbix大家都很熟悉,一般的是使用MySQL作为存储库来使用的,而我看使用手册上是使用postgresql也是可以的,所以就做了一次基于pg的zabbix搭建测试,记录下来,分享给大家

Server端配置

配置PG环境

安装好pg,且在root和postgres下都配置好pg的环境变量,以供后续使用

在hba控制文件中直接加入这一行

  1. host zabbix zabbix 192.168.0.0/24 trust
  2. host all all 127.0.0.1/32 md5

配置apache

创建user

  1. [root@Zabbix_GW_TEST opt]# adduser apache

准备好安装包并解压

  1. [root@Zabbix_GW_TEST opt]# ls httpd-2.4.37.tar.gz
  2. httpd-2.4.37.tar.gz
  3. [root@Zabbix_GW_TEST opt]# tar -xvzf httpd-2.4.37.tar.gz

编译安装

执行编译命令

  1. [root@Zabbix_GW_TEST httpd-2.4.37]# ./configure --prefix=/usr/local/apache --enable-rewrite --enable-deflate --enable-expires --enable-headers --enable-modules=most --with-mpm=worker --enable-so

报错:

  1. configure: error: APR not found. Please read the documentation.

解决:

  1. yum install apr
  2. yum install apr-util-devel

报错:

  1. configure: error: in `/opt/httpd-2.4.37':
  2. configure: error: C compiler cannot create executables
  3. See `config.log' for more details

解决:

  1. yum install gcc

问题:

  1. configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

解决:

  1. yum -y install pcre-devel

问题:

  1. configure: error: mod_deflate has been requested but can not be built due to prerequisite failures

解决:

  1. yum install -y zlib-devel

以下画面说明编译成功

  1. configure: summary of build options:
  2. Server Version: 2.4.37
  3. Install prefix: /usr/local/apache
  4. C compiler: gcc -std=gnu99
  5. CFLAGS: -pthread
  6. CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE
  7. LDFLAGS:
  8. LIBS:
  9. C preprocessor: gcc -E

继续安装

  1. gmake
  2. gmake install

安装成功之后安装目录也就生成文件了

  1. [root@Zabbix_GW_TEST apache]# ls
  2. bin build cgi-bin conf error htdocs icons include logs man manual modules

建立脚本根目录

用来存放html信息

  1. mkdir /home/www
  2. chown -R apache:apache /home/www

配置运行参数

  1. [root@nfs httpd-2.2.31]# vim /usr/local/apache/conf/httpd.conf
  2. #监听port
  3. Listen 80
  4. #运营apache服务的用户及用户组,为apache
  5. User apache
  6. Group apache
  7. #管理员的邮箱是
  8. ServerAdmin 1058582934@qq.com
  9. #配置脚本根目录
  10. DocumentRoot "/home/www"
  11. #配置
  12. ServerName 127.0.0.1:80
  13. <Directory />
  14. Options FollowSymLinks
  15. AllowOverride None
  16. Order deny,allow
  17. allow from all
  18. </Directory>
  19. <Directory "/home/www">
  20. Options Indexes FollowSymLinks
  21. AllowOverride None
  22. Order allow,deny
  23. Allow from all
  24. </Directory>

配置环境变量

添加一行环境变量到文件中

  1. export PATH=/usr/local/apache/bin:$PATH
  2. [root@Zabbix_GW_TEST apache]# source ~/.bash_profile
  3. [root@Zabbix_GW_TEST apache]# which apachectl
  4. /usr/local/apache/bin/apachectl

启动apache服务

  1. apachectl start

顺便配置开机自动

  1. vim /etc/rc.d/rc.local
  2. /usr/local/apache/bin/apachectl start

至此,Apache配置完成

安装配置php

安装php依赖包

  1. wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
  2. tar zxf libiconv-1.14.tar.gz
  3. ./configure --prefix=/usr/local/libiconv
  4. make
  5. make install

准备好包并解压

  1. tar -xvzf php-5.5.38.tar.gz

编译

  1. ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-xmlrpc --with-openssl --with-zlib --with-freetype-dir --with-gd --with-jpeg-dir --with-png-dir --with-iconv=/usr/local/libiconv --enable-short-tags --enable-sockets --enable-soap --enable-mbstring --enable-static --enable-gd-native-ttf --with-curl --with-xsl --enable-ftp --with-libxml-dir --with-pgsql=/usr/postgresql --enable-fpm --enable-bcmath --with-gettext

报错

  1. Sorry, I cannot run apxs. Possible reasons follow:
  2. 1. Perl is not installed
  3. 2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs
  4. 3. Apache was not built using --enable-so (the apxs usage page is displayed)
  5. The output of /usr/local/apache/bin/apxs follows:
  6. ./configure: /usr/local/apache/bin/apxs: /replace/with/path/to/perl/interpreter: bad interpreter: No such file or directory
  7. configure: error: Aborting

解决:将apache的bin文件下的apxs文件第一行改为

  1. #!/usr/bin/perl -w

报错:

  1. configure: error: xml2-config not found. Please check your libxml2 installation
  2. yum install libxml2-devel

报错

  1. configure: error: Cannot find OpenSSL's <evp.h>
  2. yum install openssl openssl-devel

报错

  1. configure: error: Please reinstall the libcurl distribution -
  2. easy.h should be in <curl-dir>/include/curl/
  3. yum install curl curl-devel

报错

  1. configure: error: There is something wrong. Please check config.log for more information.
  2. curl-devel-7.15.5-2.el5安装

报错

  1. configure: error: jpeglib.h not found.
  2. yum -y install libjpeg-devel

报错

  1. configure: error: png.h not found.
  2. yum install libpng libpng-devel

报错:

  1. configure: error: freetype-config not found.
  2. yum install freetype-devel

报错

  1. configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
  2. yum -y install libxslt libxslt-devel

显示如下,则编译完成

  1. creating main/internal_functions_cli.c
  2. +--------------------------------------------------------------------+
  3. | License: |
  4. | This software is subject to the PHP License, available in this |
  5. | distribution in the file LICENSE. By continuing this installation |
  6. | process, you are bound by the terms of this license agreement. |
  7. | If you do not agree with the terms of this license, you must abort |
  8. | the installation process at this point. |
  9. +--------------------------------------------------------------------+
  10. Thank you for using PHP.
  11. config.status: creating php5.spec
  12. config.status: creating main/build-defs.h
  13. config.status: creating scripts/phpize
  14. config.status: creating scripts/man1/phpize.1
  15. config.status: creating scripts/php-config
  16. config.status: creating scripts/man1/php-config.1
  17. config.status: creating sapi/cli/php.1
  18. config.status: creating sapi/fpm/php-fpm.conf
  19. config.status: creating sapi/fpm/init.d.php-fpm
  20. config.status: creating sapi/fpm/php-fpm.service
  21. config.status: creating sapi/fpm/php-fpm.8
  22. config.status: creating sapi/fpm/status.html
  23. config.status: creating sapi/cgi/php-cgi.1
  24. config.status: creating ext/phar/phar.1
  25. config.status: creating ext/phar/phar.phar.1
  26. config.status: creating main/php_config.h
  27. config.status: executing default commands

安装

  1. make
  2. make install

准备配置文件

  1. [root@Zabbix_GW_TEST php-5.5.38]# cp php.ini-development /usr/local/php/lib/php.ini
  2. [root@Zabbix_GW_TEST php-5.5.38]# vi /usr/local/php/lib/php.ini

修改配置文件

  1. [root@nfs php-5.5.38]# cp php.ini-development /usr/local/php/lib/php.ini
  2. [root@nfs php-5.5.38]# vim /usr/local/php/lib/php.ini
  3. error_reporting = E_ALL & ~E_NOTICE
  4. #报告所有的错误,但除了E_NOTICE这一种
  5. display_errors = On
  6. #在终端显示出错信息,这个在生产环境最好设置成off
  7. track_errors = Off
  8. #是否在变量$php_errormsg中保存最近一个错误或警告消息
  9. post_max_size = 16M
  10. #表单最大提交的数据量大小
  11. upload_max_filesize = 16M
  12. #准许上传文件大小限制为16M
  13. date.timezone = PRC
  14. #中华人民共和国时区
  15. expose_php = Off
  16. #隐藏php版本信息
  17. curl -I www.ha97.com
  18. HTTP/1.1 200 OK
  19. Server: nginx
  20. Date: Tue, 20 Jul 2010 05:45:13 GMT
  21. Content-Type: text/html; charset=UTF-8
  22. Connection: keep-alive
  23. Vary: Accept-Encoding
  24. #已经彻底隐藏了PHP版本。
  25. extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20121212/"
  26. #扩展模块存放目录

修改Apache的文件,在重启

  1. [root@nfs php-5.5.38]# vim /usr/local/apache/conf/httpd.conf
  2. 增加下面内容
  3. <IfModule dir_module>
  4. DirectoryIndex index.php index.html
  5. </IfModule>
  6. <IfModule mime_module>
  7. AddType application/x-httpd-php-source .phps
  8. AddType application/x-httpd-php .php .phtml
  9. </IfModule>

换一个思路的nginx搭建

概述

在apache配置解析php的操作种,遇到种种坑,Apache的配置不太熟悉,界面打不开php文件,理论上问题是出在Apache配置访问php上。但是我能力有限,解决不来,所以就换一个NGINX试试。

编译安装

上传解压,并编译。NGINX的编译相对简单,就不做详细记录

  1. tar -xvzf nginx-1.6.0.tar.gz
  2. cd nginx-1.6.0
  3. ./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module
  4. make
  5. make install

配置NGINX访问PHP

这个是NGINX的关键,因为zabbix的界面全部都是PHP语言写的,必须使用PHP软件才能解析应用

  1. server {
  2. listen 80;
  3. server_name localhost;
  4. location ~ \.(php|php5)?$ {
  5. root /data/html;
  6. fastcgi_pass 127.0.0.1:9000;
  7. fastcgi_index index.php;
  8. fastcgi_param SCRIPT_FILENAME /data/html$fastcgi_script_name;
  9. include fastcgi_params;
  10. }
  11. location ~* ^.+\.(ico|gif|jpg|jpeg|png|html|css|htm|bmp|js|svg)$ {
  12. root /data/html;
  13. }
  14. }

配置nginx.conf文件。增加两个location,第一个location增加的是站点的地址信息。第二个是增加解析各种图片样式的功能(因为在没有加的时候,我打开的zabbix界面全部都是只有文字,没有任何图片与样式,如下。原因就是PHP没有解析这些内容)

创建好站点目录

浏览器通过端口来访问服务器的文件,并用解析器解析,我们需要先准备好这些文件。zabbix的PHP文件是放在源码包里的,解压后就可以看到可以在上面的配置文件中可以看到我已经选择了/data/html

  1. cp -r /opt/zabbix-4.0.2/frontends/php/* /data/html

注意赋权

启动nginx

把环境变量配置在root下

  1. export PATH=/usr/local/nginx/sbin:$PATH

启动nginx,没有报错则启动成功,看监听端口和后台进程

  1. [root@Zabbix_GW_TEST ~]# netstat -lnp|grep 80
  2. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 25373/nginx: master
  3. [root@Zabbix_GW_TEST ~]# ps -ef|grep nginx
  4. root 12817 10266 0 18:11 pts/1 00:00:00 grep --color=auto nginx
  5. root 25373 1 0 01:21 ? 00:00:00 nginx: master process nginx
  6. www 27717 25373 0 02:07 ? 00:00:00 nginx: worker process

Zabbix配置

用户环境配置好

用户

  1. adduser zabbix

编译zabbix

编译

  1. ./configure --prefix=/usr/local/zabbix --enable-server --enable-proxy --enable-agent --enable-ipv6 --with-postgresql=/usr/local/pgsql/bin/pg_config --with-net-snmp --with-ssh2 --with-openipmi --with-ldap --with-libcurl --with-iconv

安装依赖

  1. yum install net-snmp-devel
  2. yum install libssh2-devel
  3. yum install OpenIPMI-devel
  4. yum install openldap-devel
  5. yum install libevent-devel
  6. yum install curl-devel

编译到此界面则安装成功

  1. ***********************************************************
  2. * Now run 'make install' *
  3. * *
  4. * Thank you for using Zabbix! *
  5. * <http://www.zabbix.com> *
  6. ***********************************************************

执行make install

配置好环境变量

将此行写进配置文件中

  1. PATH=/usr/local/zabbix/bin:/usr/local/zabbix/sbin:$PATH

创建zabbix 数据库

  1. postgres=# create role zabbix login
  2. postgres-# ;
  3. CREATE ROLE
  4. postgres=# \password zabbix
  5. Enter new password:
  6. Enter it again:
  7. postgres=# create database zabbix with template template0 encoding 'UTF8' ;
  8. CREATE DATABASE
  9. postgres=# grant all on database zabbix to zabbix;
  10. GRANT
  11. postgres=# \q

导入zabbix数据

在源码下,有zabbix数据库的数据

  1. cd /opt/zabbix-4.0.2/database/postgresql/
  2. psql -Uzabbix -dzabbix -h127.0.0.1 -f schema.sql
  3. psql -Uzabbix -dzabbix -h127.0.0.1 -f images.sql
  4. psql -Uzabbix -dzabbix -h127.0.0.1 -f data.sql

配置zabbix_server参数

  1. [root@Zabbix_GW_server ~]# vim /usr/local/zabbix/etc/zabbix_server.conf
  2. #监听port
  3. ListenPort=10051
  4. #日志存放地点及大小
  5. LogFile=/tmp/zabbix_server.log
  6. LogFileSize=10
  7. #pid文件存放地点
  8. PidFile=/tmp/zabbix_server.pid
  9. #下面几个参数是配置数据库连接参数
  10. DBHost=127.0.0.1
  11. DBName=zabbix
  12. DBUser=zabbix
  13. DBPassword=zabbix
  14. DBPort=5432
  15. #监听ip范围
  16. ListenIP=0.0.0.0
  17. #media types中使用script存放目录
  18. AlertScriptsPath=/usr/local/zabbix/alertscripts

启动服务

  1. zabbix_server

查看是否有错,就查看zabbix_server 的启动日志,如果有报错,按照报错修改。反正我安装的时候真的报错频出,经历过,懂得都懂

查看web界面

此时就可以通过web界面来访问zabbix了
输入地址

可以看到,配存在一些问题也还是需要修改的,不然的话无法安装

agent端配置

概述

agnet端就是被监控的数据库主机,也是需要做一些安装

创建用户

  1. groupadd zabbix
  2. useradd -g zabbix -s /sbin/nologin zabbix

编译安装

  1. ./configure --prefix=/usr/local/zabbix-agent --enable-agent
  2. make install

无需指定其他的编译参数

修改配置文件

  1. vi /usr/local/zabbix-agent/etc/zabbix_agentd.conf
  2. LogFile=/tmp/zabbix_agentd.log
  3. Server=192.168.6.17/32
  4. Hostname=Zabbix agent

配置到环境变量

  1. PATH=/usr/local/zabbix-agent/bin:/usr/local/zabbix-agent/sbin:$PATH

启动zabbix_agent

直接运行zabbix_agent命令,查看日志,观察是否正常

至此

至此,zabbix的基本配置完成。后续还要配置监控等操作。后面慢慢再说

本站文章,未经作者同意,请勿转载,如需转载,请邮件customer@csudata.com.
0 评论  
添加一条新评论