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 查看集群的状态。


分享到:


相關文章: