基于Oracle安装Zabbix

 

软件版本

Oracle Enterprise Linux 7.1 64bit

Oracle Enterprise Edition 12.1.0.2 64bit

Zabbix 3.2.1

准备工作

上传软件

我们选用Zabbix 3.2.1

解压路径为/u01/stage/zabbix-3.2.1

准备需要的软件
安装Oracle 12.1.0.2

安装和创建数据库过程略,数据库字符集注意一定要是UTF8或AL32UTF8。

Apache

Zabbix的frontend需要apache ,我们使用OL7.1自带的http服务,应该是apache2.4

PHP 及其他扩展

的相关包的具体要求,参见:https://www.zabbix.com/documentation/3.2/manual/installation/requirements

注意PHP一定要5.4以上的,因为OL7.1自带的PHP已经是5.4了,所以省去了PHP安装的过程。

具体安装的软件包:

#rpm -Uvh php-5.4.16-23.el7_0.3.x86_64.rpm php-cli-5.4.16-23.el7_0.3.x86_64.rpm php-common-5.4.16-23.el7_0.3.x86_64.rpm libzip-0.10.1-8.el7.x86_64.rpm

#rpm -Uvh php-gd-5.4.16-23.el7_0.3.x86_64.rpm t1lib-5.1.2-14.el7.x86_64.rpm

#rpm -Uvh libxml2-2.9.1-5.0.1.el7_0.1.x86_64.rpm

#rpm –Uvh libxml2-devel-2.9.1-5.0.1.el7_0.1.x86_64.rpm xz-devel-5.1.2-9alpha.el7.x86_64.rpm zlib-devel-1.2.7-13.el7.x86_64.rpm

#rpm -Uvh php-xml-5.4.16-23.el7_0.3.x86_64.rpm

#rpm -Uvh php-xmlrpc-5.4.16-23.el7_0.3.x86_64.rpm

