Zabbix Documentation 5.0

3.04.04.45.0 (current)| In development:5.2 (devel)| Unsupported:1.82.02.22.43.23.44.2Guidelines

User Tools

Site Tools


manual:appendix:install:db_scripts

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Previous revision
manual:appendix:install:db_scripts [2016/02/22 09:53]
manual:appendix:install:db_scripts [2020/03/24 15:05] (current)
marinagen timescale DB instructions removed
Line 1: Line 1:
 +==== 1 Database creation ====
  
 +=== Overview ===
 +
 +A Zabbix database must be created during the installation of Zabbix server or proxy.
 +
 +This section provides instructions for creating a Zabbix database. A separate set of instructions is available for each supported database.
 +
 +UTF-8 is the only encoding supported by Zabbix. It is known to work without any security flaws. Users should be aware that there are known security issues if using some of the other encodings.
 +
 +=== MySQL ===
 +
 +Character set utf8 and utf8_bin collation is required for Zabbix server/​proxy to work properly with MySQL database.
 +
 +  shell> mysql -uroot -p<​password>​
 +  mysql> create database zabbix character set utf8 collate utf8_bin;
 +  mysql> create user '​zabbix'​@'​localhost'​ identified by '<​password>';​
 +  mysql> grant all privileges on zabbix.* to '​zabbix'​@'​localhost';​
 +  mysql> quit;
 +
 +<note warning>​If you are installing from Zabbix **packages**,​ stop here and continue with instructions for [[https://​www.zabbix.com/​download?​zabbix=5.0&​os_distribution=red_hat_enterprise_linux&​os_version=8&​db=mysql|RHEL/​CentOS]] or [[https://​www.zabbix.com/​download?​zabbix=5.0&​os_distribution=debian&​os_version=10_buster&​db=mysql|Debian/​Ubuntu]] to import the data into the database.</​note>​
 +
 +If you are installing Zabbix from sources, proceed to import the data into the database. For a Zabbix proxy database, only ''​schema.sql''​ should be imported (no images.sql nor data.sql):
 +
 +  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 ===
 +
 +You need to have database user with permissions to create database objects. The following shell command will create user ''​zabbix''​. Specify password when prompted and repeat password (note, you may first be asked for ''​sudo''​ password):
 +
 +  shell> sudo -u postgres createuser --pwprompt zabbix
 +
 +Now we will set up the database ''​zabbix''​ (last parameter) with the previously created user as the owner (''​-O zabbix''​).
 +
 +  shell> sudo -u postgres createdb -O zabbix -E Unicode -T template0 zabbix
 +
 +<note warning>​If you are installing from Zabbix **packages**,​ stop here and continue with instructions for [[https://​www.zabbix.com/​download?​zabbix=5.0&​os_distribution=red_hat_enterprise_linux&​os_version=8&​db=postgresql|RHEL/​CentOS]] or [[https://​www.zabbix.com/​download?​zabbix=5.0&​os_distribution=debian&​os_version=10_buster&​db=postgresql|Debian/​Ubuntu]] to import the initial schema and data into the database.</​note>​
 +
 +If you are installing Zabbix from sources, proceed to import the initial schema and data (assuming you are in the root directory of Zabbix sources). For a Zabbix proxy database, only ''​schema.sql''​ should be imported (no images.sql nor data.sql).
 +
 +  shell> cd database/​postgresql
 +  shell> cat schema.sql | sudo -u zabbix psql zabbix
 +  # stop here if you are creating database for Zabbix proxy
 +  shell> cat images.sql | sudo -u zabbix psql zabbix
 +  shell> cat data.sql | sudo -u zabbix psql zabbix
 +
 +<note important>​The above commands are provided as an example that will work in most of GNU/Linux installations. You can use different commands, e. g. "psql -U <​username>"​ depending on how your system/​database are configured. If you have troubles setting up the database please consult your Database administrator.
 +</​note>​
 +
 +=== TimescaleDB ===
 +
 +Instructions for creating and configuring TimescaleDB are provided in a separate [[:​manual/​appendix/​install/​timescaledb|section]]. ​
 +
 +=== Oracle ===
 +
 +We assume that a //zabbix// database user with //​password//​ password exists and has permissions to create database objects in ORCL service located on  the //host// Oracle database server with a //user// shell user having write access to /tmp directory. Zabbix requires a Unicode database character set and a ''​UTF8''​ national character set. Check current settings:
 +
 +  sqlplus> select parameter,​value from v$nls_parameters where parameter='​NLS_CHARACTERSET'​ or parameter='​NLS_NCHAR_CHARACTERSET';​
 +
 +If you are creating a database for Zabbix server you need to have images from Zabbix sources on the host where Oracle is running. Copy them to a directory ///​tmp/​zabbix_images//​ on the Oracle host:
 +
 +  shell> cd /​path/​to/​zabbix-sources
 +  shell> ssh [email protected]_host "mkdir /​tmp/​zabbix_images"​
 +  shell> scp -r misc/​images/​png_modern [email protected]_host:/​tmp/​zabbix_images/​
 +
 +Now prepare the database:
 +
 +  shell> cd /​path/​to/​zabbix-sources/​database/​oracle
 +  shell> sqlplus zabbix/​[email protected]_host/​ORCL
 +  sqlplus> @schema.sql
 +  # stop here if you are creating database for Zabbix proxy
 +  sqlplus> @images.sql
 +  sqlplus> @data.sql
 +
 +<note tip>​Please set the initialization parameter CURSOR_SHARING=FORCE for best performance.</​note>​
 +
 +Now the temporary directory can be removed:
 +
 +  shell> ssh [email protected]_host "rm -rf /​tmp/​zabbix_images"​
 + 
 +=== SQLite ===
 +
 +Using SQLite is supported for **Zabbix proxy** only!
 +
 +<​note>​If using SQLite with Zabbix proxy, database will be automatically created if it does not exist.</​note>​
 +
 +  shell> cd database/​sqlite3
 +  shell> sqlite3 /​var/​lib/​sqlite/​zabbix.db < schema.sql
 +
 +Return to the [[manual:​installation:​install|installation section]].