2020/12,江端さんの技術メモ

Tile38

Slack Channel Docker Ready

Tile38 is an open source (MIT licensed), in-memory geolocation data store, spatial index, and realtime geofence. It supports a variety of object types including lat/lon points, bounding boxes, XYZ tiles, Geohashes, and GeoJSON.

Tile38は、オープンソース(MITライセンス)で、インメモリのジオロケーションデータストア、空間インデックス、リアルタイムジオフェンスです。緯度/経度ポイント、バウンディングボックス、XYZタイル、Geohash、GeoJSONを含む様々なオブジェクトタイプをサポートしています。

This README is quick start document. You can find detailed documentation at https://tile38.com.

このREADMEはクイックスタートのドキュメントです。詳細なドキュメントはhttps://tile38.com.

Nearby Within Intersects Geofencing Roaming Geofences

Features

特徴

Components

  • tile38-server - The server → サーバ
  • tile38-cli - Command line interface tool → コマンドインターフェースツール
  • tile38-benchmark - Server benchmark tool → サーバベンチマークツール

Getting Started

はじめに

Getting Tile38

タイル38の取得

Perhaps the easiest way to get the latest Tile38 is to use one of the pre-built release binaries which are available for OSX, Linux, FreeBSD, and Windows. Instructions for using these binaries are on the GitHub releases page. → 最新のTile38を入手する最も簡単な方法は、OSX、Linux、FreeBSD、Windows用に提供されているビルド済みのリリースバイナリを使用することでしょう。これらのバイナリの使い方は、GitHub release pageにあります。

Docker

To run the latest stable version of Tile38:→Tile38の最新の安定版を実行する。

docker pull tile38/tile38
docker run -p 9851:9851 tile38/tile38

Visit the Tile38 hub page for more information. → 詳しくはTile38ハブページをご覧ください。

Homebrew (macOS)

