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 processZabbix配置
用戶環境配置好
用戶
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 (上篇):基础环境的搭建部署的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 虚拟桌面启动后自动全屏
- 下一篇: 记一次laravel-jwt修改黑名单所