LoginSignup
0
2

More than 5 years have passed since last update.

メモリ512M最安VPSでnginx + php + elasticsearch on dockerを起動する

Last updated at Posted at 2018-12-02

困ったのはelasticsearchだけなので、php, nginxにはほぼ触れない。

VPS

amazon Lightsail 512MBプラン
https://aws.amazon.com/jp/lightsail/
OS:amazon Linux

docker-compose.yml

version: "2"
services:
  # php-fpm
  phpfpm:
    build: ./phpfpm/
    links:
      - elastic
    volumes:
      - ./data:/var/www/html
    mem_limit: 64m

  # nginx
  nginx:
    build: ./nginx/
    ports:
      - 80:80
    links:
      - phpfpm
    volumes:
      - ./data:/var/www/html
    mem_limit: 64m

  # Elasticsearch
  elastic:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.5.1
    environment:
      - cluster.name=docker-cluster
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      nproc:
        soft: 4096
        hard: 4096
      memlock:
        soft: 256000
        hard: 256000
      nofile:
        soft: 65536
        hard: 65536
    mem_limit: 256m
    memswap_limit: 2g

着目すべきはelasticsearchの設定。かなりマシンリソースが必要なので、そもそもこんな使い方をしてはいけない。

基本はElasticsearch公式。それをもとにゴニョゴニョした結果が上記。
https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html

  • プロセス数(nproc)は4096の確保が必須。確保しないとelasticsearchのヘルスチェックでfailしてコンテナが停止
  • ファイルディスクリプタ(nofile)は65536の確保が必須。確保しないと(ry
  • (memlockはmem_limitに合わせただけ。確保すべき値は不明)
  • mem_limitはホストマシンのメモリの半分≒256mを確保。えいや〜
  • memswap_limitで2Gを確保。えいや〜
  • bootstrap.memory_lock: true の設定を使わない。true = スワッピングをさせない (当然Elasticsearchの公式では、パフォーマンスとノードの安定性のためにこの設定をtrueにするように言及している)

Swapping needs to be disabled for performance and node stability.

こんな貧弱なマシンを使わないなら上の設定は書かなくていい気がする。(手元のローカルPCでは必要なかった)

(参考)swap領域の確保

0
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2