ubuntu16.04 安装nominatim 实现离线逆地理解析服务

首先!the first!!!

强烈推荐一篇很有质量的博文:https://blog.csdn.net/u013719339/article/details/53908990

我是根据该博客配置的,博主是一个很有实力又很热心的大神!帮我解答一些疑惑,实在太感谢了!



开始我的搭建Nominatim 之旅

背景:大数据项目中,大量的gps需要解析成地理位置,用第三方接口显然是不现实的,主要是收费和调用次数的限制。所以被迫自力更生搭建逆打理编码的服务,经历了自己根据经纬度换算地址、geopy的失败,直到查到了openstreemap,它有一个在github开源的项目–Nominatim,和大量的全球数据,可以提供地理正反解析、线路规划等等服务。而我需要的就只有逆地理解析一个服务!官网的资料:http://nominatim.org/release-docs/latest/admin/Installation/ ,尽管我的英语还很自信,可是看的一头雾水!还是别看了,很容易被误导,为此还搞得重装系统。总之,这几天对于一个传统的java民工,去使用从未接触过的php、postgresql是有多么痛苦!!!

准备环境

先来看看最终结果

这里写图片描述

逆地理解析示例

这里写图片描述

安装过程

  • 安装必须的软件,必须全部手敲!不要复制!
    用户状态:普通用户
sudo apt-get update
sudo apt-get install build-essential wget
sudo apt-get install libxml2-dev wget
sudo apt-get install libpq-dev wget
sudo apt-get update
sudo apt-get install libbz2-dev wget
sudo apt-get install libtool wget
sudo apt-get install automake wget
sudo apt-get install libproj-dev wget
sudo apt-get install libboost-dev wget
sudo apt-get install libboost-system-dev wget
sudo apt-get install libboost-filesystem-dev wget
sudo apt-get install libboost-thread-dev wget
sudo apt-get install libexpat-dev wget
sudo apt-get install gcc wget
sudo apt-get install proj-bin wget
sudo apt-get install libgeos-c1v5 wget
sudo apt-get install libgeos++-dev wget
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt update
sudo apt install php5.6
sudo apt install libapache2-mod-php5.6
sudo apt install php5.6-curl
sudo apt install php5.6-gd
sudo apt install php5.6-mbstring
sudo apt install php5.6-mcrypt
sudo apt install php5.6-mysql
sudo apt install php5.6-xml
sudo apt install php5.6-xmlrpc
sudo a2dismod php7.0
sudo a2enmod php5.6
sudo systemctl restart apache2
sudo apt-get install php-pear wget
sudo apt-get install php5.6-pgsql wget
sudo apt-get install php5.6-json wget
sudo apt-get install php5.6-db wget
sudo apt-get install osmosis wget
sudo apt-get install postgresql-9.5 wget
sudo apt-get install postgis
sudo apt-get install postgresql-contrib-9.5 wget
sudo apt-get install postgresql-server-dev-9.5 wget
sudo apt-cache search postgres
sudo apt-get install postgresql-9.5-postgis-2.2
sudo apt-get install libprotobuf-c0-dev
sudo apt-get install protobuf-c-compiler
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-client-9.5
sudo apt-get install pgadmin3
  • 添加postgres用户
    用户状态:普通用户
sudo -u postgres psql postgres  
\password postgres  
(输入密码,就postgres吧,好记)
\q  
  • 配置postgres
    用户状态:普通用户
sudo gedit /etc/postgresql/9.5/main/postgresql.conf

去掉 “#” 号,修改参数

shared_buffers = 2GB                             113
work_mem = 50MB                                  122
maintenance_work_mem = 10GB                      123
fsync = off                                      173
synchronous_commit= off                          174
full_page_writes = off                           183
checkpoint_timeout = 10min                       196
checkpoint_completion_target = 0.9               199
effective_cache_size = 24GB                      289
  • 编译Nominatim

    • 下载后统一放到 /opt目录下
    • 解压
      tar xvf /opt/Nominatim-2.5.1.tar.bz2
    • 检查编译条件
      cd /opt/Nominatim-2.5.1
      ./configure
      在这一步中,如果结尾出现报”lua<=5.2”的警告,说明是可以编译的,若是其它信息,仔细看,缺少哪个必须的软件就安装那个(一般是必须软件那里漏了)
    • 编译
      make
  • 创建导入账户,用于导入数据
    用户状态:先是普通用户,创建完test用户后,切换到test用户

sudo -u postgres createuser -s test   (postgres的)
sudo adduser test                      (系统的)
(test密码随意,123456)
su root
chmod 777 /etc/sudoers
vi /etc/sudoers
在”root    ALL=(ALL) ALL “下添加:test    ALL=(ALL) ALL
然后保存退出,再修I改回sudoers的状态
chmod 440 /etc/sudoers
exit
su test               
createuser -SDR www-data              (创建postgres用户)

这时,可以在终端输入 pgadmin3, 会弹出一个admin界面,管理postgres的,密码是postgres(上面已经创建好了),然后在最下边会看到3个用户:postgres是超级用户, test是导入数据用的,www-data是网站访问的

这里写图片描述

  • 导入数据
    用户状态:test
cd /opt/Nominatim-2.5.1/utils/
./setup.php --osm-file /opt/taiwan-latest.osm.pbf --all   (我这里方便测试,只下载了台湾省的数据)

注意:
(1)这里,如果刚执行命令时报 php找不到DB的错误,执行sudo pear install DB
(2)如果是导入过程中出现错误,要删除数据库再重新导入, 删除命令为: sudo -u postgres dropdb nominatim

  • 配置网站
    用户状态:test
cd /opt/Nominatim-2.5.1/settings
touch local.php
gedit local.php
在local.php添加如下内容:
<?php
// Paths
@define('CONST_Postgresql_Version', '9.5');
@define('CONST_Postgis_Version', '2.2');
// Website settings
@define('CONST_Website_BaseURL', 'http://localhost/nominatim/');
  • 创建网站目录
    用户状态:test
sudo mkdir -m 755 /var/www/html/nominatim  
sudo chmod 777 /var/www/html/nominatim 
/opt/Nominatim-2.5.1/utils/setup.php --create-website /var/www/html/nominatim  
  • 配置apache环境
    用户状态:test
sudo gedit /etc/apache2/sites-enabled/000-default.conf
在</VirtualHost>之上添加:
<Directory "/var/www/html/nominatim/">
       Options FollowSymLinks MultiViews
       AddType text/html   .php
</Directory>
  • 最后修改数据库的权限
    用户状态:test
psql template1  
GRANT ALL PRIVILEGES ON DATABASE nominatim to test             
\q  
exit  

到此为止,就可以在本地访问了:http://localhost/nominatim/ , 至于局域网的配置,明天再折腾。

猜你喜欢

转载自blog.csdn.net/change_on/article/details/79795206