CentOS 6.8操作系统安装PostGIS笔记

CentOS 6.8操作系统安装PostGIS笔记

首先顺便利一下SSH工具的选择。因为我不能操作安装CentOS系统的机器,只能远程操作。所以在工作进行之前必须选择一款好的SSH工具。以前操作Oracle Red Hat Enterprise Linux系统的时候用SSHSecureShellClient工具挺顺手的。这次远程登录到CentOS操作系统后中文全部乱码。于是选择了PuTTY工具。

首先在Windows系统上启动PuTTY,远程登录到CentOS系统,如下所示:

login as: root

root@192.168.8.155's password:

Active connection state: activated

Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/2

[root@db ~]# ls

anaconda-ks.cfg install.log install.log.syslog

安装PostgreSQL

安装大型软件经常要拷贝文件,需要创建一个固定的文件夹用来存放专用文件。

[root@db /]# mkdir /home/postgis

[root@db /]# ls -l /home/postgis

total 0

[root@db /]#

CentOS软件列表默认没有PostgresSQL,所有要先从PostgreSQL下载rpm包。这个包主要用来在软件源中加入PostgreSQL,以便使用yum install命令安装。下载链接如下:

http://yum.postgresql.org/9.4/redhat/rhel­6­x86_64/pgdg­redhat94­9.4­1.noarch.rpm

我放到了F盘的根目录。接下来要用SSH管道传递到远程服务器。与PuTTY配套的工具还有很多,这里使用配套的PSCP工具。我把pscp.exe复制到了Windows目录,这样不用设置环境不用切换目录,打开Windows控制台窗口,输入命令,如下所示:

C:\Users\xuesongshu>pscp f:\pgdg-redhat94-9.4-1.noarch.rpm root@192.168.8.155:/home/postgis

root@192.168.8.155's password:

pgdg-redhat94-9.4-1.noarc | 5 kB | 5.2 kB/s | ETA: 00:00:00 | 100%

C:\Users\xuesongshu>

然后安装:

[root@db /]# cd /home/postgis

[root@db postgis]# yum install pgdg-redhat94-9.4-1.noarch.rpm login as: root

Loaded plugins: fastestmirror,refresh-packagekit,security

Setting up Install Process

Examining pgdg-redhat94-9.4-1.noarch.rpm: pgdg-redhat94-9.4-1.noarch

Marking pgdg-redhat94-9.4-1.noarch.rpm to be installed

Loading mirror speeds from cached hostfile

如下图所示,输入Y

至此提示则成功

Downloading Packages:

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

Installing : pgdg-redhat94-9.4-1.noarch 1/1

Verifying : pgdg-redhat94-9.4-1.noarch 1/1

Installed:

pgdg-redhat94.noarch 0:9.4-1

Complete!

[root@db postgis]#

输入命令安装PostgreSQL,如下所示:

[root@db postgis]# yum install postgresql94-server postgresql94-contrib

在随后的提示中都输入Y即可,静待下载和安装,等待时间由网速决定。出现以下提示则表示安装成功。

Installed:

postgresql94-contrib.x86_64 0:9.4.8-1PGDG.rhel6

postgresql94-server.x86_64 0:9.4.8-1PGDG.rhel6

Dependency Installed:

postgresql94.x86_64 0:9.4.8-1PGDG.rhel6

postgresql94-libs.x86_64 0:9.4.8-1PGDG.rhel6

Complete!

[root@db postgis]#

配置PostgreSQL

PostgreSQL以默认方式安装完成之后不能马上投入使用,必须进行配置。首先初始化并启动服务,如下所示:

[root@db /]# service postgresql-9.4 initdb

Initializing database: [ OK ]

[root@db /]# chkconfig postgresql-9.4 on

[root@db /]#

编辑pg_hba.conf,如下所示:

[root@db /]# cd /var/lib/pgsql/9.4/data

[root@db data]# ls

base pg_ident.conf pg_replslot pg_subtrans postgresql.auto.conf

global pg_log pg_serial pg_tblspc postgresql.conf

pg_clog pg_logical pg_snapshots pg_twophase

pg_dynshmem pg_multixact pg_stat PG_VERSION

pg_hba.conf pg_notify pg_stat_tmp pg_xlog

[root@db data]# vi pg_hba.conf

按向下键快速向后找到以下文字:

# Put your actual configuration here

# ----------------------------------

#

# If you want to allow non-local connections,you need to add more

# "host" records. In that case you will also need to make PostgreSQL

# listen on a non-local interface via the listen_addresses

# configuration parameter,or via the -i or -h command line switches.

