系统:CentOS 7.2php
:tw-26a0: Never, ever run the installation as a root user.
经过root用户将一个普通用户joe加入sudoer,解决 xxx is not in the sudoers file。命令:html
visudo
Note: these installation instructions are also available in executable form for use with vagrant under vagrant/Install-on-Centos-7.sh
https://github.com/openstreetmap/Nominatim/blob/master/vagrant/Install-on-Centos-7.shnode
A minimum of 2GB of RAM is required or installation will fail. For a full planet import 32GB of RAM or more strongly are recommended.python
For a full planet install you will need about 500GB of hard disk space (as of June 2016, take into account that the OSM database is growing fast). SSD disks will help considerably to speed up import and queries.linux
On a 6-core machine with 32GB RAM and SSDs the import of a full planet takes a bit more than 2 days. Without SSDs 7-8 days are more realistic.nginx
#更新软件包 sudo yum update -y #The standard CentOS repositories don't contain all the required packages,Enable the EPEL repository sudo yum install -y epel-release #安装软件 sudo yum install postgresql-server postgresql-contrib postgresql-devel postgis postgis-utils git cmake make gcc gcc-c++ libtool policycoreutils-python php-pgsql php php-pear php-pear-DB php-intl libpqxx-devel proj-epsg bzip2-devel proj-devel geos-devel libxml2-devel boost-devel expat-devel zlib-devel
For compiling:c++
For running Nominatim:git
:tw-26a0: Note that you must install php5, php7 does not work.github
For running continuous updates:web
#查看PHP版本 php -v #查看PostgreSQL版本 psql --version #查看PostGIS版本 rpm -qa | grep postgis
Nominatim will run as a global service on your machine. It is therefore best to install it under its own separate user account. In the following we assume this user is called nominatim
and the installation will be in /srv/nominatim
. To create the user and directory
#建立帐号并设置目录 sudo useradd -d /srv/nominatim -s /bin/bash -m nominatim export USERNAME=nominatim export USERHOME=/srv/nominatim #Make sure that system servers can read from the home directory: chmod a+x $USERHOME
#初始化 sudo postgresql-setup initdb sudo systemctl enable postgresql
#修改PostgreSQL默认配置 vim /var/lib/pgsql/data/postgresql.conf
添加或修改以下内容:
fsync = off full_page_writes = off shared_buffers (2GB) maintenance_work_mem (10GB) work_mem (50MB) effective_cache_size (24GB) synchronous_commit = off checkpoint_segments = 100 # only for postgresql <= 9.4 checkpoint_timeout = 10min checkpoint_completion_target = 0.9
:tw-26a0: Don't forget to reenable fsync
full_page_writes
after the initial import or you risk database corruption. Autovacuum must not be switched off because it ensures that the tables are frequently analysed.
#重启PostgreSQL数据库 sudo systemctl restart postgresql
建立三个PostgreSQL数据库用户:
one for the user that does the import;
another for the webserver which should access the database only for reading:
another for the website user www-data as a PostgreSQL database role
sudo -u postgres createuser -s $USERNAME sudo -u postgres createuser apache sudo -u postgres createuser -SDR www-data
You need to create an alias to the website directory in your apache configuration. Add a separate nominatim configuration to your webserver:
sudo tee /etc/httpd/conf.d/nominatim.conf << EOFAPACHECONF <Directory "$USERHOME/Nominatim/build/website"> Options FollowSymLinks MultiViews AddType text/html .php DirectoryIndex search.php Require all granted </Directory> Alias /nominatim $USERHOME/Nominatim/build/website EOFAPACHECONF
#重启Apache服务器 sudo systemctl restart httpd
It is a good idea to leave SELinux enabled and enforcing, particularly with a web server accessible from the Internet. At a minimum the following SELinux labeling should be done for Nominatim:
sudo semanage fcontext -a -t httpd_sys_content_t "$USERHOME/Nominatim/(website|lib|settings)(/.*)?" sudo semanage fcontext -a -t lib_t "$USERHOME/Nominatim/module/nominatim.so" sudo restorecon -R -v $USERHOME/Nominatim
#进入/srv/nominatim目录,获取源码 cd $USERHOME git clone --recursive git://github.com/openstreetmap/Nominatim.git cd Nominatim #When installing the latest source from github, you also need to download the country grid: wget -O data/country_osm_grid.sql.gz http://www.nominatim.org/data/country_grid.sql.gz #The code must be built in a separate directory. mkdir build cd build cmake $USERHOME/Nominatim make
create a minimal configuration file that tells nominatim the name of your webserver user and the URL of the website:
tee settings/local.php << EOF <?php @define('CONST_Database_Web_User', 'apache'); @define('CONST_Website_BaseURL', '/nominatim/'); EOF
If you plan to import a large dataset (e.g. Europe, North America, planet), you should also enable flatnode storage of node locations. With this setting enabled, node coordinates are stored in a simple file instead of the database.Add to your /srv/nominatim/Nominatim/build/settings/local.php
#由于我导入的地图数据较小,未设置该项 @define('CONST_Osm2pgsql_Flatnode_File', '/srv/nominatim/Nominatim/data/flatnode.file');
:tw-26a0: Replace the second part with a suitable path on your system and make sure the directory exists. There should be at least 35GB of free space.
Wikipedia can be used as an optional auxiliary data source to help indicate the importance of osm features. Nominatim will work without this information but it will improve the quality of the results if this is installed.
cd /srv/nominatim/Nominatim/data wget http://www.nominatim.org/data/wikipedia_article.sql.bin wget http://www.nominatim.org/data/wikipedia_redirect.sql.bin
Combined the 2 files are around 1.5GB and add around 30GB to the install size of nominatim. They also increase the install time by an hour or so.
Nominatim can use postcodes from an external source to improve searches that involve a UK postcode.
cd /srv/nominatim/Nominatim/data wget http://www.nominatim.org/data/gb_postcode_data.sql.gz
Important: first try the import with a small excerpt, for example from Geofabrik.
数据能够从Geofabrik下载,建议下载.osm.pbf格式。
#下载中国的数据 cd /srv/nominatim/Nominatim/data wget http://download.geofabrik.de/asia/china-latest.osm.pbf #导入数据 cd /srv/nominatim/Nominatim/build ./utils/setup.php --osm-file ../data/china-latest.osm.pbf --all 2>&1 | tee setup.log #
:tw-26a0: The --osm2pgsql-cache
parameter is optional but strongly recommended for planet imports. It sets the node cache size for the osm2pgsql import part (see -C
parameter in osm2pgsql help). 28GB are recommended for a full planet import, for excerpts you can use less. Adapt to your available RAM to avoid swapping, never give more than 2/3 of RAM to osm2pgsql.当导入的数据十分大时(好比超过1GB)建议使用如下命令:
./utils/setup.php --osm-file ../data/china-latest.osm.pbf --all [--osm2pgsql-cache 28000] 2>&1 | tee setup.log
完成导入数据大概须要1个小时!!!
The following commands will create additional entries for POI searches:
cd /srv/nominatim/Nominatim/build ./utils/specialphrases.php --wiki-import > specialphrases.sql psql -d nominatim -f specialphrases.sql
There are many different possibilities to update your Nominatim database. The following section describes how to keep it up-to-date with Pyosmium. For a list of other methods see the output of
cd /srv/nominatim/Nominatim/build ./utils/update.php --help
It is recommended to install Pyosmium via pip:
pip install --user osmium
Nominatim needs a tool called pyosmium-get-updates
that comes with Pyosmium. You need to tell Nominatim where to find it. Add the following line to your build/settings/local.php
:
@define('CONST_Pyosmium_Binary', '/home/user/.local/bin/pyosmium-get-changes');
The path above is fine if you used the --user
parameter with pip. Replace user
with your user name.
Next the update needs to be initialised. By default Nominatim is configured to update using the global minutely diffs.
If you want a different update source you will need to add some settings to build/settings/local.php
. For example, to use the daily country extracts diffs for Ireland from geofabrik add the following:
// base URL of the replication service @define('CONST_Replication_Url', 'http://download.geofabrik.de/europe/ireland-and-northern-ireland-updates'); // How often upstream publishes diffs @define('CONST_Replication_Update_Interval', '86400'); // How long to sleep if no update found yet @define('CONST_Replication_Recheck_Interval', '900');
To set up the update process now run the following command:
cd /srv/nominatim/Nominatim/build ./utils/update --init-updates
It outputs the date where updates will start. Recheck that this date is what you expect.
The --init-updates command needs to be rerun whenever the replication service is changed.
The following command will keep your database constantly up to date:
cd /srv/nominatim/Nominatim/build ./utils/update.php --import-osmosis-all
If you have imported multiple country extracts and want to keep them up-to-date, have a look at the script in issue #60.
1.https://github.com/openstreetmap/Nominatim/blob/master/docs/Install-on-Centos-7.md
2.https://github.com/openstreetmap/Nominatim/blob/master/docs/Import-and-Update.md
3.https://github.com/openstreetmap/Nominatim/blob/master/docs/Installation.md
1.https://github.com/openstreetmap/Nominatim/blob/master/docs/Faq.md
2.http://wiki.openstreetmap.org/wiki/Nominatim/Installation/Troubleshooting
3.ERROR: permission denied for relation
参考
#切换用户 su - nominatim 进入PostgreSQL psql #使用nominatim数据库 \c nominatim #给apache用户赋予权限 GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO apache;
比较好的解决方案:(最后的操做:把用户readonly改成apache,或者修改build/settings/local.php
中CONST_Database_Web_User
为readonly)
CREATE USER readonly WITH ENCRYPTED PASSWORD 'readonly'; GRANT USAGE ON SCHEMA public to readonly; ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonly; #在每一个数据库上重复如下代码,以nominatim数据库为例: GRANT CONNECT ON DATABASE nominatim to readonly; \c nominatim ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO readonly; #this grants privileges on new tables generated in new database "nominatim" GRANT USAGE ON SCHEMA public to readonly; GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO readonly; GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly;
1.http://localhost/nominatim 2.逆地理编码查询 http://localhost/nominatim/reverse?format=xml&lat=31&lon=121&zoom=18&addressdetails=1