postgresql部署
- 安装postgresql组件
bash
root@test-server03:~# apt-get install postgresql-10 -y
- 修改posgresql数据目录
bash
root@test-server03:~# systemctl stop postgresql
root@test-server03:~# cd /etc/postgresql/10/main/
root@test-server03:/etc/postgresql/10/main# vim postgresql.conf
#修改下面参数为自己的数据盘目录
data_directory = '/opt/postgresql/data'
- 创建数据目录并授权
bash
root@test-server03:/etc/postgresql/10/main# mkdir /opt/postgresql/data -p
root@test-server03:/etc/postgresql/10/main# chown -R postgres.postgres /opt/postgresql*
- 初始化数据库
bash
#找到initdb的位置
root@test-server03:~# find / -name initdb
/usr/lib/postgresql/10/bin/initdb
#初始化
root@test-server03:~# sudo -u postgres /usr/lib/postgresql/10/bin/initdb -D /opt/postgresql/data
#重新启动postgresql
root@test-server03:~# systemctl restart postgresql
- 修改postgres用户密码
bash
root@test-server03:~# passwd postgres
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
#登录psql查看数据目录是否修改,并且设置密码
root@test-server03:~# su postgres
postgres@test-server03:/root$ psql
psql (10.23 (Ubuntu 10.23-0ubuntu0.18.04.2))
Type "help" for help.
postgres=# SHOW data_directory;
data_directory
----------------------
/opt/postgresql/data
postgres=# ALTER USER postgres PASSWORD 'newpassd';
ALTER ROLE
- 修改配置
bash
root@test-server03:~# vim /etc/postgresql/10/main/pg_hba.conf
标红的注释掉,标黄的修改一处,新增一处
bash
root@test-server03:~# vim /etc/postgresql/10/main/postgresql.conf
listen_addresses = '*'
- 重启psql
bash
root@test-server03:~# systemctl restart postgresql
root@test-server03:~# psql -U postgres
Password for user postgres:
psql (10.23 (Ubuntu 10.23-0ubuntu0.18.04.2))
Type "help" for help.
postgres=#
postgis安装
- 安装postgis
bash
root@test-server03:~# apt-get install postgis -y
- 配置postgis
bash
root@test-server03:~# psql -U postgres -W
Password for user postgres:
psql (10.23 (Ubuntu 10.23-0ubuntu0.18.04.2))
Type "help" for help.
postgres=# create extension postgis;
CREATE EXTENSION
postgres=# \dx
List of installed extensions
Name | Version | Schema | Description
---------+---------+------------+---------------------------------------------------------------------
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
postgis | 2.4.3 | public | PostGIS geometry, geography, and raster spatial types and functions
(2 rows)
postgis插件成功安装