# TYPE DATABASE USER ADDRESS METHOD

紧接在这里的是PostgreSQL的服务配置:

# TYPE DATABASE USER ADDRESS METHOD

# "local" is for Unix domain socket connections only

local all all peer

# IPv4 local connections:

host all all 127.0.0.1/32 ident

# IPv6 local connections:

host all all ::1/128 ident

# Allow replication connections from localhost,by a user with the

# replication privilege.

#local replication postgres peer

#host replication postgres 127.0.0.1/32 ident

#host replication postgres ::1/128 ident

shift+I键进入编辑状态,改成如下所示:

然后按Esc键,输入:wq!命令保存文件,如下图所示。

编辑postgresql.conf文件,如下所示:

[root@db data]# vi postgresql.conf

按向下键快速向后查看找到以下文字:

#ident_file = 'ConfigDir/pg_ident.conf' # ident configuration file

# (change requires restart)

# If external_pid_file is not explicitly set,no extra PID file is written.

#external_pid_file = '' # write an extra PID file

# (change requires restart)

#------------------------------------------------------------------------------

# CONNECTIONS AND AUTHENTICATION

#------------------------------------------------------------------------------

# - Connection Settings -

紧接下来的是服务配置文字如下:

# - Connection Settings -

#listen_addresses = 'localhost' # 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 = 100 # (change requires restart)

shift+I键进入编辑状态,改成如下所示:

Esc键后输入:wq!保存文件。

编辑环境变量,如下所示:

[root@db data]# cd /etc/

[root@db etc]# vi profile

按向下键快速向后移到光标,找到以下文字:

HOSTNAME=`/bin/hostname 2>/dev/null`

HISTSIZE=1000

if [ "$HISTCONTROL" = "ignorespace" ] ; then

export HISTCONTROL=ignoreboth

else

export HISTCONTROL=ignoredups

fi

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL

改成:

HOSTNAME=`/bin/hostname 2>/dev/null`

HISTSIZE=1000

if [ "$HISTCONTROL" = "ignorespace" ] ; then

export HISTCONTROL=ignoreboth

else

export HISTCONTROL=ignoredups

fi

export PGHOME=/usr/pgsql-9.4

export PGDATA=/var/lib/pgsql/9.4/data

export PATH=$PGHOME/bin:$PATH

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL

Esc键,输入:wq!,然后回车保存文件。

使环境变量立即生效,如下所示:

[root@db etc]# source /etc/profile

Active connection state: activated

Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/3

[root@db etc]#

如果防火墙已经打开,那么输入以下命令关闭防火墙:

systemctl stop firewalld.service

systemctl disable firewalld.service

如果企业用户没有网关防火墙则不建议直接关闭防火墙,而是增加端口规则。

PostgreSQL服务不允许以root身份启动,所以要切换到postgres用户。首先可看postgres用户是否存在。

[root@db etc]# cat /etc/passwd | grep -i postgres

postgres:x:26:26:PostgreSQL Server:/var/lib/pgsql:/bin/bash

[root@db etc]#

如果输出为空则表示用户不存在,需要新建用户。如果已经存在,则需要修改用户密码。用户密码需要分两步修改。首先修改系统的postgres用户的密码:

[root@db etc]# passwd postgres

Changing password for user postgres.

New password:

Retype new password:

passwd: all authentication tokens updated successfully.

[root@db etc]#

切换到postgres用户:

[root@db etc]# su postgres

bash-4.1$

尝试重启或启动PostgreSQL服务

bash-4.1$ pg_ctl restart

pg_ctl: PID file "/var/lib/pgsql/9.4/data/postmaster.pid" does not exist

Is server running?

starting server anyway

pg_ctl: could not read file "/var/lib/pgsql/9.4/data/postmaster.opts"

bash-4.1$ pg_ctl start

server starting

bash-4.1$ < 2016-06-28 23:46:04.688 CST >LOG: redirecting log output to logging collector process

< 2016-06-28 23:46:04.688 CST >HINT: Future log output will appear in directory "pg_log".

bash-4.1$

注意服务启动成功时命令行没有返回用户的bash,按一下回车即可。

进入psql命令行:

bash-4.1$ psql

psql (9.4.8)

Type "help" for help.

postgres=#

修改数据库的postgres用户的密码:

alter user postgres with password '最好与系统的用户密码相同';

命令中的红色文字请自行更改为您自己的密码,然后执行命令,如下所示:

postgres=# alter user postgres with password '不告诉你^_^^_^';

ALTER ROLE

postgres=#

退出测试一下:

postgres=# \q

