CentOS 配置postgresql+psotgis

1.安装CentOS并下载所需的材料包:

 

2.创建用户postgres:

  # groupadd postgres
  # useradd -g postgres postgres

 

3.安装必须的工具包:

  # yum -y install gcc   安装gcc编译器

  # yum -y install gcc-c++  安装gcc-c++编译器

  # yum -y install make  安装make,这个是自动编译源码的工具

  # yum -y install kernel-headers 安装内核头文件,编译内核,驱动必要的头文件

  # yum -y install kernel-devel  安装kernel-devel

  # yum -y install readline-devel  安装readline-devel

  # yum -y install zlib-devel  安装zlib-devel

 

4.安装libxml2包:

  # tar -zvxf libxml2-2.6.26.tar.gz
  # cd libxml2-2.6.26
  # ./configure –prefix=/usr/local/libxml2
  # make
  # make install

下载:ftp://xmlsoft.org/libxml2/

 

5.安装proj包:

  # tar -zvxf proj-4.8.0.tar.gz
  # cd proj-4.8.0
  # ./configure –prefix=/usr/local/proj
  # make
  # make install

下载:http://trac.osgeo.org/proj/

 

6.安装geos包:

  # tar xvfj geos-3.3.6.tar.bz2
  # cd geos-3.3.6
  # ./configure –prefix=/usr/local/geos
  # make
  # make install

下载:http://trac.osgeo.org/geos/

 

7.安装postgresql 包:

  # tar –zvxf postgresql-9.2.2.tar.gz
  # cd postgresql-9.2.2
  # ./configure –prefix=/usr/local/pgsql
  # make
  # make install

下载:http://www.postgresql.org/ftp/source/

 

8.添加环境变量:

  备份:# cp /etc/profile profile.bak

  # vi /etc/profile

  添加:
  PATH=$PATH:$HOME/bin
  export PATH
  PATH=$PATH:$HOME/bin
  PGSQL_HOME=/usr/local/pgsql
  PATH=$PATH:$PGSQL_HOME/bin
  PROJ_HOME=/usr/local/proj
  GEOS_HOME=/usr/local/geos
  PATH=$PATH:$PROJ_HOME/bin:$GEOS_HOME/bin
  LD_LIBRARY_PATH=$PGSQL_HOME/lib:$PROJ_HOME/lib:$GEOS_HOME/lib
  export PATH
  export PGSQL_HOME
  export PROJ_HOME
  export GEOS_HOME
  export LD_LIBRARY_PATH

 

9.初始化数据库:

  # mkdir /usr/local/pgsql/data
  # cd  /usr/local

  把pgsql目录交给postgres管理:

  # chown  -R postgres:postgres  pgsql
  # su postgres
  # /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data

 

10.配置pg_hba.conf、postgresql.conf :

  # su root  切换用户

  # cd /usr/local/pgsql/data

  备份:# cp pg_hba.conf pg_hba.conf.bak

  # vi pg_hba.conf   后面加  host  all  all   all trust

  备份:# cp postgresql.conf postgresql.conf.bak

  # vi postgresql.conf  将文件中的#listen_address=’localhost’ 改为 listen_address=’*’  将#port=5432改为port=5432

 

11.设置postgresql启动:

  拷贝安装包下面的:
  ..../contrib/start-scripts/linux 到/etc/init.d/ 目录下
  # cp /home/postgresql/postgresql-9.2.2/contrib/start-scripts/linux /etc/init.d/postgis
  # chmod a+x /etc/init.d/postgis
  # chown -R postgres:postgres /etc/init.d/postgis
  加入开机启动 # chkconfig --add postgis

 

12.安装postgis包:

  

  # tar -zvxf postgis-1.5.8.tar.gz
  # cd postgis-1.5.8
  # LDFLAGS=-lstdc++ 
  # ./configure -prefix=/usr/local/postgis --with-pgsql=/usr/local/pgsql/bin/pg_config --with-pgconfig=/usr/local/pgsql/bin/pg_config --with-proj=/usr/local/proj --with-geos=/usr/local/geos/bin/geos-config --with-geosconfig=/usr/local/geos/bin/geos-config --with-projdir=/usr/local/proj --with-xml2config=/usr/local/libxml2/bin/xml2-config
  # make
  # make install

下载:http://postgis.net/source

  

如果需要--with-gdalconfig,则需要下载安装gdal:

  # tar -zvxf gdal-1.11.0.tar.gz
  # cd gdal-1.11.0
  # ./configure -prefix=/usr/local/gdal
  # make
  # make install

使用时添加--with-gdalconfig=/usr/local/gdal/bin/gdal-config

下载:http://trac.osgeo.org/gdal/wiki/DownloadSource

 

13.检查postgres目录分配情况:

  # vi /etc/passwd  对应信息应为:postgres:x:502:501::/usr/local/pgsql:/bin/bash

 

14.新建测试数据库:

  # su postgres
  # /usr/local/pgsql/bin/createdb  demogis
  # /usr/local/pgsql/bin/psql -d demogis -f /usr/local/pgsql/share/contrib/postgis-1.5/postgis.sql
  # /usr/local/pgsql/bin/psql -d demogis -f /usr/local/pgsql/share/contrib/postgis-1.5/spatial_ref_sys.sql

 

15.修改防火墙配置:

  # vi /etc/sysconfig/iptables

  添加-A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT

  保存退出

  # service iptables restart

 

   End.

posted @ 2013-06-21 16:48  lianche  阅读(674)  评论(0编辑  收藏  举报