日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

Zabbix4.0 for PostgreSQL (上篇):基础环境的搭建部署

發布時間:2024/9/21 数据库 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Zabbix4.0 for PostgreSQL (上篇):基础环境的搭建部署 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

概述

Zabbix大家都很熟悉,一般的是使用MySQL作為存儲庫來使用的,而我看使用手冊上是使用postgresql也是可以的,所以就做了一次基于pg的zabbix搭建測試,記錄下來,分享給大家

Server端配置

配置PG環境

安裝好pg,且在root和postgres下都配置好pg的環境變量,以供后續使用

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

host zabbix zabbix 192.168.0.0/24 trust host all all 127.0.0.1/32 md5

配置apache

創建user

[root@Zabbix_GW_TEST opt]# adduser apache

準備好安裝包并解壓

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

編譯安裝

執行編譯命令

[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

報錯:

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

解決:

yum install apr yum install apr-util-devel

報錯:

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

解決:

yum install gcc

問題:

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

解決:

yum -y install pcre-devel

問題:

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

解決:

yum install -y zlib-devel

以下畫面說明編譯成功

configure: summary of build options:Server Version: 2.4.37Install prefix: /usr/local/apacheC compiler: gcc -std=gnu99CFLAGS: -pthread CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE LDFLAGS: LIBS: C preprocessor: gcc -E

繼續安裝

gmake gmake install

安裝成功之后安裝目錄也就生成文件了

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

建立腳本根目錄

用來存放html信息

mkdir /home/www chown -R apache:apache /home/www

配置運行參數

[root@nfs httpd-2.2.31]# vim /usr/local/apache/conf/httpd.conf#監聽port Listen 80#運營apache服務的用戶及用戶組,為apache User apache Group apache#管理員的郵箱是 ServerAdmin 1058582934@qq.com#配置腳本根目錄 DocumentRoot "/home/www"#配置 ServerName 127.0.0.1:80 <Directory />Options FollowSymLinksAllowOverride NoneOrder deny,allowallow from all </Directory><Directory "/home/www">Options Indexes FollowSymLinks AllowOverride None Order allow,denyAllow from all </Directory>

配置環境變量

添加一行環境變量到文件中

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

啟動apache服務

apachectl start

順便配置開機自動

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

至此,Apache配置完成

安裝配置php

安裝php依賴包

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

準備好包并解壓

tar -xvzf php-5.5.38.tar.gz

編譯

./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

報錯

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

解決:將apache的bin文件下的apxs文件第一行改為

#!/usr/bin/perl -w

報錯:

configure: error: xml2-config not found. Please check your libxml2 installationyum install libxml2-devel

報錯

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

報錯

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

報錯

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

報錯

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

報錯

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

報錯:

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

報錯

configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distributionyum -y install libxslt libxslt-devel

顯示如下,則編譯完成

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

安裝

make make install

準備配置文件

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

修改配置文件

[root@nfs php-5.5.38]# cp php.ini-development /usr/local/php/lib/php.ini [root@nfs php-5.5.38]# vim /usr/local/php/lib/php.inierror_reporting = E_ALL & ~E_NOTICE#報告所有的錯誤,但除了E_NOTICE這一種 display_errors = On #在終端顯示出錯信息,這個在生產環境最好設置成off track_errors = Off #是否在變量$php_errormsg中保存最近一個錯誤或警告消息 post_max_size = 16M #表單最大提交的數據量大小 upload_max_filesize = 16M #準許上傳文件大小限制為16Mdate.timezone = PRC #中華人民共和國時區expose_php = Off #隱藏php版本信息curl -I www.ha97.com HTTP/1.1 200 OK Server: nginx Date: Tue, 20 Jul 2010 05:45:13 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive Vary: Accept-Encoding #已經徹底隱藏了PHP版本。extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20121212/" #擴展模塊存放目錄

修改Apache的文件,在重啟

[root@nfs php-5.5.38]# vim /usr/local/apache/conf/httpd.conf 增加下面內容<IfModule dir_module>DirectoryIndex index.php index.html </IfModule><IfModule mime_module>AddType application/x-httpd-php-source .phpsAddType application/x-httpd-php .php .phtml </IfModule>

換一個思路的nginx搭建

概述

在apache配置解析php的操作種,遇到種種坑,Apache的配置不太熟悉,界面打不開php文件,理論上問題是出在Apache配置訪問php上。但是我能力有限,解決不來,所以就換一個NGINX試試。

編譯安裝

上傳解壓,并編譯。NGINX的編譯相對簡單,就不做詳細記錄

tar -xvzf nginx-1.6.0.tar.gz cd nginx-1.6.0./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 make make install

配置NGINX訪問PHP

這個是NGINX的關鍵,因為zabbix的界面全部都是PHP語言寫的,必須使用PHP軟件才能解析應用

server {listen 80;server_name localhost;location ~ \.(php|php5)?$ {root /data/html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /data/html$fastcgi_script_name;include fastcgi_params;}location ~* ^.+\.(ico|gif|jpg|jpeg|png|html|css|htm|bmp|js|svg)$ {root /data/html;}}

配置nginx.conf文件。增加兩個location,第一個location增加的是站點的地址信息。第二個是增加解析各種圖片樣式的功能(因為在沒有加的時候,我打開的zabbix界面全部都是只有文字,沒有任何圖片與樣式,如下。原因就是PHP沒有解析這些內容)

創建好站點目錄

瀏覽器通過端口來訪問服務器的文件,并用解析器解析,我們需要先準備好這些文件。zabbix的PHP文件是放在源碼包里的,解壓后就可以看到可以在上面的配置文件中可以看到我已經選擇了/data/html

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

注意賦權

啟動nginx

把環境變量配置在root下

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

啟動nginx,沒有報錯則啟動成功,看監聽端口和后臺進程

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

Zabbix配置

用戶環境配置好

用戶

adduser zabbix

編譯zabbix

編譯

./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

安裝依賴

yum install net-snmp-devel yum install libssh2-devel yum install OpenIPMI-devel yum install openldap-devel yum install libevent-devel yum install curl-devel

編譯到此界面則安裝成功

*********************************************************** * Now run 'make install' * * * * Thank you for using Zabbix! * * <http://www.zabbix.com> * ***********************************************************

執行make install

配置好環境變量

將此行寫進配置文件中

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

創建zabbix 數據庫

postgres=# create role zabbix login postgres-# ; CREATE ROLE postgres=# \password zabbix Enter new password: Enter it again: postgres=# create database zabbix with template template0 encoding 'UTF8' ; CREATE DATABASE postgres=# grant all on database zabbix to zabbix; GRANT postgres=# \q

導入zabbix數據

在源碼下,有zabbix數據庫的數據

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

配置zabbix_server參數

[root@Zabbix_GW_server ~]# vim /usr/local/zabbix/etc/zabbix_server.conf#監聽port ListenPort=10051#日志存放地點及大小 LogFile=/tmp/zabbix_server.log LogFileSize=10#pid文件存放地點 PidFile=/tmp/zabbix_server.pid#下面幾個參數是配置數據庫連接參數 DBHost=127.0.0.1 DBName=zabbix DBUser=zabbix DBPassword=zabbix DBPort=5432#監聽ip范圍 ListenIP=0.0.0.0#media types中使用script存放目錄 AlertScriptsPath=/usr/local/zabbix/alertscripts

啟動服務

zabbix_server

查看是否有錯,就查看zabbix_server 的啟動日志,如果有報錯,按照報錯修改。反正我安裝的時候真的報錯頻出,經歷過,懂得都懂

查看web界面

此時就可以通過web界面來訪問zabbix了
輸入地址

可以看到,配存在一些問題也還是需要修改的,不然的話無法安裝

agent端配置

概述

agnet端就是被監控的數據庫主機,也是需要做一些安裝

創建用戶

groupadd zabbix useradd -g zabbix -s /sbin/nologin zabbix

編譯安裝

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

無需指定其他的編譯參數

修改配置文件

vi /usr/local/zabbix-agent/etc/zabbix_agentd.confLogFile=/tmp/zabbix_agentd.log Server=192.168.6.17/32 Hostname=Zabbix agent

配置到環境變量

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

啟動zabbix_agent

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

至此

至此,zabbix的基本配置完成。后續還要配置監控等操作。后面慢慢再說

總結

以上是生活随笔為你收集整理的Zabbix4.0 for PostgreSQL (上篇):基础环境的搭建部署的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。