bash-4.1$ psql -h 192.168.8.155 -p 5432 -d postgres -U postgres -W

Password for user postgres:

psql (9.4.8)

Type "help" for help.

postgres=#

至此可以用pgAdmin工具远程登录数据库系统了。

安装PostGIS

首选检查PostGIS是否存在源列表中:

postgres=# \q

bash-4.1$ exit

exit

[root@db etc]# yum list | grep -i postgis

postgis.x86_64 1.3.6-1.el6.rf rpmforge

postgis-utils.x86_64 1.3.6-1.el6.rf rpmforge

postgis2_94.x86_64 2.1.8-1.rhel6 pgdg94

postgis2_94-client.x86_64 2.1.8-1.rhel6 pgdg94

postgis2_94-debuginfo.x86_64 2.1.8-1.rhel6 pgdg94

postgis2_94-devel.x86_64 2.1.8-1.rhel6 pgdg94

postgis2_94-docs.x86_64 2.1.8-1.rhel6 pgdg94

postgis2_94-utils.x86_64 2.1.8-1.rhel6 pgdg94

[root@db etc]#

尝试安装:

[root@db etc]# yum install postgis2_94

如果出现这些提示,则表示缺少依赖项:

Error: Package: gdal-libs-1.9.2-7.rhel6.x86_64 (pgdg94)

Requires: libnetcdf.so.6()(64bit)

Error: Package: gdal-libs-1.9.2-7.rhel6.x86_64 (pgdg94)

Requires: libdap.so.11()(64bit)

Error: Package: gdal-libs-1.9.2-7.rhel6.x86_64 (pgdg94)

Requires: libspatialite.so.2()(64bit)

Error: Package: gdal-libs-1.9.2-7.rhel6.x86_64 (pgdg94)

Requires: libfreexl.so.1()(64bit)

Error: Package: gdal-libs-1.9.2-7.rhel6.x86_64 (pgdg94)

Requires: libdapserver.so.7()(64bit)

Error: Package: gdal-libs-1.9.2-7.rhel6.x86_64 (pgdg94)

Requires: libCharLS.so.1()(64bit)

Error: Package: gdal-libs-1.9.2-7.rhel6.x86_64 (pgdg94)

Requires: libarmadillo.so.4()(64bit)

You could try using --skip-broken to work around the problem

You could try running: rpm -Va --nofiles --nodigest

从网上下载epel-release-6-8.noarch.rpm,放到F盘根目录。下载地址是:

http://dl.fedoraproject.org/pub/epel/6/x86_64/epel­release­6­8

pscp工具上传到远程服务器,如下所示:

C:\Users\xuesongshu>pscp f:\epel-release-6-8.noarch.rpm root@192.168.8.155:/home/postgis

root@192.168.8.155's password:

epel-release-6-8.noarch.r | 14 kB | 14.2 kB/s | ETA: 00:00:00 | 100%

C:\Users\xuesongshu>

安装epel-release-6-8.noarch.rpm,如下所示:

[root@db etc]# cd /home/postgis

[root@db postgis]# rpm -ivh epel-release-6-8.noarch.rpm

warning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256 Signature,key ID 0608b895: NOKEY

Preparing... ########################################### [100%]

1:epel-release ########################################### [100%]

[root@db postgis]#

再次运行:

[root@db postgis]# yum install postgis2_94

静静等待下载安装即可,等待时间取决于网速。在所有的询问中一律输入Y,最后安装成功时如下所示:

Complete!

[root@db postgis]#

测试建立空间数据库:

-bash-4.1$ psql -c "CREATE DATABASE test01;"

CREATE DATABASE

-bash-4.1$ psql -d test01 -c "CREATE EXTENSION postgis;"

CREATE EXTENSION

-bash-4.1$ psql -d test01

psql (9.4.8)

输入 "help" 来获取帮助信息.

test01=# select postgis_full_version();

注意: Function postgis_topology_scripts_installed() not found. Is topology support enabled and topology.sql installed?

postgis_

full_version

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

-----

POSTGIS="2.1.8 r13780" GEOS="3.4.2-CAPI-1.8.2 r3921" PROJ="Rel. 4.8.0,6 March

2012" GDAL="GDAL 1.9.2,released 2012/10/08" LIBXML="2.7.6" LIBJSON="UNKNOWN" RA

STER

(1 行记录)

test01=#

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


