1. 程式人生 > >安裝部署elasticsearch

安裝部署elasticsearch

elasticsearch

環境準備:

服務器:centos7服務器1臺,IP:10.0.0.103
安裝包:
elasticsearch-6.1.1.tar.gz
jdk-8u151-linux-x64.tar.gz

[root@node2 ~]# ll
-rw-r--r--  1 root root  33783880 6月   3 11:18 elasticsearch-6.1.1.tar.gz
-rw-r--r--  1 root root 189736377 6月   3 11:23 jdk-8u151-linux-x64.tar.gz
[root@docker ~]# 

安裝JDK

elasticsearch需要依賴JDK,因此首先要安裝JDK:

1、解壓安裝包

[root@node2?~]#?tar xf jdk-8u151-linux-x64.tar.gz -C /usr/local/

2、安裝jdk修改/etc/profile,在文件末尾加入下面幾句:

export JAVA_HOME=/usr/local/jdk1.8.0_151   #根據目錄和版本修改
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export  PATH=${JAVA_HOME}/bin:$PATH

3、source命令讓修改後的/etc/profile生效:

[root@node2 ~]# source /etc/profile

4、檢查安裝正確性:

[root@node2 ~]# java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
[root@node2 ~]# 

安裝elasticsearch

1、解壓文件

[root@node2?~]#?tar?-xf?elasticsearch-6.1.1.tar.gz?-C /usr/local??##解壓
[root@node2?~]#?cd?/usr/local/elasticsearch-6.1.1
[root@node2?elasticsearch-6.1.1]#?ls
bin??config??lib??LICENSE.txt??modules??NOTICE.txt??plugins??README.textile

2、修改配置如下(根據實際情況調整)

[root@node2 config]# cat 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: mycluster   #配置ES集群名字
#
# ------------------------------------ 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: /opt/elk/data     #配置數據路徑
#
# Path to log files:
#
path.logs: /opt/elk/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: 10.0.0.103    ?#配置為本地ip,監聽主機
#
# Set a custom port for HTTP:
#
http.port: 9200   #設置對外服務的http端口
#
# For more information, consult the network module documentation.
#
# --------------------------------- 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: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
discovery.zen.minimum_master_nodes: 1    #設置這個參數來保證集群中的節點可以知道其它N個有master資格的節點。默認為1,對於大的集群來說,可以設置大一點的值(2-4)。我這裏只有一臺,所以設置為1
#
# For more information, consult the zen discovery 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

3、修改系統配置文件:
修改之前最好先備份:

[root@node2 elasticsearch-6.1.1]# cp /etc/security/limits.conf  /etc/security/limits.conf.bak
[root@node2 elasticsearch-6.1.1]# cp /etc/sysctl.conf /etc/sysctl.conf.bak

vi /etc/security/limits.conf?
在文件末尾添加如下內容:

* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096

vi /etc/sysctl.conf?
添加下面配置:

vm.max_map_count=655360

並執行命令sysctl -p讓其修改生效:

[root@node2 elasticsearch-6.1.1]# sysctl -p
vm.max_map_count = 655360

4、創建啟動elasticsearch的用戶和日誌目錄,修改權限:

[root@node2 elasticsearch-6.1.1]# cd /usr/local
[root@node2 local]# useradd elk
[root@node2 local]# mkdir /opt/elk/logs -p
[root@node2 local]# mkdir /opt/elk/data -p
[root@node2 local]# chown -R elk:elk /opt/elk/
[root@node2 local]# chown -R elk:elk /usr/local/elasticsearch-6.1.1

5、啟動服務
[root@node2 config]# su elk
[elk@node2 config]$ nohup /usr/local/elasticsearch-6.1.1/bin/elasticsearch >/dev/null 2>&1 &

6、服務驗證:
1)查看進程和端口號:

[root@node2 config]# netstat -tlunp|grep 9200
tcp6       0      0 10.0.0.103:9200         :::*                    LISTEN      6665/java           

[root@node2 config]# ps -ef|grep elasticsearch
elk        6665      1  4 15:10 pts/0    00:01:17 /usr/local/jdk1.8.0_151/bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+AlwaysPreTouch -server -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -XX:+HeapDumpOnOutOfMemoryError -Des.path.home=/usr/local/elasticsearch-6.1.1 -Des.path.conf=/usr/local/elasticsearch-6.1.1/config -cp /usr/local/elasticsearch-6.1.1/lib/* org.elasticsearch.bootstrap.Elasticsearch
root       6769   3724  0 15:37 pts/0    00:00:00 grep --color=auto elas

2)命令行驗證:
[root@node2 config]# curl http://10.0.0.103:9200
{
"name" : "node-1",
"cluster_name" : "elk",
"cluster_uuid" : "gv8DzvZeR1W-aOM_UTEdVA",
"version" : {
"number" : "6.1.1",
"build_hash" : "bd92e7f",
"build_date" : "2017-12-17T20:23:25.338Z",
"build_snapshot" : false,
"lucene_version" : "7.1.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
[root@node2 config]#

3)瀏覽器訪問驗證:
技術分享圖片

安裝部署elasticsearch