netbox/docs/installation/1-postgresql.md

82 lines
3.2 KiB
Markdown
Raw Normal View History

2020-03-05 17:23:56 -05:00
# PostgreSQL Database Installation
2020-02-26 11:40:31 -05:00
This section entails the installation and configuration of a local PostgreSQL database. If you already have a PostgreSQL database service in place, skip to [the next section](2-redis.md).
!!! warning
2020-07-20 16:53:04 -04:00
NetBox requires PostgreSQL 9.6 or higher. Please note that MySQL and other relational databases are **not** currently supported.
2020-02-26 11:40:31 -05:00
## Installation
2020-02-26 11:40:31 -05:00
#### Ubuntu
2016-07-08 16:00:53 -04:00
2017-10-12 13:38:23 -04:00
If a recent enough version of PostgreSQL is not available through your distribution's package manager, you'll need to install it from an official [PostgreSQL repository](https://wiki.postgresql.org/wiki/Apt).
```no-highlight
2020-11-17 12:01:10 -05:00
sudo apt update
sudo apt install -y postgresql libpq-dev
```
2020-02-26 11:40:31 -05:00
#### CentOS
2016-07-08 16:00:53 -04:00
2020-07-20 16:53:04 -04:00
CentOS 7 does not ship with a recent enough version of PostgreSQL, so it will need to be installed from an external repository. The instructions below show the installation of PostgreSQL 9.6, however you may opt to install a more recent version.
2017-10-12 13:38:23 -04:00
```no-highlight
2020-11-17 12:01:10 -05:00
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install -y postgresql96 postgresql96-server postgresql96-devel
sudo /usr/pgsql-9.6/bin/postgresql96-setup initdb
```
2017-10-12 13:38:23 -04:00
CentOS users should modify the PostgreSQL configuration to accept password-based authentication by replacing `ident` with `md5` for all host entries within `/var/lib/pgsql/9.6/data/pg_hba.conf`. For example:
```no-highlight
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
2016-07-08 16:00:53 -04:00
```
2017-10-12 13:38:23 -04:00
Then, start the service and enable it to run at boot:
```no-highlight
2020-11-17 12:01:10 -05:00
sudo systemctl start postgresql-9.6
sudo systemctl enable postgresql-9.6
```
2016-07-08 16:00:53 -04:00
2020-02-26 11:40:31 -05:00
## Database Creation
2016-07-08 16:00:53 -04:00
At a minimum, we need to create a database for NetBox and assign it a username and password for authentication. This is done with the following commands.
!!! danger
2020-07-20 16:53:04 -04:00
**Do not use the password from the example.** Choose a strong, random password to ensure secure database authentication for your NetBox installation.
2016-07-08 16:00:53 -04:00
```no-highlight
2020-11-17 12:01:10 -05:00
$ sudo -u postgres psql
psql (12.5 (Ubuntu 12.5-0ubuntu0.20.04.1))
2016-07-08 16:00:53 -04:00
Type "help" for help.
postgres=# CREATE DATABASE netbox;
CREATE DATABASE
postgres=# CREATE USER netbox WITH PASSWORD 'J5brHrAXFLQSif0K';
CREATE ROLE
postgres=# GRANT ALL PRIVILEGES ON DATABASE netbox TO netbox;
GRANT
postgres=# \q
```
2020-02-26 11:40:31 -05:00
## Verify Service Status
2017-10-12 13:38:23 -04:00
You can verify that authentication works issuing the following command and providing the configured password. (Replace `localhost` with your database server if using a remote database.)
2016-07-08 16:00:53 -04:00
```no-highlight
2020-11-17 12:01:10 -05:00
$ psql --username netbox --password --host localhost netbox
2020-07-20 16:53:04 -04:00
Password for user netbox:
2020-11-17 12:01:10 -05:00
psql (12.5 (Ubuntu 12.5-0ubuntu0.20.04.1))
2020-07-20 16:53:04 -04:00
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.
2020-11-17 12:01:10 -05:00
netbox=> \conninfo
You are connected to database "netbox" as user "netbox" on host "localhost" (address "127.0.0.1") at port "5432".
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
2020-07-20 16:53:04 -04:00
netbox=> \q
2016-07-08 16:00:53 -04:00
```
2020-11-17 12:01:10 -05:00
If successful, you will enter a `netbox` prompt. Type `\conninfo` to confirm your connection, or type `\q` to exit.