#使用军哥的lnmp配置虚拟主机,需要注意的是要配置hosts文件(这一点官方没有讲到)具体方法:1、修改hosts文件sudo vim /etc/hosts2、在hosts文件中新增一行(这里类似于windows上配置hosts文件)127.0.0.1 www.baidu.com3、保存并重启网络
一、配置编译环境 yum update &amp;&amp; yum upgrade yum groupinstall &quot;Development Tools&quot; yum install gcc gcc-c++ pcre* openssl* gd-devel* zlib-devel
一、下载repo文件 二、备份并替换系统的repo文件 三、执行yum源更新操作
LAMP -- Linux Apache MySQL PHP 在CentOS安装的顺序,我一般是Apache&#160;-&gt;&#160;MySQL&#160;-&gt;&#160;PHP 第一步、安装并配置Apache 1、使用yum安装 [plain]&#160;view plaincopy
一、下载nginx安装包,官网下载中心http://nginx.org/download [root@localhost software]# wget http://nginx.org/download/nginx-1.10.1.tar.gz 二、解压nginx安装包 [root@localhos
1.下载composer curl -sS https://getcomposer.org/installer | php ps:如果出现php无法运行的情况,请先把PHP加入环境变量,具体操作参考《centOS安装PHP》 2.移动或复制composer到环境下可执行 cp composer.ph
一、卸载旧版本的vim 二、安装终端字符处理库ncurses 三、下载Vim8 四、编译安装 五、添加到系统环境变量 六、安装成功
引言 我们在日常的开发过程中,很多时候需要连接服务器查看日志或者在服务器上调试代码。但是,使用 ssh 命令登录服务器每次都需要输出密码,就比较繁琐。因此我们可以使用 sshpass 通过参数指定密码进行登录。解决了这个问题之后,我发现登录服务器之后,还需要手动 cd 切换到项目目录或者日志目录。为
iptables basics Introduction iptables 是一个配置 Linux 防火墙的工具,是 netfilter 项目的一部分。 在 Linux Kernel 3.13 及以上版本中, nftables 将作为后继者取代 iptables 以成为更强大易用的防火墙工具 Bas
一、下载tengine 二、安装tenginx(nginx)的模块依赖库 三、解压并指定安装路径 四、编译安装 五、启动(tengine)nginx 六、访问(tengine)nginx
这篇文章介绍了如何快速部署一套Kubernetes集群,下面就快速开始吧! 准备工作 机器部署规划 主机 | IP | 部署组件 | | master主节点 | 192.168.199.206 | etcd、kube apiserver、kube controller manager、kube sc
一、pip下载 二、解压安装 三、安装完成
1、WebBench安装: yum install ctags(先安装依赖库) mkdir /usr/local/man (创建一个目录不然会报错) wget http://home.tiscali.cz/~cz210552/distfiles/webbench-1.5.tar.gz tar zxv
1:查看环境: [root@10-4-14-168 html]# cat /etc/redhat-release CentOS release 6.5 (Final) 2:关掉防火墙 [root@10-4-14-168 html]# chkconfig iptables off 3:配置CentOS
安装 1.检查当前是否有安装php rpm&#160;-qa|grep&#160;php 如果有安装PHP,那么请先删除这些安装包: yum&#160;remove&#160;php* 2.安装php源 Centos 5 安装php源: rpm&#160;-ivh&#160;http://mirro
一、安装 二、配置 三、修改配置文件 四、program 配置 五、启动
Sed 日常使用介绍 简介 是 环境下常用的流处理工具, 可以处理字符流, 文件或者二进制文件流。 各个 发行版都会配备 及其衍生的命令工具, 因此, 掌握该工具的基本用法, 足以满足我们日常的许多文本处理的任务。 以下采用示例的方式对 进行基本用法介绍. 如果有兴趣了解更高级的使用技巧, 本文采用
linux下开机自启: 在/etc/init.d目录下新建文件elasticsearch 并敲入shell脚本: 注意, 前两行必须填写,且要注释掉。 第一行为shell前行代码,目的告诉系统使用shell。 第二行分别代表运行级别、启动优先权、关闭优先权,且后面添加开机服务会用到。 shell脚本
1、因为在centos7中/etc/rc.d/rc.local的权限被降低了,所以需要赋予其可执行权 chmod +x /etc/rc.d/rc.local 2、赋予脚本可执行权限假设/usr/local/script/autostart.sh是你的脚本路径,给予执行权限 chmod +x /usr
最简单的查看方法可以使用ls -ll、ls-lh命令进行查看,当使用ls -ll,会显示成字节大小,而ls- lh会以KB、MB等为单位进行显示,这样比较直观一些。 通过命令du -h –max-depth=1 *,可以查看当前目录下各文件、文件夹的大小,这个比较实用。 查询当前目录总大小可以使用d