PG安装
一.基础包的安装(yum源的配置,可以采用光盘挂载,及ftp yum源,针对外网环境忽略此步):
yum -y install wget tcpdump glibc libgcc gcc gcc-c++ ncurses-devel bison openssl openssl-devel xinetd glibc glibc-common gd gd-devel rsync puppet ntp perl cmake man tree lsof openssh-clients traceroute lsb glibc-2.12-1.132.el6.i686 libgcc-4.4.7-4.el6.i686 vim strace readline-devel tcl tcl-devel python-devel libnl-devel unzip lrzsz
二.Pg具体安装
1. 安装依赖包
yum –y install bison flex readline-devel
2. 创建用户组和用户
groupadd postgres
useradd –g postgres postgres
passwd postgres
3. 解压文件
tar xzvf postgresql-9.1.0.tar.gz
cd postgresql-9.1.0
4. 配置
./configure --prefix=/usr/local/pgsql
5.编译
make
6. 安装
make install
[root@server8 ~]# cd /postgres/postgresql-9.1.0/contrib/
make&&make install 安装contrib 的插件
7. 创建数据库库文件存储目录、给postgres赋予权限
mkdir -p /pgdata/9.1/data
chown -R postgres:postgres /pgdata
8. 初始化数据库目录
su – postgres
/usr/local/pgsql/bin/initdb -D /pgdata/9.1/data
9. 配置用户postgres的环境变量
vi /home/postgres/.bash_profile
export PGHOME=/usr/local/pgsql
export PGDATA=/pgdata/9.1/data
PATH=$PATH:$PGHOME/bin
export PATH
10.让环境变量生效:source /home/postgres/.bash_profile
11. 启动数据库
su – postgres
pg_ctl start -D $PGDATA
备注:停止数据库的方法:pg_ctl stop –m fast–D $PGDATA
12.配置监听地址和端口及其它参数
vi $PGDATA/postgresql.conf
修改以下两行:
#listen_addresses = 'localhost'
#port = 5432
为:
listen_addresses ='*'
port = 5432
13.修改/pgdata/9.1/data/pg_hba.conf里面的参数:
在最后一行加入:host all all 172.25.0.0/16 trust
14.进入到root下关闭防火墙
service iptables stop(start)
service iptables status 常看状态
三 . 设置PostgreSQL开机自启动
PostgreSQL的开机自启动脚本位于PostgreSQL源码目录的contrib/start-scripts路径下
linux文件即为linux系统上的启动脚本
1)修改linux文件属性,添加X属性
#chmod a+x linux
2) 复制linux文件到/etc/init.d目录下,更名为postgresql
#cp linux /etc/init.d/postgresql
3)修改/etc/init.d/postgresql文件的两个变量
prefix设置为postgresql的安装路径:/usr/local/pgsql
PGDATA设置为postgresql的数据目录路径:/pgdata/9.1/data/
4) 执行service postgresql start,就可以启动PostgreSQL服务
#service postgresql start
5)设置postgresql服务开机自启动
#chkconfig --add postgresql
四. postgis安装
tar zxvf gdal-1.11.0.tar.gz
cd gdal-1.11.0
./configure --prefix=/usr/local/gdal
make
make install
2 .
tar jxvf geos-3.3.9.tar.bz2
cd geos-3.3.3
./configure --prefix=/usr/local/geos
make
make install
3.
unzip proj.4-master.zip
cd proj.4-master
./configure --prefix=/usr/local/proj
make
make install
4.
tar zxvf libxml2-2.6.27.tar.gz
cd libxml2-2.6.27
./configure --prefix=/usr/local/libxml2
make
make install
5.
vim /etc/ld.so.conf.d/postgresql.conf
加入: /usr/local/pgsql/lib
vim /etc/ld.so.conf.d/gdal.conf
加入: /usr/local/gdal/lib
vim /etc/ld.so.conf.d/proj.conf
加入: /usr/local/proj/lib
vim /etc/ld.so.conf.d/geos.conf
加入: /usr/local/geos/lib
ldconfig
6.
tar zxvf postgis-2.1.4.tar.gz
cd postgis-2.1.4
./configure --prefix=/usr/local/postgis --with-xml2config=/usr/local/libxml2/bin/xml2-config --with-geosconfig=/usr/local/geos/bin/geos-config --with-projdir=/usr/local/proj --with-gdalconfig=/usr/local/gdal/bin/gdal-config -with-pgconfig=/usr/local/pgsql/bin/pg_config
make
make install
执行上面的命令,就可以实现postgresql服务的开机自启动。