PostgreSQL&PostGIS完全安装

Posted 一泽涟漪

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PostgreSQL&PostGIS完全安装相关的知识,希望对你有一定的参考价值。

1. 创建postgres用户和组

# groupadd -g 101 dba
# useradd -u 501 -g dba -G root -d /usr/local/pgsql postgres

2. 添加postgres用户环境变量

$ cat ~/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs

export PGHOME=/usr/local/pgsql
export PGDATA=/usr/local/pgsql/data
export PATH=$PGHOME/bin:$PATH:$HOME/bin
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH

 3. 调整系统参数

# tail -n 12 /etc/sysctl.conf
vm.overcommit_memory=1
vm.overcommit_ratio=90
fs.aio-max-nr=1048576
fs.file-max= 7672460
net.ipv4.ip_local_port_range=9000 65500
net.core.rmem_default=262144
net.core.rmem_max=4194304
net.core.wmem_default=262144
net.core.wmem_max=1048586
kernel.sem= 50100 64128000 50100 1280
kernel.shmall=5242880
kernel.shmmax=12884901888

# tail -n 4 /etc/security/limits.conf
postgres soft nproc 8192
postgres hard nproc 16384
postgres soft nofile 4096
postgres hard nofile 65536

 4. 安装Python

# wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
# tar -zxf Python-2.7.13.tgz
# cd Python-2.7.13
# ./configure --enable-shared --with-distutils
# make
# make install
# /usr/local/bin/python --version
Python 2.7.13

5. 安装依赖包

# yum install -y perl-ExtUtils-Embed python-devel gcc-c++ openssl-devel readline readline-devel zlib zlib-devel openssl openssl-devel pam pam-devel libxml2 libxml2-devel libxslt libxslt-devel openldap openldap-devel libgeos-dev libproj-dev libgdal-dev xsltproc docbook-xsl docbook-xml imagemagick libmagickcore-dev dblatex tcl tcl-devel

6. 安装PostgreSQL

$ wget https://ftp.postgresql.org/pub/source/v9.5.7/postgresql-9.5.7.tar.bz2
$ tar -jxf postgresql-9.5.7.tar.bz2
$ cd postgresql-9.5.7
$ ./configure -prefix=/usr/local/pgsql --with-perl --with-tcl --with-openssl --with-pam --with-libxml --with-libxslt --with-wal-segsize=32
$ make
$ make install
$ cd contrib/
$ make && make install
$ mkdir /usr/local/pgsql/{data,arch}
$ sudo echo "su - postgres -c ‘pg_ctl start -D /usr/local/pgsql/data‘" >> /etc/rc.local
$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/
$ cat /usr/local/pgsql/data/postgresql.conf | grep -v "^$" | grep -v "^#"
listen_addresses = *        # what IP address(es) to listen on;
port = 5432                # (change requires restart)
max_connections = 300            # (change requires restart)
shared_buffers = 2048MB            # min 128kB
logging_collector = on        # Enable capturing of stderr and csvlog
log_directory = pg_log        # directory where log files are written,
log_filename = postgresql-%Y-%m-%d_%H%M%S.log    # log file name pattern,
$ cat /usr/local/pgsql/data/pg_hba.conf | grep -v "^$" | grep -v "^#"
local   all             all                                     trust
host    all             all             127.0.0.1/32            trust
host    all             all             0.0.0.0/0               md5
host    all             all             ::1/128                 trust
$ pg_ctl start -W
$ psql 
psql (9.5.7)
Type "help" for help.

postgres=# select version();
                                                 version                                                  
----------------------------------------------------------------------------------------------------------
 PostgreSQL 9.5.7 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18), 64-bit
(1 row)

 


以上是关于PostgreSQL&PostGIS完全安装的主要内容,如果未能解决你的问题,请参考以下文章

如何在 docker 中为 postgresql 创建 postgis 扩展?

如何在docker中为postgresql创建postgis扩展?

rails3、postgresql 和 postGIS:在迁移中冻结

postgresql与postgis结合示例

练习---空间数据入库postgresql

ubuntu 安装 postgresql 和 postgis