centos7安装pg数据库9.2.0

1、安装epel源https://mp.csdn.net/postedit/80693388该博客有写

2、安装各种依赖包

#yum install -y gcc gdb strace gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel 
#yum install ncurses ncurses-devel curl curl-devel e2fsprogs patch e2fsprogs-devel krb5-devel libidn libidn-devel openldap-devel nss_ldap openldap-clients openldap-servers libevent-devel libevent uuid-devel uuid mysql-devel

#yum install make cmake lrzsz perl perl-ExtUtils-Embed readline readline-devl python-devel proj proj-devel screen gmp gmp-devel mpfr mpfr-devel devtoolset-2-gcc devtoolset-2-binutils devtoolset-2-gcc-c++ boost boost-devel cmake3 cmake3-gui cmake3-data 

3、下载安装包:

#cd  /mnt/data

wget http://download.osgeo.org/postgis/source/postgis-2.2.2.tar.gz

wget http://download.osgeo.org/gdal/2.0.0/gdal-2.0.0.tar.gz

wget http://download.osgeo.org/geos/geos-3.5.0.tar.bz2

postgresql-9.2.0.tar.gz到官网下载

4、postgresql 安装

(1)选择路径:比如我的是/mnt/data/

(2)安装
#cd  /mnt/data
#tar zxvf postgresql-9.2.0.tar.gz
#cd postgresql-9.2.0
#./configure   --with-python --with-perl
#make

#make install

安装完毕了

(3)添加数据库帐号

#adduser postgres

添加数据存放路径:mkdir /mnt/data/postgresql-9.2.0/data

chown postgres.postgres  /mnt/data/postgresql-9.2.0/data

(4)启动

(4)启动
进入普通账号
#su - postgres
初始化操作
#/mnt/data/postgresql-9.2.0/bin/initdb -D /mnt/data/postgresql-9.2.0/data
启动
#/mnt/data/postgresql-9.2.0/bin/postgres -D /mnt/data/postgresql-9.2.0/data >logfile 2>&1 &

或者:#pg_ctl start -D /mnt/data/postgresql-9.2.0/data/ -m  fast

停止

#pg_ctl stop -D /mnt/data/postgresql-9.2.0/data/ -m  fast

将pg数据库添加到环境变量上:#su - postgres

#vi ~/.bash_profile

export LD_LIBRARY_PATH=/mnt/data/postgresql-9.2.0/lib
export PATH=/mnt/data/postgresql-9.2.0/bin:$PATH

#source ~/.bash_profile (执行一下脚本,让环境变量生效,终端执行#echo $PATH可以检查是否添加成功)


然后就安装完成了,由于pg数据库还有很多扩展,这里说几个常用扩展的安装

1、安装:fuzzystrmatch扩展包

cd /home/data/postgresql-9.2.0/contrib/fuzzystrmatch/ 
make
make install          //make install后生成了需要的 extension;

2、安装gdal扩展包

#tar zxvf gdal-2.0.0.tar.gz     
#cd gdal-2.0.0
#./configure --prefix=/usr/local/gdal  --with-xml2=/usr/bin/xml2-config --with-static-proj4=/usr/bin/proj
#make

#make install

3、安装geos扩展包

#tar jxvf geos-3.5.0.tar.bz2
#cd geos-3.5.0
#./configure --prefix=/usr/local/geos3
#make

#make install

装完配置依赖库的路径信息

#vi  /etc/ld.so.conf
/home/data/postgresql-9.2.0/lib/
/usr/local/gdal/lib/
/usr/local/geos3/lib
/usr/local/lib

#ldconfig   //动态函数加载

4、安装postgis

#tar zxvf postgis-2.2.2.tar.gz
#cd postgis-2.2.2.tar.gz
#../configure --with-pgconfig=/home/data/postgresql-9.2.0/bin/pg_config  --with-gdalconfig=/usr/local/gdal/bin/gdal-config --with-geosconfig=/usr/local/geos3/bin/geos-config

#make

#cd extensions

#cd postgis
#make clean
#make 
#make install
#cd ..
#cd postgis_topology
#make clean
#make 
#make install

#cd ..
#cd postgis_tiger_geocoder
#make clean
#make 

装完这些扩展,然后退出目录继续make install postgis

#cd ../..
#make install

(装完了扩展然后就是在数据库上添加扩展了)

#su - postgres
#psql
进入控制台执行以下语句:
CREATE EXTENSION postgis;
CREATE EXTENSION fuzzystrmatch; 
CREATE EXTENSION postgis_tiger_geocoder;
CREATE EXTENSION postgis_topology;

############OK!!装好了,也添加好了扩展,可以修改下密码,然后让远程登录咯#####################

密码:#su - postgres
#psql

alter user postgres with password 'mima';

设置远程连接:

#cd /home/data/postgresql-9.2.0/data
#vi pg_hba.conf 

local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
host    all             all             0.0.0.0/0               md5   //修改的是这一行
# IPv6 local connections:
host    all             all             ::1/128                 trust     

#vi postgresql.conf

listen_addresses = '*'          # what IP address(es) to listen on;   //修改了这一行
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
#port = 5432                            # (change requires restart)

max_connections = 1024                  # (change requires restart)  //改打连接数

设置postgresql数据库开机自启动
#vi /etc/rc.d/rc.local
设置postgresql数据库开机自启动
#vi /etc/rc.d/rc.local
su - postgres -c 'pg_ctl start -D /data01/data/pgsql9_4_8/data/ -m fast'
#chmod +x rc.local


好了,完事了,对着做应该没问题了,如果还有问题,根据报错什么的,万能的度娘。



猜你喜欢

转载自blog.csdn.net/iris_csdn/article/details/80693969