软件版本
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
# rpm -Uvh PHP-mbstring-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
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=
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');
conn,'select table_name from user_tables');
oci_execute($stid);
echo "<table>\n";
while ((
stid,OCI_ASSOC+OCI_RETURN_NULLS)) != false) {
echo "<tr>\n";
foreach (
item) {
echo " <td>".(
item,ENT_QUOTES) : " ")."</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
?>
访问http://<hostname>:<port>/ocitest.PHP,正常应该在页面上返回system用户的所有表。
修改其他PHP参数
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了。
images.sql需要修改,第一行的目录指向zabbix解压目录下的misc/images目录,我这里是/u01/stage/zabbix-3.2.1/misc/images
插入元数据:
创建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=
PATH
export PATH
LD_LIBRARY_PATH=
LD_LIBRARY_PATH
export LD_LIBRARY_PATH
编译Zabbix
安装其他依赖包
从OL7的DVD中安装下列包,保证zabbix的编译能过够成功。
文章来自:http://www.dawen.org/wen/7245.html
- --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
编译安装
#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文件复制到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
确保所有pre-requisites都是OK的:
后面会提示闯将配置文件失败,我想是因为我们使用OS自带的HTTPD的原因,运行httpd的用户没有相应的目录访问权限,可以按照提示将配置文件另存,并手工复制到指定位置。