elasticsearch 部署

系统环境为: ubuntu 16 server
注:想要测试同一台机器上配置两个节点并放在同一个集群中,如果只是想在一台机器上配置一个节点,方法更简单一些

1.java 环境部署

下载java jdk安装

jdk版本

解压后,放到目标目录下,配置环境变量:
vim ~/.bashrc
在文件最后添加

export JAVA_HOME='/opt/jdk1.8.0_131'
export CLASSPATH=${JAVA_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH                             

执行source ~/.bashrc生效
检测是否安装成功java -version

2.下载elasticsearch

curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.1.tar.gz
解压软件包
tar xzvf elasticsearch-6.0.1.tar.gz
然后移动到目标路径,添加新的用户用来专门管理另一个节点的用户,最终效果为

image.png

3. 配置两个节点

修改node-1的配置文件/opt/elasticsearch6/config

# ======================== 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: search-controler
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-1
#
# 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: /elastic/data
#
# Path to log files:
#
path.logs: /elastic/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):
#
network.host: 192.168.9.128
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
transport.tcp.port: 9300
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.zen.ping.unicast.hosts: ["192.168.9.128", "192.168.9.128:9301"]

节点2的配置文件修改为:

# ======================== 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: search-controler
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-2
#
# 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: /elastic/data-node2
#
# Path to log files:
#
path.logs: /elastic/logs-node2
#
# ----------------------------------- 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):
#
network.host: 192.168.9.128
#
# Set a custom port for HTTP:
#
http.port: 9201
#
# For more information, consult the network module documentation.
#
transport.tcp.port: 9301
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.zen.ping.unicast.hosts: ["192.168.9.128:9300", "192.168.9.128:9301"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 3
#
# For more information, consult the zen discovery module documentation.
#

4.启动两个节点

分别执行
./bin/elasticsearch
两个节点启动,这个时候,如果再虚拟机会碰到一个错误
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决方案的链接:解决方案

5.再次执行就可成功启动两个节点了,通过同一个ip地址的9200端口和9201端口分别访问的是集群的不同节点

6.使用x-pack对elasticsearch添加认证

x-pack是elasticsearch 官方插件,功能不仅包括对elasticsearch认证.
cd /opt/elasticsearch6/bin
./elasticsearch-plugin install x-pack
安装完成后,启动elasticsearch.
bin/x-pack/setup-passwords auto产生相关用户的密码

image.png

7.最终我们就可以通过使用认证的方法访问我们的集群节点

image.png

8.安装中文分词器IK Analysis

image.png

不同版本下载对应版本的分词器


image.png

安装方式有两种,安装完成后重启即可。

9,新发现

自elasticsearch 5.6之后的版本,一个索引只有一个type,多于一个会报错。

你可能感兴趣的:(elasticsearch 部署)