Install Tile38 using Homebrew →Homebrew](https://brew.sh/)を使ってTile38をインストールします。

brew install tile38
tile38-server

Building Tile38

タイル38の構築

Tile38 can be compiled and used on Linux, OSX, Windows, FreeBSD, and probably others since the codebase is 100% Go. We support both 32 bit and 64 bit systems. Go must be installed on the build machine.

Tile38は、コードベースが100%Goなので、Linux、OSX、Windows、FreeBSD、そしておそらく他のOSでもコンパイルして使うことができます。32ビットと64ビットの両方をサポートしています。ビルドマシンにはGoがインストールされている必要があります。

To build everything simply:

すべてをシンプルに構築する為に

$ make

To test:

$ make test

Running

実行

For command line options invoke: コマンドラインオプションの場合は、次を呼び出します。

$ ./tile38-server -h

To run a single server:

$ ./tile38-server

# The tile38 shell connects to localhost:9851
$ ./tile38-cli
> help

Playing with Tile38

Basic operations: 基本操作:

$ ./tile38-cli

# add a couple of points named 'truck1' and 'truck2' to a collection named 'fleet'.
#「fleet」という名前のコレクションに「truck1」および「truck2」という名前のポイントをいくつか追加します。
> set fleet truck1 point 33.5123 -112.2693   # on the Loop 101 in Phoenix
> set fleet truck2 point 33.4626 -112.1695   # on the I-10 in Phoenix

# search the 'fleet' collection.
#「フリート」コレクションを検索します。
> scan fleet                                 # returns both trucks in 'fleet'
> nearby fleet point 33.462 -112.268 6000    # search 6 kilometers around a point. returns one truck.

# key value operations
# キー値操作
> get fleet truck1                           # returns 'truck1'
> del fleet truck2                           # deletes 'truck2'
> drop fleet                                 # removes all 

Tile38 has a ton of great commands. Tile38にはたくさんの[すばらしいコマンド](https://tile38.com/commands)があります。

Fields

フィールド

Fields are extra data that belongs to an object. A field is always a double precision floating point. There is no limit to the number of fields that an object can have.

フィールドは、オブジェクトに属する追加のデータです。 フィールドは常に倍精度浮動小数点です。 オブジェクトが持つことができるフィールドの数に制限はありません。

To set a field when setting an object: オブジェクトを設定するときにフィールドを設定するには:

> set fleet truck1 field speed 90 point 33.5123 -112.2693             
> set fleet truck1 field speed 90 field age 21 point 33.5123 -112.2693

To set a field when an object already exists: オブジェクトがすでに存在するときにフィールドを設定するには:

> fset fleet truck1 speed 90

Searching

検索

Tile38 has support to search for objects and points that are within or intersects other objects. All object types can be searched including Polygons, MultiPolygons, GeometryCollections, etc.

Tile38は、他のオブジェクト内または他のオブジェクトと交差するオブジェクトおよびポイントの検索をサポートしています。 Polygons、MultiPolygons、GeometryCollectionsなどを含むすべてのオブジェクトタイプを検索できます。

Search Within

Within

WITHIN searches a collection for objects that are fully contained inside a specified bounding area. WITHINは、指定された境界領域内に完全に含まれているオブジェクトをコレクションで検索します。

Search Intersects

Intersects

INTERSECTS searches a collection for objects that intersect a specified bounding area.

Search Nearby

Nearby

NEARBY searches a collection for objects that intersect a specified radius. INTERSECTSは、指定された境界領域と交差するオブジェクトをコレクションで検索します。

Search options

検索オプション

SPARSE - This option will distribute the results of a search evenly across the requested area.

** SPARSE **-このオプションは、検索結果を要求された領域全体に均等に分散します。

This is very helpful for example; when you have many (perhaps millions) of objects and do not want them all clustered together on a map. Sparse will limit the number of objects returned and provide them evenly distributed so that your map looks clean.

これは、非常に役立ちます。 多数(おそらく数百万)のオブジェクトがあり、それらすべてをマップ上にクラスター化したくない場合。 スパースは、返されるオブジェクトの数を制限し、マップがきれいに見えるようにそれらを均等に分散させます。

You can choose a value between 1 and 8. The value 1 will result in no more than 4 items. The value 8 will result in no more than 65536. 1=4, 2=16, 3=64, 4=256, 5=1024, 6=4098, 7=16384, 8=65536.

1から8までの値を選択できます。値1は、4つ以下のアイテムになります。 値8は、65536以下になります。* 1 = 4、2 = 16、3 = 64、4 = 256、5 = 1024、6 = 4098、7 = 16384、8 =65536。*

>

No SparsingSearch WithinSparse 1Search WithinSparse 2Search WithinSparse 3Search WithinSparse 4Search WithinSparse 5Search Within

Please note that the higher the sparse value, the slower the performance. Also, LIMIT and CURSOR are not available when using SPARSE.

スパース値が高いほど、パフォーマンスが低下することに注意してください。 また、SPARSEを使用している場合、LIMITとCURSORは使用できません。

WHERE - This option allows for filtering out results based on field values. For example
nearby fleet where speed 70 +inf point 33.462 -112.268 6000 will return only the objects in the 懼fleet懼 collection that are within the 6 km radius and have a field named speed that is greater than 70.

Multiple WHEREs are concatenated as and clauses. WHERE speed 70 +inf WHERE age -inf 24 would be interpreted as speed is over 70 and age is less than 24.

The default value for a field is always 0. Thus if you do a WHERE on the field speed and an object does not have that field set, the server will pretend that the object does and that the value is Zero.

WHERE - このオプションは、fieldの値に基づいて結果をフィルタリングすることができます。例えば
`nearby fleet where speed 70 +inf point 33.462 -112.268 6000````は、半径6km以内にあるオブジェクトのみを返します。<br><br>複数のWHEREは**and**句として連結されます。<br><br>フィールドのデフォルト値は常に0です。したがって、フィールドspeed` の WHERE を実行したときに、オブジェクトにそのフィールドが設定されていない場合、サーバーはオブジェクトが設定されていて、その値がゼロであるかのように振舞うことになります。

MATCH - MATCH is similar to WHERE except that it works on the object id instead of fields.
nearby fleet match truck* point 33.462 -112.268 6000 will return only the objects in the 懼fleet懼 collection that are within the 6 km radius and have an object id that starts with truck. There can be multiple MATCH options in a single search. The MATCH value is a simple glob pattern.

nearby fleet match truck* point 33.462 -112.268 6000は、半径6km以内にある懼fリート懼コレクションのオブジェクトのうち、かつtruckで始まるオブジェクトIDを持つものだけを返します。1つの検索で複数のMATCHオプションを指定することができます。MATCHの値は単純なglob patternです。

CURSOR - CURSOR is used to iterate though many objects from the search results. An iteration begins when the CURSOR is set to Zero or not included with the request, and completes when the cursor returned by the server is Zero.

CURSOR - CURSORは、検索結果から多くのオブジェクトを繰り返し処理するために使用されます。CURSORが0に設定されているか、リクエストに含まれていない場合には反復処理が開始され、サーバから返されたカーソルが0になった時点で終了します。

NOFIELDS - NOFIELDS tells the server that you do not want field values returned with the search results.

NOFIELDS - NOFIELDSは、検索結果で返されるフィールド値を望まないことをサーバーに伝えます。

LIMIT - LIMIT can be used to limit the number of objects returned for a single search request.

LIMIT - LIMITは、1つの検索リクエストに対して返されるオブジェクトの数を制限するために使用することができます。

Geofencing

ジオフェンシング

Geofence animation A geofence is a virtual boundary that can detect when an object enters or exits the area. This boundary can be a radius, bounding box, or a polygon. Tile38 can turn any standard search into a geofence monitor by adding the FENCE keyword to the search.

ジオフェンスは、物体がその領域に入ったり出たりしたときに検出できる仮想的な境界です。この境界は、半径、境界ボックス、または多角形にすることができます。Tile38は、検索にFENCEキーワードを追加することで、標準的な検索をジオフェンスモニタに変えることができます。

Tile38 also allows for Webhooks to be assigned to Geofences.

*Tile38では、ジオフェンスにWebhooksを割り当てることもできます。

 

A simple example:

簡単な例です。

> nearby fleet fence point 33.462 -112.268 6000

This command opens a geofence that monitors the 懼fleet懼 collection. The server will respond with:

このコマンドは 懼fリート懼 コレクションを監視するジオフェンスを開きます。サーバは以下のように応答します。

{"ok":true,"live":true}

And the connection will be kept open. If any object enters or exits the 6 km radius around 33.462,-112.268 the server will respond in realtime with a message such as:

また、接続はオープンに保たれます。33.462,-112.268` 付近の半径6kmの範囲に何か物体が出入りすると、サーバはリアルタイムで次のようなメッセージを返します。

{"command":"set","detect":"enter","id":"truck02","object":{"type":"Point","coordinates":[-112.2695,33.4626]}}

The server will notify the client if the command is del | set | drop.

サーバは commanddel | set | drop の場合にクライアントに通知する。

  • del notifies the client that an object has been deleted from the collection that is being fenced.
  • del` は、フェンシングされているコレクションからオブジェクトが削除されたことをクライアントに通知します。
  • drop notifies the client that the entire collection is dropped.
  • drop` はコレクション全体が削除されたことをクライアントに通知する。
  • set notifies the client that an object has been added or updated, and when it懼s position is detected by the fence.
  • set` はオブジェクトが追加または更新されたことをクライアントに通知し、フェンスによってその位置が検出されたときにそのことを通知します。

The detect may be one of the following values.

detect` は以下の値のいずれかである。

  • inside is when an object is inside the specified area.
  • inside` はオブジェクトが指定された領域の内側にあるときのことである。
  • outside is when an object is outside the specified area.
  • outside` は、オブジェクトが指定された領域の外にあるときのことである。
  • enter is when an object that was not previously in the fence has entered the area.
  • enter`は、それまで柵の中に**なかったオブジェクトがエリア内に入ってきたときのことである。
  • exit is when an object that was previously in the fence has exited the area.
  • exit`は、以前にフェンスの中にあった***オブジェクトがエリア外に出たときのことである。
  • cross is when an object that was not previously in the fence has entered and exited the area.
  • クロス`とは、それまで柵の中になかったオブジェクトがエリアに入ってきて**エリアから出てきたときのことである。

These can be used when establishing a geofence, to pre-filter responses. For instance, to limit responses to enter and exit detections:

これらは、ジオフェンスを確立する際に、応答を事前にフィルタリングするために使用することができます。例えば、enterexit の検出に対して応答を制限することができます。

> nearby fleet fence detect enter,exit point 33.462 -112.268 6000

Pub/sub channels

パブ/サブチャンネル

Tile38 supports delivering geofence notications over pub/sub channels.

Tile38は、パブ/サブチャンネル上のジオフェンス通知の配信をサポートしています。

To create a static geofence that sends notifications when a bus is within 200 meters of a point and sends to the busstop channel:

バスがポイントから200メートル以内にいるときに通知を送信し、busstopチャンネルに送信する静的ジオフェンスを作成します。

> setchan busstop nearby buses fence point 33.5123 -112.2693 200

Subscribe on the busstop channel:

バストップチャンネルを購読してください。

> subscribe busstop

Object types

オブジェクトの種類

All object types except for XYZ Tiles and QuadKeys can be stored in a collection. XYZ Tiles and QuadKeys are reserved for the SEARCH keyword only.

XYZ TilesとQuadKeyを除くすべてのオブジェクトタイプは、コレクションに格納することができます。XYZ TilesとQuadKeyは、SEARCHキーワードのみに予約されています。

Lat/lon point

ラット/ロングポイント

The most basic object type is a point that is composed of a latitude and a longitude. There is an optional z member that may be used for auxiliary data such as elevation or a timestamp.

最も基本的なオブジェクト型は緯度と経度からなる点である。オプションの z メンバがあり、標高やタイムスタンプなどの補助データに使用することができます。

set fleet truck1 point 33.5123 -112.2693     # plain lat/lon
set fleet truck1 point 33.5123 -112.2693 225 # lat/lon with z member

Bounding box

バウンディングボックス

A bounding box consists of two points. The first being the southwestern most point and the second is the northeastern most point.

バウンディングボックスは2つの点で構成されています。1つ目は最も南西の点で、2つ目は最も北東の点です。

set fleet truck1 bounds 30 -110 40 -100

Geohash

ジオハッシュ

A geohash is a string representation of a point. With the length of the string indicating the precision of the point.

geohash は、点を文字列で表現したものです。文字列の長さは点の精度を表します。

set fleet truck1 hash 9tbnthxzr # this would be equivalent to 'point 33.5123 -112.2693'

GeoJSON

GeoJSON is an industry standard format for representing a variety of object types including a point, multipoint, linestring, multilinestring, polygon, multipolygon, geometrycollection, feature, and featurecollection.

GeoJSON](https://tools.ietf.org/html/rfc7946)は、点、多点、線条、多線条、多角形、マルチポリゴン、ジオメトリコレクション、フィーチャ、フィーチャコレクションなど、様々なオブジェクトタイプを表現するための業界標準フォーマットです。

* All ignored members will not persist.

* すべての無視されたメンバーは持続しません。

Important to note that all coordinates are in Longitude, Latitude order.

すべての座標は経度、緯度の順になっていることに注意してください。

set city tempe object {"type":"Polygon","coordinates":[[[0,0],[10,10],[10,0],[0,0]]]}

XYZ Tile

XYZタイル

An XYZ tile is rectangle bounding area on earth that is represented by an X, Y coordinate and a Z (zoom) level.

XYZタイルとは、X,Y座標とZ(ズーム)レベルで表現された地球上の矩形領域のことです。

Check out maptiler.org for an interactive example.

インタラクティブな例は maptiler.org をご覧ください。

QuadKey

A QuadKey used the same coordinate system as an XYZ tile except that the string representation is a string characters composed of 0, 1, 2, or 3. For a detailed explanation checkout The Bing Maps Tile System.

QuadKey は XYZ タイルと同じ座標系を使用しますが、文字列表現は 0, 1, 2, 3 で構成される文字列です。詳しい説明は Bing Maps Tile System をご覧ください。

Network protocols

ネットワークプロトコル

It懼s recommended to use a client library or the Tile38 CLI, but there are times when only HTTP is available or when you need to test from a remote terminal. In those cases we provide an HTTP and telnet options.

クライアントライブラリ](#client-libraries)またはTile38 CLIを使用することをお勧めしますが、HTTPしか利用できない場合や、リモート端末からテストする必要がある場合があります。そのような場合には、HTTPとtelnetオプションを用意しています。

HTTP

One of the simplest ways to call a tile38 command is to use HTTP. From the command line you can use curl. For example:

tile38コマンドを呼び出す最も簡単な方法の1つは、HTTPを使用することです。コマンドラインからcurlを使用することができます。例えば、以下のようになります。

# call with request in the body
curl --data "set fleet truck3 point 33.4762 -112.10923" localhost:9851

# call with request in the url path
curl localhost:9851/set+fleet+truck3+point+33.4762+-112.10923

Websockets

ウェブソケット

Websockets can be used when you need to Geofence and keep the connection alive. It works just like the HTTP example above, with the exception that the connection stays alive and the data is sent from the server as text websocket messages.

Websocket は、ジオフェンスして接続を維持する必要がある場合に使用することができます。これは上記の HTTP の例と同じように動作しますが、接続が生きていることと、データがテキストの Websocket メッセージとしてサーバーから送信されることを除いては、動作しません。

Telnet

There is the option to use a plain telnet connection. The default output through telnet is RESP.

プレーンなtelnet接続を使用するオプションがあります。telnetによるデフォルトの出力はRESPです。

telnet localhost 9851
set fleet truck3 point 33.4762 -112.10923
+OK

The server will respond in JSON or RESP depending on which protocol is used when initiating the first command.

サーバは、最初のコマンドを開始するときに使用されるプロトコルに応じて、JSONまたはRESPで応答します。

  • HTTP and Websockets use JSON.
  • HTTPとWebsocketsはJSONを使用しています。
  • Telnet and RESP clients use RESP.
  • Telnet と RESP クライアントは RESP を使用します。

Client Libraries

クライアントライブラリ

Tile38 uses the Redis RESP protocol natively. Therefore most clients that support basic Redis commands will in turn support Tile38. Below are a few of the popular clients.

Tile38はRedis RESPプロトコルをネイティブに使用します。そのため、基本的なRedisコマンドをサポートしているほとんどのクライアントがTile38をサポートしています。以下に人気のあるクライアントをいくつか紹介します。

Contact

連絡先

Josh Baker [@tidwall](https://twitter.com/tidwall)

License

ライセンス

Tile38 source code is available under the MIT License.

Tile38のソースコードはMIT Licenseで公開されています。

2020/12,江端さんの技術メモ

キッチンの蛍光管を交換しても点灯しなくなったことから、どうやら安定器(スターター)が不調になってきているとアタリを付けました。

そもそも、この家を作った時には、LED電球という考え方すらなく、今のように蛍光管の代替となるLED直管ライトなどは、影も形もありませんでした。

で、この機会に、スターターをバイパス(無視)して、LED直管ライトを接続できるように、回路を変更してやろうと思ったのですが、そもそも、蛍光管も、LED直管ライトも、その仕組みがよく分っていません(ネットの情報も、これといったものが見つかりませんでした)。

で、今回、「オーム電機 LED蛍光灯 直管形LEDランプ G13 40形 昼光色 グロー専用 LDF40SS・D/17/23」を使って調べてみました。

https://www.youtube.com/watch?v=ne2NLdvOvSI
 

これで、ざっくりと結線のやり方が分かりました。

 

赤丸のところにマイナスドライバーを差し込むと、配線が外れました。

配線の番号はこのようになっています(ネットで仕様書を調べて、アタリを付けています)

これを、以下のように変更します。電子安定器に接続された結線は、すべて外して(あるいは切断して)下さい。

結線を外す前に配線の番号をタグ付けしておきます。

今回は、半田付けが難しかったので、こういう接合具を使って結線しました。外被を向いた動線を差し込んで、ペンチで金属部を押し潰します。

結線して、点灯を確認しました。

これで、安定器(スターター)は不要となりました。待機電力の消費もなくなるので、少しは節電になるでしょう。

注意事項:LED直管ライトの方向を逆にするとショートします。映像の中で見たように、逆方向は短絡しているからです。結線の中にヒューズを入れておくべきです(私も今、気がつきましたので、後日対応しておきます)。

2020/11,江端さんの技術メモ

「無理せんと、リバースプロキシ(nginx)使えば?」

で、nginxで、外向きにはhttps, 内側はhttpという nginx.confを作りました。

今回は、nginxがdockerのコンテナですでに稼動中のプログラムで、これを試してみました。

まず、docker-compose.ymlですが、まず、docker-compose.ymlと同じディレクトリに、algo.crtとalgo.keyを放り込んでおいて、portsとvolumesを以下のように変更します。

(前略)
nginx:
    image: nginx:1.15-alpine
    ports:
      - "80:80"    ←ここ      
      - "443:443"   ←ここ      
    links:
      - app:app
    volumes:
      - "./nginx.conf:/etc/nginx/conf.d/default.conf"
      - "./algo.crt:/etc/nginx/conf.d/algo.crt"  ←ここ  
      - "./algo.key:/etc/nginx/conf.d/algo.key"  ←ここ  

portsは、"443:80"と記載するのが正解じゃないかなーと思うのですが、上手く動かなかったので、理由は不明ですが上記のように記載しました。

最後の2行ですが、これはnginxのdockerのコンポーネントの中に強制的にリンクするものらしいのです。少なくとも、dockerのコンポーネントの中に、/etc/nginx/conf.d/ は存在しているようなので、もう適当に、そこにリンクを張ることにしました。(いや、"docker container exec -it nginx_1 sh "等で、コンテナに入って確認すれば良いですが、なんか上手く入れないことがありましてですね)

また、docker-compose.ymlと同じディレクトリに(最初から)入っている、nginx.confを以下のよう改造します。

server { 
 listen 80 default_server;  ←ここ   listen [::]:80 default_server;  ←ここ   return 301 https://$host$request_uri;  ←ここ   } server {  # listen 80 default_server; # listen [::]:80 default_server; listen 443; ←ここ server_name localhost; ←ここ ssl on; ←ここ ssl_certificate /etc/nginx/conf.d/algo.crt; ←ここ # https://wp.kobore.net/2020/09/post-1124/で作ったもの ssl_certificate_key /etc/nginx/conf.d/algo.key; ←ここ # 同上  client_max_body_size 1M; root /go/hitachi_ride_hailing_go/static; # これが良く分からんのだが (app_1の方のディレクトリみたいなんだよなぁ)  location / { index index.html index.htm; proxy_pass_header Server; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; if (!-f $request_filename) { proxy_pass http://app:8000; } } location /ws { proxy_pass http://app:8000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Frame-Options SAMEORIGIN; # リバースプロキシするサーバーから応答が無くとも、接続を切断しない上限の秒数 # http://zaiste.net/2014/12/nginx_websockets_proxy_for_nodejs/ proxy_read_timeout 86400; } }

なんだか分からんけど、太線(←ここ)の所を直したら、https://で通信できるようになったみたいです。

(多分、静的なhtmlファイルの表示だけなら問題はないでしょう)。

あ、忘れていましたが、

JSONのデータを直接受けるhtmlファイルを作成している途中の件

の問題も発生するようなので、面倒なら、"Cross Domain - CORS"を起動しておくと良いでしょう(終了したら取り外しておかないと、Twitterで通信障害「"問題が発生しました" “やりなおす"」が発生するので注意のこと)

ただ、私が現状、https化を試みているプログラムは、まだ問題が残っていて、全部は動いていません。

 

build.9a271f4.js:23 WebSocket connection to 'ws://localhost/ws' failed: Error during WebSocket handshake: Unexpected response code: 301
value @ build.9a271f4.js:23

の方は直接、ws:// → wss://に 書き換えたりとかやっていんだけど、上手く動かないみたいです。

=======

翌日、動いていました。

こういう原因が分からない起動も、厄介です。

2020/11,江端さんの技術メモ

Dockerを使っていて、このメッセージにどれだけ苦しめられたことか分からない。

で、世界中の人も困っているようである。

コードにトレースログを仕込んでも、どうもコードではない部分で発生しているらしくて、手がつけられなかったが、調べている内に、こんなことが分かってきた。

  1. Dockerの中にデフォルトに入っているコンテナ間名前解決に関するアドレスらしい
  2. PostgreSQLに関する接続に関するところで発生るうことが多いらしい
  3. で、試しに、docker-compose.yml の"db:"に関わるところに、3行ほど追加してみた(最近濫用している、セキュリティ無視の接続の呪文)
    db:
    image: postgis-pgrouting:latest
    build:
    context: docker/postgis-pgrouting
    expose:
    - "5432"
    ports:
    - "15432:5432"
    volumes:
    - data
    - ./:/hitachi_ride_hailing_go
    environment:
    POSTGRES_HOST_AUTH_METHOD: 'trust'
    POSTGRES_PASSWORD: 'postgres'

そうしたら、いきなり、"dial tcp: lookup db on 127.0.0.11:53: no such host exit" が出てこなくなった。

理由は不明ですし、たまたまかもしれないけど、直ったので、それで良しとします。

 

2020/11,江端さんの技術メモ

2年前のコードをAWS Lightsailに乗せられないか、docker compose up -d  を試してみたところ、変なところでエラーが出てきた。

go build cmd/server/main.go

と打ち込んでみたら

というところで、引掛っていることが分かった。

原因をググってみた「メモリ不足」。

最低でも1G用意しろ、って書いてあった。

Amazon Lightsailの一番安いやつは、512MBだった。

まあ、今時、ノートPCだって、4G搭載しているからなー、これはないかなー 。

しかし、搭載を断念するのも残念だしなー、安全を考えると2GBは欲しいしなー ・・・でも、10ドル/月かぁ。

ちょっと考えよう。

Lightsail のインスタンスのスケールアップ

(後日談) 1MBのメモリを持つ、5$/月 の インスタンスにスケールアップして、docker compose up -d を通しました。

# いや、実装に成功していたラズパイのメモリが1GBだったので、多分大丈夫だろうと踏みました。

―― が、コンテナが起動していないので、ここからが勝負です。

 

2020/11,江端さんの技術メモ

地図データの入った PostgreSQL + postGIS サーバ を関係者に配るために、Docker containerのイメージを公開する(サーバ構築手順書を作成するのが面倒だから)

1.コンテナイメージの確認

C:\Users\ebata>docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6432e639f678 postgis-pgrouting:latest "docker-entrypoint.s…" 3 months ago Up 6 hours 0.0.0.0:15432->5432/tcp toyosu_db_1

2.コンテナイメージのパッキング(commit)

C:\Users\ebata>docker commit 6432e639f678 tommurphy/toyosu_db_1
sha256:c7a1a0537fbe24d0c1371264cbd83e620a09e2ec5c328b5fbb42efb0e9454f8e

3. dockerへのログイン

C:\Users\ebata>docker login -u tommurphy
Password:
Login Succeeded

4. 外部への公開

C:\Users\ebata>docker push tommurphy/toyosu_db_1
The push refers to repository [docker.io/tommurphy/toyosu_db_1]
fcc5c725337c: Layer already exists             

fcc5c725337c: Layer already exists
a3994f456ccb: Layer already exists
.....
latest: digest: sha256:27a46f90aa1c7c9f9b5fa92877d22156144b882ba15ba4e04fe0e4fe2cb4af24 size: 4497

5. 確認

https://hub.docker.com/にアクセス

5. 相手側への連絡

「dockerをインストールしたマシンで、"docker pull tommurphy/toyosu_db_1" とコマンド投入しろ」

「で、そのあと、$ docker run -it tommurphy/toyosu_db_1 bash とコマンド投入しろ」

 

と連絡する。

(とりあえず、Windows10で作ったイメージを、Amazon Lightsailの ubuntu20.04に入れることまでは成功した。動くかどうかは不明)

→ ダメ。データベースすっからかんのコンテナができた。もうちょっと嵌る必要があるなぁ

というか、そもそもDockerコンテナとはそういうものらしい("docker" "postgresql" "永続化"、あたりでググってみる)

現在、PostgreSQLをデータごとDockerコンテナ化するを読んでいる。

 

 

2020/11,江端さんの技術メモ

私が使っているQGIS3の地図と地物情報を、先方に送りたいのですが、先方に「DB構築してくれ」とは言えない場合があります(というか、殆どの場合がそうだろう)。

# で、今、実際にそんな状況になっている。

最初、qgzファイルを送付すれば足る、とか思っていたのですが、甘かったようです(qgzファイルはプロジェクト情報しか送付できない)

で、QGIS3を色々触っているうちに、なんかファイルができたような気がするので、自分用のメモとして残しておきます。

以上(現在、先方の成否報告待ち)。

キーワード:gpkg QGIS3 地物情報 先方にメールで送付

 

2020/11,未分類,江端さんの技術メモ

以下、自分用のメモのみ

AWS  Lightsailにdockerのインストールまで成功

PostgreSQLのインストールも成功したと思う

が、ここから嵌り始める。

ca_sim=# create extension postgis;

^C^CCancel request sent
Cancel request sent
ERROR: canceling statement due to user request
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
!>

が出てきて、

サーバ側に
2020-11-04 12:52:16.858 UTC [51] ERROR: canceling statement due to user request
2020-11-04 12:52:16.858 UTC [51] STATEMENT: create extension postgis;
2020-11-04 12:53:53.365 UTC [1] LOG: server process (PID 51) was terminated by signal 9: Killed
2020-11-04 12:53:53.365 UTC [1] DETAIL: Failed process was running: create extension postgis;
2020-11-04 12:53:53.365 UTC [1] LOG: terminating any other active server processes
2020-11-04 12:53:53.367 UTC [25] WARNING: terminating connection because of crash of another server process
2020-11-04 12:53:53.367 UTC [25] DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2020-11-04 12:53:53.367 UTC [25] HINT: In a moment you should be able to reconnect to the database and repeat your command.
2020-11-04 12:53:53.371 UTC [53] WARNING: terminating connection because of crash of another server process
2020-11-04 12:53:53.371 UTC [53] DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2020-11-04 12:53:53.371 UTC [53] HINT: In a moment you should be able to reconnect to the database and repeat your command.
2020-11-04 12:53:53.372 UTC [56] WARNING: terminating connection because of crash of another server process
2020-11-04 12:53:53.372 UTC [56] DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2020-11-04 12:53:53.372 UTC [56] HINT: In a moment you should be able to reconnect to the database and repeat your command.
2020-11-04 12:53:53.516 UTC [1] LOG: all server processes terminated; reinitializing
2020-11-04 12:53:53.535 UTC [58] FATAL: the database system is in recovery mode
2020-11-04 12:53:53.538 UTC [57] LOG: database system was interrupted; last known up at 2020-11-04 12:47:18 UTC
2020-11-04 12:53:53.607 UTC [57] LOG: database system was not properly shut down; automatic recovery in progress
2020-11-04 12:53:53.613 UTC [57] LOG: redo starts at 0/216DCD0
2020-11-04 12:53:53.712 UTC [57] LOG: invalid record length at 0/24F2310: wanted 24, got 0
2020-11-04 12:53:53.712 UTC [57] LOG: redo done at 0/24F22D8
2020-11-04 12:53:53.741 UTC [1] LOG: database system is ready to accept connections

そこで、

コンテナの外に出て、

sudo apt-get clean
sudo apt-get install postgis
sudo apt-get update

■全部のDockerを止める
C:\Users\ebata>docker ps -aq | xargs docker stop
C:\Users\ebata>docker ps -aq | xargs docker rm (これやると、これまでの設定も全滅するので注意)

もう一度、imageから作り直して ・・(30分経過)・・ううむ、それでもダメか。

今日はここで一旦引き上げ

2020/11,江端さんの技術メモ

正直手続忘れてしまったけど、一応historyからメモを作成しておきます。
https://docs.docker.com/engine/install/ubuntu/

$ sudo apt-get remove docker docker-engine docker.io containerd runc
$ sudo apt-get update
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo apt-key fingerprint 0EBFCD88
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io

ここからコケ始めました。

$ apt-cache madison docker-ce

の後、

$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

を入力したら、予想通り失敗しました。

(ちょっと一息)

$ apt-cache madison docker-ce

を入力した時、一番最初に表示された"5:19.03.13~3-0~ubuntu-focal" を訳も分からずに、置き換えしました。

$sudo apt-get install docker-ce=5:19.03.13~3-0~ubuntu-focal docker-ce-cli=5:19.03.13~3-0~ubuntu-focal containerd.io

でもって、

$ sudo docker run hello-world

をして、コメントに出てくる通りに、

$ docker run -it ubuntu bash

を実施しても"Got permission denied....." とか言われて、dockerのコンテナの中に入ることができませんでした。

$ docker ps

Got permission denied while trying to connect to the Docker daemon
socket at unix:///var/run/docker.sock:
Get http://%2Fvar%2Frun%2Fdocker.sock/v1.39/containers/json:
dial unix /var/run/docker.sock: connect: permission denied

てなエラーが出てくるので、このエラーメッセージで検索したところ、

# dockerグループへユーザを追加
$ sudo gpasswd -a ubuntu docker

# グループの追加ができたことを確認
$ id ubuntu

と入力して、(ここ大事)

# 一回ログアウトして再ログインする
$ exit

して、再度

$ sudo docker run hello-world
$ docker run -it ubuntu bash

をしたら、今度はコンテナの中に入ることができました。

ubuntu@ip-172-26-13-137:~$ docker run -it ubuntu bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
6a5697faee43: Pull complete
ba13d3bc422b: Pull complete
a254829d9e55: Pull complete
Digest: sha256:fff16eea1a8ae92867721d90c59a75652ea66d29c05294e6e2f898704bdb8cf1
Status: Downloaded newer image for ubuntu:latest
root@e9ff5fa891d0:/# ;s
bash: syntax error near unexpected token `;'
root@e9ff5fa891d0:/# ls
bin   dev  home  lib32  libx32  mnt  proc  run   srv  tmp  var
boot  etc  lib   lib64  media   opt  root  sbin  sys  usr

よく分からんけど、これで、Amazon Lightsailの中にDockerをインストールすることができたんだろう・・・と思っています。

2020/11,江端さんの技術メモ

イプシムのSIM(IPアドレス付きで、一番安いやつ)が、ラズパイに差さったままで使っていなかったので、iPadで使えるようにした。必要に応じて、またラズパイに戻せばいいし。

  1. SIM取り出し用の機具の準備

  2. イプシムのSIMカード情報の確認(画像は偽造しています)

  3. SIMカード番号の確認 (上記のICCIDと同じであるかを確認(画像は偽造しています))

3. iPadのスロットに挿入する

4. iPadから、https://ipsim.net/support.html にアクセスし、APN構成プロファイルをダウンロードする

これをダウンロードするのだが、これがインストールできているどうかが、確認できずに困った(インストールボタンが見あたらなかったから)。この場合は、「設定」で調べる。

ちなみに、以下の情報が必要なのかは分からないが一応セットしておいた。

 

5. iPadから、https://ipsim.net/support.html にアクセスし、APN構成プロファイルをダウンロードする(画像は偽造しています)

上記の赤い囲みに数字が出てくれば、インストールできている(と思う)。

7.右上にこの表示が出てくれば、SIMカードは稼動している(最初のうち、ブラウザが表示されなかったりするが時間が経過すると見えるようになる(ことがあるみたい)。表示されずに、なんども、手順をやりなおしていたが、"放置"が正解だったような気がする)

以上