一、叢集部署規劃
版本選擇:
Os版本: CentOS-7-x86_64-DVD-1810
Jdk版本: jdk-8u151
ES版本: elasticsearch-7.3.1
部署節點:
三台虛拟機 :centos-01、centos-02、centos-03
二、基礎環境搭建
2.1虛拟機環境網絡配置:
vi /etc/sysconfig/network-scripts/ ifcfg-ens33
先讓它動态配置設定一個ip位址 :ONBOOT=yes
重新開機網卡
service network restart
檢視動态配置設定的ip
ip add
再設定靜态ip位址
BOOTPROTO=static
IPADDR=192.168.98.128
NETMASK=255.255.255.0
GATEWAY=192.168.98.1
最後再次重新開機網卡
service network restart
ip add
2.2配置主機和ip的映射關系:
vi /etc/hosts
2.3關閉防火牆:
檢視防火牆狀态:
firewall-cmd --state
臨時關閉防火牆:
Systemctl stop firewalld.service
永久關閉防火牆:
Systemctl disable firewalld
2.4.安裝jdk:
上傳jdk并解壓縮:
tar -zxvf jdk-8u151-linux-x64.tar.gz
配置環境變量
vi /etc/profile
export JAVA_HOME=/usr/local/jdk1.8.0_151
export PATH=$PATH:$JAVA_HOME/bin
使配置檔案生效:
source /etc/profile
2.5建立elasticsearch使用者
為了安全es不允許使用root使用者啟動,建議建立一個單獨的使用者來運作elasticsearch。
建立elasticsearch使用者及設定密碼:
adduser elasticsearch
passwd elasticsearch
2.6三台機器elasticsearch使用者的免密配置
切換到elasticsearch使用者
su elasticsearch
生成本機的公鑰:
ssh-keygen -t rsa
cd ~/.ssh/
将本地的公鑰複制為authorized_keys檔案。
cp id_rsa.pub authorized_keys
将本地的公鑰複制到其他主機的authorized_keys檔案中
ssh-copy-id -i centos-02
三、部署elasticsearch
3.1上傳elasticsearch并解壓縮
tar -zxvf elasticsearch-7.3.1-linux-x86_64.tar.gz
3.2建立elasticsearch的資料存儲目錄和日志存儲目錄
mkdir -p /data/elasticsearch/data
mkdir -p /data/elasticsearch/logs
3.3更改檔案的擁有者為elasticsearch使用者
chown -R elasticsearch /data/elasticsearch/data
chown -R elasticsearch /data/elasticsearch/logs
chown -R elasticsearch /usr/local/elasticsearch-7.3.1
3.4 修改es叢集的配置參數
centos-01節點:
vi config/elasticsearch.yml
# ======================== 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: my-elasticsearch
#
# ------------------------------------ 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: /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):
#監聽位址,用于通路該elasticsearch
network.host: 192.168.98.128
#
# 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 ["127.0.0.1", "[::1]"]
#es7.x之後新增的配置,寫入候選節點的裝置位址,在開啟服務後可以被選為主節點
discovery.seed_hosts: ["centos-01", "centos-02","centos-03"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#es7.x之後新增的配置,初始化一個新的叢集時需要此配置來選舉master
cluster.initial_master_nodes: ["node-1", "node-2", "node-3"]
#
# 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
#是否支援跨域
http.cors.enabled: true
#*表示支援所有域名
http.cors.allow-origin: "*"
centos-02節點修改如下配置:
#節點名稱
node.name: node-2
#監聽位址,用于通路該elasticsearch
network.host: 192.168.98.129
centos-03節點修改如下配置:
#節點名稱
node.name: node-3
#監聽位址,用于通路該elasticsearch
network.host: 192.168.98.130
3.5 一些特殊配置
因啟動報錯:
[1]每個程序最大同時打開檔案數太小。
解決方法:
vi /etc/security/limits.conf
添加
* soft nofile 65536
* hard nofile 65536
注:“*”表示給所有使用者起作用
[2]最大線程個數太低。
解決方法:
vi /etc/security/limits.conf
添加
* soft nproc 4096
* hard nproc 4096
[3]每個程序可以擁有的VMA(虛拟記憶體區域)的數量太低。
解決辦法:
vi /etc/sysctl.conf
添加
vm.max_map_count=262144
記得sysctl –p 生效。
四、啟動es
切換到elasticsearch使用者
su elasticsearch
在三台機器上分别啟動es
./bin/elasticsearch
背景啟動方式
./bin/elasticsearch –d
五、通路es
curl -XGET centos-01:9200
curl -XGET centos-01:9200/_cat/nodes?v
六、關閉es
jps | grep Elasticsearch
kill -9 11827
七、遇到的錯誤:
原因是有兩個獨立的叢集,删除要加入的叢集的data目錄下的資料。
八、參考
1、https://www.cnblogs.com/remainsu/p/elasticsearch-711-ji-qun-huan-jing-da-jian.html
2、https://www.cnblogs.com/zhi-leaf/p/8484337.html
3、https://blog.51cto.com/860143/2422797?source=dra
4、https://www.cnblogs.com/nr-zhang/p/9084820.html