linux下postgres环境变量配置,linux安装postgresql+postgis全流程

系统

linux

演示架构

arm

安装版本:

赠:yum安装java环境

java 安装

查询java可安装列表

yum -y list java*

从上方列表中取对应版本和系统

yum install -y java-xxx-openjdk.xxx

查询已经安装版本

java -version

安装过程问题:

问题一:/configure --prefix=/opt/...

1:checking build system type... configure: error: cannot guess build type; you must specify one

解决办法:

./configure --prefix=/opt/ ..... --build=arm-linux

2:configure: error: readline library not found

解决办法,追加

yum -y install -y readline-devel

3:configure: error: zlib library not found

yum install zlib-devel

3:configure: error: you must specify a parameter to --with-xml2config, e.g. --with-xml2config=/path/to/xml2-config

yum安装 libxml2 或者手动安装资源.gz -> http://xmlsoft.org/sources/

开始安装

(1)PostgreSQL 的安装

tar xvfz postgresql-9.6.19.tar.gz

cd postgresql-9.6.19

./configure --prefix=/opt/postgresql-9.6.19

make

make install

ln -s /opt/postgresql-9.6.19 /usr/local/pgsql

cd ..

(2)proj 的安装

tar xvfz proj-4.9.3.tar.gz

cd proj-4.9.3

./configure --prefix=/opt/proj-4.9.3

make

make install

ln -s /opt/proj-4.9.3 /usr/local/proj

cd ..

(3)geos 的安装

tar xvfj geos-3.6.1.tar.bz2

cd geos-3.6.1

./configure --prefix=/opt/geos-3.6.1

make;

make install;

ln -s /opt/geos-3.6.1 /usr/local/geos

cd ..

(4)JSON-C 的安装

tar xvfz json-c-0.9.tar.gz

cd json-c-0.9

./configure --prefix=/opt/json-c-0.9

make;

make install;

ln -s /opt/json-c-0.9 /usr/local/json-c

(5)PostGIS 的安装

tar xvfz postgis-2.5.3.tar.gz

cd postgis-2.5.3

./configure --prefix=/opt/postgis-2.5.3 --with-pgconfig=/plugin/postgresql-9.6.19/src/bin/pg_config/pg_config --with-projdir=/usr/local/proj --with-geosconfig=/usr/local/geos/bin/geos-config --with-jsondir=/usr/local/json-c --without-raster --with-xml2config=/xml2Cong插件位置

make

make install

ln -s /opt/postgis-2.5.3 /usr/local/postgis

(6). 配置环境

(6-1)创建用户 postgres,默认已经创建,如是可跳过

groupadd postgres

useradd -g postgres postgres

(6-2)用户postgres的环境变量

su - postgres

$ vi .bash_profile

(6-3)按 “ i ”添加下面的内容:

PGDATA=$HOME/data

PGSQL_HOME=/usr/local/pgsql

PROJ_HOME=/usr/local/proj

GEOS_HOME=/usr/local/geos

LD_LIBRARY_PATH=$PGSQL_HOME/lib:$PROJ_HOME/lib:$GEOS_HOME/lib

PATH=$PGSQL_HOME/bin:$PATH:$HOME/bin

export PATH PGDATA PGSQL_HOME PROJ_HOME GEOS_HOME LD_LIBRARY_PATH

按 “ Esc ” 并输入“:wq” 保存并退出

(6-4)$ exit :重新登录后环境变量生效

(7)PostgreSQL 数据库初始化及配置

su - postgres

$ initdb -D data

$ cd data

(8)PostGIS 安装配置

su - postgres

$ pg_ctl start

$ createdb postgis

$ createlang plpgsql postgis

$ cd $PGSQL_HOME/share/contrib/postgis-2.5

$ psql -d postgis -f postgis.sql

$ psql -d postgis -f spatial_ref_sys.sql

(postgis数据库为PostGIS模版数据库,可以使用这个模版创建其他支持PostGIS的数据库。)

(9)、配置允许远程访问PostgreSQL

PostgreSQL默认是只能数据库服务器本机访问,需要进行配置修改(经测试发现从其它机器telnet到postgresql服务器端口5432不通,但是数据库本地是有监听的)

注意有两个地方的配置文件要改:pg_hba.conf 和 postgresql.conf

1.先找到配置文件

find / -name pg_hba.conf

/root/xxx/pg_hba.conf

/var/xxx/pg_hba.conf

find / -name postgresql.conf

/root/xxx/postgresql.conf

/var/xxx/postgresql.conf

2.编辑/var/lib/pgsql/data/pg_hba.conf(根据实际需求,修改ipv4或ipv6配置),这样才能从其它地址连接到数据库IP。

#IPv4 local connections:

host all all 0.0.0.0/0 trust

#IPv6 local connections:

host all all ::1/128 trust

3.编辑/var/lib/pgsql/data/postgresql.conf,将listen_addresses设置为 *

# Connection Settings -

listen_addresses = '*' # what IP address(es) to listen on;

改为(注意重启postgresql服务后才生效 ):

pg查看

ps aux | grep postgres

netstat -npl | grep postgres

重启命令:

su - postgres

$pg_ctl restart