Elasticsearch

安裝

elasticsearch 在新版本中已經自帶了 jdk,不需要另外安裝。


Elasticsearch - 部署配置集群,來試試


<code>
version="7.6.1"

cd $HOME

package_url="https://mirrors.huaweicloud.com/elasticsearch/${version}/elasticsearch-${version}-linux-x86_64.tar.gz"

wget -c ${package_url} || exit 1

tar zxvf elasticsearch-${version}-linux-x86_64.tar.gz

mv elasticsearch-${version} /opt/

cd /opt/

ln -sf elasticsearch-${version} elasticsearch

/<code>

修改內核參數

<code>echo vm.max_map_count=262144 >> /etc/sysctl.conf
sysct -p
/<code>

修改句柄限制

<code>echo "* soft nofile 65536" >> /etc/security/limits.conf
echo "* hard nofile 131072" >> /etc/security/limits.conf
/<code>

創建數據目錄

<code>mkdir -p /data/elasticsearch/data
mkdir -p /data/elasticsearch/logs
/<code>

創建運行用戶

<code>useradd elasticsearch
/<code>

修改目錄權限

<code>chown  -v elasticsearch:elasticsearch /opt/elasticsearch /opt/elasticsearch-${version} /data/elasticsearch/ -R
/<code>

集群配置


Elasticsearch - 部署配置集群,來試試

集群,節點可以在同一臺機器,也可以在不同的機器上。安裝過程都是一樣的。如果是在同一臺機器,就安裝到不同的目錄即可。

實驗機器 IP:

<code>192.168.122.101
192.168.122.102
192.168.122.103
/<code>

修改配置文件

<code>cd /opt/elasticsearch/config
vim elasticsearch.yml
/<code>

修改對應的配置(看備註)

<code># ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
# 這裡是集群名稱,確定每個節點的配置的名稱是一樣的即可。
cluster.name: myes
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:

# 節點名稱,不同節點使用不同的名稱
node.name: node-192.168.122.101
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
# 數據目錄
path.data: /data/elasticsearch/data
#
# Path to log files:
# 日誌目錄
path.logs: /data/elasticsearch/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
# 設置當前的ip地址,通過指定相同網段的其他節點會加入該集群中,不同節點,填寫節點通訊IP
network.host: 192.168.122.101
#
# Set a custom port for HTTP:
# 服務端口
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:

# The default list of hosts is ["192.168.122.101", "[::1]"]
# 集群初始化查找列表
discovery.seed_hosts: ["192.168.122.101", "192.168.122.102", "192.168.122.103"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
# 集群初始化節點
cluster.initial_master_nodes:
["node-192.168.122.101", "node-192.168.122.102", "node-192.168.122.103"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
/<code>

切換用戶

運行的時候需要用普通用戶去啟動。

<code>su - elasticsearch
/<code>

啟動服務

<code>/opt/elasticearch/bin/elasticsearch -d
/<code>

測試

創建索引

<code>curl -XPUT http://192.168.122.101:9200/testindex
{"acknowledged":true,"shards_acknowledged":true,"index":"testindex"}
/<code>

查看所有的索引

<code>curl 'http://192.168.122.101:9200/_cat/indices?v'
/<code>
<code>health status index     uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open testindex BliIJCoYQiW4TL_L_26zeg 1 1 1 0 0b 0b

/<code>

刪除索引

<code>curl -X DELETE http://192.168.122.101:9200/testindex
{"acknowledged":true}
/<code>

添加文檔(如果索引不存在會自動創建索引)

<code>curl -H "Content-Type: application/json" -XPUT 'http://192.168.122.101:9200/testindex/external/1' -d '{"name": "OPcai"}'
/<code>


Elasticsearch - 部署配置集群,來試試


總結

可以安裝 cerebro 查看集群的狀態。


分享到:


相關文章: