2022 Zabbix中国峰会
2022 Zabbix中国峰会

1 数据库创建脚本

概述

Zabbxi数据库必须在Zabbix服务器和代理安装的时候创建。 这部分提供了创建数据库的脚本。 对于每一个支持的数据库都提供了不同的架构脚本。

<note 注意>schema.sql, images.sql and data.sql 这些文件在Zabbix的子目录 database 下. 如果Zabbix是通过分发包安装的, 参考分发包相关文档. :::

<note 重要>对于Zabbix proxy 数据库, 只需要导入 schema.sql (不需要 images.sql 和 data.sql) :::

脚本

MySQL

shell> mysql -uroot -p<password>
       mysql> create database zabbix character set utf8 collate utf8_bin;
       mysql> grant all privileges on zabbix.* to zabbix@localhost identified by '<password>';
       mysql> quit;
       shell> cd database/mysql
       shell> mysql -uzabbix -p<password> zabbix < schema.sql
       # stop here if you are creating database for Zabbix proxy
       shell> mysql -uzabbix -p<password> zabbix < images.sql
       shell> mysql -uzabbix -p<password> zabbix < data.sql

PostgreSQL

我们假定存在一个用户,并且有权限创建数据库。

shell> psql -U <username>
       psql> create database zabbix; 
       psql> \q 
       shell> cd database/postgresql
       shell> psql -U <username> zabbix < schema.sql
       # stop here if you are creating database for Zabbix proxy
       shell> psql -U <username> zabbix < images.sql
       shell> psql -U <username> zabbix < data.sql

Oracle

我们假定存在一个 zabbix 数据库用户和 password 密码 并且有权限创建数据库 in ORCL service located on the host Oracle database server with a user shell user having write access to /tmp directory. Zabbix 要求 Unicode 数据库字符集 和 UTF8 通用字符集. 检查当前设置:

sqlplus> select parameter,value from v$nls_parameters where parameter='NLS_CHARACTERSET' or parameter='NLS_NCHAR_CHARACTERSET';

如果要创建一个Zabbix server的数据库,需要在Oracle主机上指定目录有images . 在Oracle主机上,复制 images from misc/images/png_modern目录下的文件到 /tmp/zabbix_images 目录:

shell> cd /path/to/zabbix-sources  
       shell> scp -r misc/images/png_modern user@host:/tmp/zabbix_images  

Now prepare the database:

shell> cd database/oracle
       shell> sqlplus zabbix/password@host/ORCL
       sqlplus> @schema.sql
       # stop here if you are creating database for Zabbix proxy
       sqlplus> @images.sql
       sqlplus> @data.sql

执行完 images.sql 脚本后, 可以删除临时目录 /tmp/zabbix_images 。

IBM DB2

shell> db2 "create database zabbix using codeset utf-8 territory us pagesize 32768"
       shell> cd database/ibm_db2
       shell> db2batch -d zabbix -f schema.sql
       # stop here if you are creating database for Zabbix proxy
       shell> db2batch -d zabbix -f images.sql
       shell> db2batch -d zabbix -f data.sql 

SQLite

shell> cd database/sqlite3
       shell> sqlite3 /var/lib/sqlite/zabbix.db < schema.sql
       # stop here if you are creating database for Zabbix proxy
       shell> sqlite3 /var/lib/sqlite/zabbix.db < images.sql
       shell> sqlite3 /var/lib/sqlite/zabbix.db < data.sql

如果Zabbix proxy使用SQLite ,若没有数据库,会自动创建。

返回 安装部分.