(ftp://bo.mirror.garr.it/1/slc/centos/7.0.1406/updates/x86_64/Packages/php-mbstring-5.4.16-23.el7_0.3.x86_64.rpm)

# rpm -Uvh php-mbstring-5.4.16-23.el7_0.3.x86_64.rpm

(ftp://bo.mirror.garr.it/1/slc/centos/7.0.1406/updates/x86_64/Packages/php-bcmath-5.4.16-23.el7_0.3.x86_64.rpm)

# rpm -Uvh php-bcmath-5.4.16-23.el7_0.3.x86_64.rpm

OCI8扩展

为了安装OCI8,还需要先安装下列包:

autoconf-2.69-11.el7.noarch.rpm

automake-1.13.4-3.el7.noarch.rpm

pcre-devel-8.32-14.el7.x86_64.rpm

php-devel-5.4.16-23.el7_0.3.x86_64.rpm (OS安装DVD中没有,下载地址:

http://rpm.pbone.net/index.php3/stat/4/idpl/27829696/dir/centos_7/com/php-devel-5.4.16-23.el7_0.3.x86_64.rpm.html,这个包包含phpize)

OCI8 2.0 下载地址:

http://pecl.php.net/package/oci8

PHP 5.4 应该用2.0.X版本的oci8,更新版本是和PHP 7 搭配使用的

# tar -xzf oci8-2.0.11.tgz

# cd oci8-2.0.11

# phpize

# ./configure --with-oci8=/u01/app/oracle/product/12.1.0/dbhome_1

# make install

修改/etc/php.ini

在文件最后添加一行:

extension=oci8.so

在/etc/ld.so.conf中添加oci8.so所在的路径,例如:

include ld.so.conf.d/*.conf

/root/oci8-2.0.11/modules

在/etc/sysconfig/httpd文件中添加必要的环境变量(不要加export):

ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib

NLS_LANG=AMERICAN_AMERICA.AL32UTF8

测试

#service httpd start

将下列脚本存成ocitest.php,放在/var/www/html 目录下,保证可执行权限:

<?php

error_reporting(E_ALL);

ini_set('display_errors', 'On');

$conn = oci_connect('system', 'welcome', 'localhost/orcl');

$stid = oci_parse($conn, 'select table_name from user_tables');

oci_execute($stid);

echo "<table>\n";

while (($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) != false) {

echo "<tr>\n";

foreach ($row as $item) {

echo " <td>".($item !== null ? htmlspecialchars($item, ENT_QUOTES) : "&nbsp;")."</td>\n";

}

echo "</tr>\n";

}

echo "</table>\n";

?>

访问http://<hostname>:<port>/ocitest.php,正常应该在页面上返回system用户的所有表。

修改其他PHP参数

修改/etc/php.ini文件中的下列参数:

post_max_size = 16M

max_execution_time = 300

max_input_time = 300

date.timezone = Asia/Shanghai

创建数据库schema
建数据库用户

SQL> create tablespace zabbix datafile '/u01/app/oracle/oradata/orcl/zabbix01.dbf' size 500M;

Tablespace created.

SQL> create user zabbix identified by welcome1 default tablespace zabbix;

User created.

SQL> grant connect,resource,unlimited tablespace to zabbix;

Grant succeeded.

SQL> grant create any directory to zabbix;

Grant succeeded.

SQL> grant drop any directory to zabbix;

Grant succeeded.

创建表结构

进入zabbix解压缩目录下的database/oracle目录,以zabbix用户身份登录数据库,运行3个sql脚本,创建表结构及元数据:

[oracle@rhelvm1 oracle]$ id

uid=500(oracle) gid=501(dba) groups=501(dba)

[oracle@rhelvm1 oracle]$ pwd

/u01/stage/zabbix-3.2.1/database/oracle

[oracle@rhelvm1 oracle]$ sqlplus zabbix/welcome1

SQL*Plus: Release 12.1.0.2.0 Production on Thu Nov 10 11:20:43 2016

Copyright (c) 1982, 2014, Oracle. All rights reserved.

Last Successful login time: Thu Nov 10 2016 11:19:12 -08:00

Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL>

schema.sql需要修改,将其中nvarchar2(2048)都改成nvarchar2(2000),这是12c的限制,最大只能2000了。

SQL>@schema.sql

images.sql需要修改,第一行的目录指向zabbix解压目录下的misc/images目录,我这里是/u01/stage/zabbix-3.2.1/misc/images

SQL>@images.sql

插入元数据:

SQL>@data.sql

创建OS用户

groupadd zabbix

useradd -g zabbix zabbix

为了保证运行zabbix程序时可以正常引用Oracle库文件,需要设置ORACLE_HOME等环境变量,修改zabbix的.bash_profile设置,添加以下行:

ORACLE_BASE=/u01/app/oracle

export ORACLE_BASE

ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1

export ORACLE_HOME

ORACLE_SID=orcl

export ORACLE_SID

PATH=$ORACLE_HOME/bin:$PATH

export PATH

LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH

export LD_LIBRARY_PATH

编译Zabbix

安装其他依赖包

从OL7的DVD中安装下列包,保证zabbix的编译能过够成功。

  • --with-net-snmp

#rpm -Uvh net-snmp-devel-5.7.2-20.el7.x86_64.rpm elfutils-devel-0.160-1.el7.x86_64.rpm elfutils-libelf-devel-0.160-1.el7.x86_64.rpm lm_sensors-devel-3.3.4-11.el7.x86_64.rpm net-snmp-agent-libs-5.7.2-20.el7.x86_64.rpm openssl-devel-1.0.1e-42.el7.x86_64.rpm perl-devel-5.16.3-285.el7.x86_64.rpm rpm-devel-4.11.1-25.el7.x86_64.rpm tcp_wrappers-devel-7.6-77.el7.x86_64.rpm krb5-devel-1.12.2-14.el7.x86_64.rpm gdbm-devel-1.10-8.el7.x86_64.rpm libdb-devel-5.3.21-17.el7_0.1.x86_64.rpm systemtap-sdt-devel-2.6-8.0.1.el7.x86_64.rpm popt-devel-1.13-16.el7.x86_64.rpm libselinux-devel-2.2.2-6.el7.x86_64.rpm libverto-devel-0.2.5-4.el7.x86_64.rpm pyparsing-1.5.6-9.el7.noarch.rpm libcom_err-devel-1.42.9-7.el7.x86_64.rpm keyutils-libs-devel-1.5.8-3.el7.x86_64.rpm libsepol-devel-2.1.9-3.el7.x86_64.rpm perl-ExtUtils-Install-1.58-285.el7.noarch.rpm perl-ExtUtils-MakeMaker-6.68-3.el7.noarch.rpm perl-ExtUtils-ParseXS-3.18-2.el7.noarch.rpm perl-ExtUtils-Manifest-1.61-244.el7.noarch.rpm

  • --with-libxml2

#rpm -Uvh libxml2-devel-2.9.1-5.0.1.el7_0.1.x86_64.rpm

  • --with-libcurl

#rpm -Uvh libcurl-devel-7.29.0-19.el7.x86_64.rpm

  • --with-libssh2

#rpm -Uvh libssh2-devel-1.4.3-8.el7.x86_64.rpm

ftp://bo.mirror.garr.it/1/slc/centos/7.1.1503/os/x86_64/Packages/libssh2-devel-1.4.3-8.el7.x86_64.rpm

编译安装

#su – zabbix

$cd /u01/stage/zabbix-

$./configure –prefix=/home/zabbix --enable-server --enable-agent --with-oracle=/u01/app/oracle/product/12.1.0/dbhome_1 --with-net-snmp --with-libcurl --with-libxml2 --with-ssh2

$make install

执行上述命令后,Zabbix会被安装在/home/zabbix目录下,运行命令启动server和本机agentd:

(在启动之前要修改etc/zabbix_server.conf文件,修改dbname,dbuser,dbpassword几个参数)

$cd

$sbin/zabbix_server

$sbin/zabbix_agentd

安装PHP应用

安装过程就是将PHP文件复制到apache http server对应的目录中:

#cd /var/www/html

#mkdir zabbix

# cd /u01/stage/zabbix-3.2.1/frontends/php

# cp -a . /var/www/html/zabbix

配置Zabbix

打开浏览器,访问http://<server_ip_or_name>/zabbix

clip_image002

确保所有pre-requisites都是OK的:

clip_image003

clip_image004

clip_image005

后面会提示闯将配置文件失败,我想是因为我们使用OS自带的HTTPD的原因,运行httpd的用户没有相应的目录访问权限,可以按照提示将配置文件另存,并手工复制到指定位置。

配置完成后直接转入登录页面。缺省用户和口令是Admin/zabbix

clip_image007

posted @ 2016-12-22 16:49  raobing  阅读(6603)  评论(0编辑  收藏  举报