Elasticsearch settings for single-node cluster

此方式是由 docker-compose 啟用,以下是下載包

解壓縮

# cd /opt
# tar -zxvf docker-elk-cluster-200108.tar.gz
/opt # cd docker-elk-cluster/

編輯設定檔 (elasticsearch)

# vi /opt/docker-elk-cluster/elasticsearch/config/elasticsearch-single.yml

修改 node.name
discovery.zen.ping.unicast.hosts:(可設可不設)

## Default Elasticsearch configuration from elasticsearch-docker.
## from https://github.com/elastic/elasticsearch-docker/blob/master/build/elasticsearch/elasticsearch.yml
#
cluster.name: ${ES_CLUSTER_NAME}
network.host: 0.0.0.0
bootstrap.memory_lock: true

# minimum_master_nodes need to be explicitly set when bound on a public IP
# set to 1 to allow single node clusters
# Details: https://github.com/elastic/elasticsearch/pull/17288
#
# To avoid a split brain, this setting should be set to a quorum of master- eligible nodes:
# (master_eligible_nodes / 2) + 1
discovery.zen.minimum_master_nodes: 1
node.name:  prod-adp-elk
http.port: 9200
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["172.18.0.2"]
## Use single node discovery in order to disable production mode and avoid bootstrap checks
## see https://www.elastic.co/guide/en/elasticsearch/reference/current/bootstrap-checks.html
#
discovery.type: single-node

## Disable X-Pack
## see https://www.elastic.co/guide/en/x-pack/current/xpack-settings.html
##     https://www.elastic.co/guide/en/x-pack/current/installing-xpack.html#xpack-enabling
#
xpack.security.enabled: false
xpack.monitoring.enabled: false
xpack.ml.enabled: false
xpack.watcher.enabled: false

thread_pool.search.queue_size: 10000

啟用

/opt/docker-elk-cluster # docker-compose up -d

啟用完之後修改 default template value 預設5 改成 1

若不改的話,會成 unsigned 資料會有問題

curl -X PUT http://localhost:9200/_template/default -H 'Content-Type: application/json' -d '{"index_patterns": ["*"],"order": -1,"settings": {"number_of_shards": "1","number_of_replicas": "0"}}'

查詢方式
[email protected]:/opt/docker-elk-cluster/elasticsearch/templates# curl -XGET ‘http://localhost:9200/_cat/shards’


container-2019.12.27 0 p STARTED   41  65.8kb 172.18.0.2 prod-adp-elk
container-2020.01.07 0 p STARTED 3543   1.6mb 172.18.0.2 prod-adp-elk
container-2019.12.30 0 p STARTED   37  81.4kb 172.18.0.2 prod-adp-elk
container-2020.01.04 0 p STARTED 6250   2.4mb 172.18.0.2 prod-adp-elk
container-2020.01.05 0 p STARTED 5856     2mb 172.18.0.2 prod-adp-elk
container-2019.12.31 0 p STARTED   91 120.6kb 172.18.0.2 prod-adp-elk
container-2020.01.06 0 p STARTED 7942   3.5mb 172.18.0.2 prod-adp-elk
container-2020.01.02 0 p STARTED   52  84.3kb 172.18.0.2 prod-adp-elk
container-2019.12.28 0 p STARTED    4    25kb 172.18.0.2 prod-adp-elk
container-2020.01.03 0 p STARTED 8428     5mb 172.18.0.2 prod-adp-elk

查詢方式 2

curl http://localhost:9200/_cat/health

1578383246 07:47:26 docker-cluster green 1 1 10 10 0 0 0 0 - 100.0%

查詢方式 3

curl http://localhost:9200/_cat/indices?v


health status index                uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   container-2020.01.07 JPKzEcfkTTm8Yb-0JE7yaw   1   0       3560            0      1.6mb          1.6mb
green  open   container-2019.12.28 jysSVQwzSzWVQwmm8UDLNA   1   0          4            0       25kb           25kb
green  open   container-2020.01.03 h2Q9WNGxSWOMtOY55Gv-Yw   1   0       8428            0        5mb            5mb
green  open   container-2020.01.02 3oDzBMbBQJmfcKo6noTgzA   1   0         52            0     84.3kb         84.3kb
green  open   container-2019.12.31 UionanqyS6ehnw2zijwHGg   1   0         91            0    120.6kb        120.6kb
green  open   container-2019.12.30 OGJ8jAbPSyq_rD4nU0HN2g   1   0         37            0     81.4kb         81.4kb
green  open   container-2020.01.06 qD6I2LDITOKatNV-2Jy_3g   1   0       7942            0      3.5mb          3.5mb
green  open   container-2019.12.27 S3M5242URgmxs48JAFuBDA   1   0         41            0     65.8kb         65.8kb
green  open   container-2020.01.05 I3J5UzlVRdmnAwMAExA4Pg   1   0       5856            0        2mb            2mb
green  open   container-2020.01.04 heSWu-99QSCDLFgwgejRBw   1   0       6250            0      2.4mb          2.4mb

參考:https://gist.github.com/angristan/9d251d853d11f265899b8a4725bff756