1. 程式人生 > >ElasticSearch 安裝啟動與配置

ElasticSearch 安裝啟動與配置

簡介
ElasticSearch是一個開源免費,用Java開發的,基於Lucene框架的,提供RESTful web介面的、分散式多使用者能力的,實時的分散式搜尋分析引擎。簡單高效,開箱即用。

這裡寫圖片描述

安裝
在安裝ElasticSearch 之前,我們需要先安裝一個java,為什麼呢?因為ElasticSearch 是java語言開發的。

這裡要提醒一下,elasticsearch java支援最低 jdk1.8 !

下載解壓

#下載es
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3
.1.tar.gz #解壓 tar -xzf elasticsearch-6.3.1.tar.gz

啟動
es很方便,解壓就可以直接用了,下面我們嘗試執行一下。

[root@localhost elasticsearch-6.3.1]# ./bin/elasticsearch

結果啟動報錯了 can not run elasticsearch as root

[2018-01-28T22:00:31,358][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException:
java.lang.RuntimeException: can not run elasticsearch as root at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:125) ~[elasticsearch-6.1.2.jar:6.1.2] at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-6.1.2.jar:6.1.2] at org.elasticsearch
.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.1.2.jar:6.1.2] at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.1.2.jar:6.1.2] at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.1.2.jar:6.1.2] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-6.1.2.jar:6.1.2] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:85) ~[elasticsearch-6.1.2.jar:6.1.2] Caused by: java.lang.RuntimeException: can not run elasticsearch as root at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:104) ~[elasticsearch-6.1.2.jar:6.1.2] at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:171) ~[elasticsearch-6.1.2.jar:6.1.2] at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:322) ~[elasticsearch-6.1.2.jar:6.1.2] at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-6.1.2.jar:6.1.2] ... 6 more

看起來root不允許直接啟動。因為這個原因,那我們需要新建一個使用者來啟動es,具體操作如下:

# 以root使用者來建立新的使用者 , groupadd 新增一個使用者組
[root@localhost home]# groupadd elk
# 新增一個使用者,-g是在使用者組下 -p是密碼
[root@localhost home]# useradd elk -g elk -p elk
# 進入es的安裝目錄
[root@localhost home]# cd /home/elasticsearch 
# 給使用者elk授權
[root@localhost home]# chown -R elk:elk elasticsearch-6.3.1/
# 切換到 elk使用者
[root@localhost elasticsearch]# su elk

到這裡新的使用者也建立好了,也授權了,接下來我們重新啟動一下

[[email protected] elasticsearch-6.1.2]$ ./bin/elasticsearch
[2018-01-28T22:11:06,918][INFO ][o.e.n.Node               ] [] initializing ...
[2018-01-28T22:11:07,161][INFO ][o.e.e.NodeEnvironment    ] [qR5cyzh] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [12.5gb], net total_space [17.6gb], types [rootfs]
[2018-01-28T22:11:07,162][INFO ][o.e.e.NodeEnvironment    ] [qR5cyzh] heap size [1015.6mb], compressed ordinary object pointers [true]
[2018-01-28T22:11:07,163][INFO ][o.e.n.Node               ] node name [qR5cyzh] derived from node ID [qR5cyzhRQUix7PbCNFViTw]; set [node.name] to override
[2018-01-28T22:11:07,163][INFO ][o.e.n.Node               ] version[6.1.2], pid[7200], build[5b1fea5/2018-01-10T02:35:59.208Z], OS[Linux/3.10.0-514.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_141/25.141-b15]
[2018-01-28T22:11:07,163][INFO ][o.e.n.Node               ] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -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=/home/elasticsearch/elasticsearch-6.1.2, -Des.path.conf=/home/elasticsearch/elasticsearch-6.1.2/config]
[2018-01-28T22:11:09,295][INFO ][o.e.p.PluginsService     ] [qR5cyzh] loaded module [aggs-matrix-stats]
[2018-01-28T22:11:09,295][INFO ][o.e.p.PluginsService     ] [qR5cyzh] loaded module [analysis-common]
[2018-01-28T22:11:09,295][INFO ][o.e.p.PluginsService     ] [qR5cyzh] loaded module [ingest-common]
[2018-01-28T22:11:09,296][INFO ][o.e.p.PluginsService     ] [qR5cyzh] loaded module [lang-expression]
[2018-01-28T22:11:09,296][INFO ][o.e.p.PluginsService     ] [qR5cyzh] loaded module [lang-mustache]
[2018-01-28T22:11:09,296][INFO ][o.e.p.PluginsService     ] [qR5cyzh] loaded module [lang-painless]
[2018-01-28T22:11:09,296][INFO ][o.e.p.PluginsService     ] [qR5cyzh] loaded module [mapper-extras]
[2018-01-28T22:11:09,296][INFO ][o.e.p.PluginsService     ] [qR5cyzh] loaded module [parent-join]
[2018-01-28T22:11:09,296][INFO ][o.e.p.PluginsService     ] [qR5cyzh] loaded module [percolator]
[2018-01-28T22:11:09,296][INFO ][o.e.p.PluginsService     ] [qR5cyzh] loaded module [reindex]
[2018-01-28T22:11:09,296][INFO ][o.e.p.PluginsService     ] [qR5cyzh] loaded module [repository-url]
[2018-01-28T22:11:09,296][INFO ][o.e.p.PluginsService     ] [qR5cyzh] loaded module [transport-netty4]
[2018-01-28T22:11:09,296][INFO ][o.e.p.PluginsService     ] [qR5cyzh] loaded module [tribe]
[2018-01-28T22:11:09,297][INFO ][o.e.p.PluginsService     ] [qR5cyzh] no plugins loaded
[2018-01-28T22:11:13,791][INFO ][o.e.d.DiscoveryModule    ] [qR5cyzh] using discovery type [zen]
[2018-01-28T22:11:14,926][INFO ][o.e.n.Node               ] initialized
[2018-01-28T22:11:14,927][INFO ][o.e.n.Node               ] [qR5cyzh] starting ...
[2018-01-28T22:11:15,582][INFO ][o.e.t.TransportService   ] [qR5cyzh] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
[2018-01-28T22:11:15,598][WARN ][o.e.b.BootstrapChecks    ] [qR5cyzh] max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2018-01-28T22:11:15,598][WARN ][o.e.b.BootstrapChecks    ] [qR5cyzh] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2018-01-28T22:11:18,915][INFO ][o.e.c.s.MasterService    ] [qR5cyzh] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {qR5cyzh}{qR5cyzhRQUix7PbCNFViTw}{wRzc-CVaRmmdLNnPfT_LTA}{127.0.0.1}{127.0.0.1:9300}
[2018-01-28T22:11:18,920][INFO ][o.e.c.s.ClusterApplierService] [qR5cyzh] new_master {qR5cyzh}{qR5cyzhRQUix7PbCNFViTw}{wRzc-CVaRmmdLNnPfT_LTA}{127.0.0.1}{127.0.0.1:9300}, reason: apply cluster state (from master [master {qR5cyzh}{qR5cyzhRQUix7PbCNFViTw}{wRzc-CVaRmmdLNnPfT_LTA}{127.0.0.1}{127.0.0.1:9300} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
[2018-01-28T22:11:19,028][INFO ][o.e.g.GatewayService     ] [qR5cyzh] recovered [0] indices into cluster_state
[2018-01-28T22:11:19,097][INFO ][o.e.h.n.Netty4HttpServerTransport] [qR5cyzh] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[2018-01-28T22:11:19,097][INFO ][o.e.n.Node               ] [qR5cyzh] started

很順利,啟動成功了,我們curl來試一下

root@ubuntu:~# curl "127.0.0.1:9200"
{
  "name" : "2ColKaJ",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "i5iE7u0BQcegI7kb7LRRxQ",
  "version" : {
    "number" : "6.3.1",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "eb782d0",
    "build_date" : "2018-06-29T21:59:26.107521Z",
    "build_snapshot" : false,
    "lucene_version" : "7.3.1",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

沒什麼問題,我們再用瀏覽器來試一下

這裡寫圖片描述

也沒問題,好了,到現在為止我們的elasticsearch服務就搭建成功了,接下來我們來看配置

配置

先來看一下elasticsearch的配置檔案:

# ======================== 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-application
#
# ------------------------------------ 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: /path/to/data
#
# Path to log files:
# 配置日誌目錄
#path.logs: /path/to/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地址
network.host: 172.16.88.35
# 
# Set a custom port for HTTP:
# 指定http訪問埠
http.port: 9200
#
# 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: 
#
# 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

配置Network部分

在開始之前,我們首先得確保 宿主機和虛擬機器的網路是互相可以ping通的。

注意關閉宿主機和虛擬機器的防火牆哦,不然會遇到各種莫名其妙的問題,關閉防火牆命令

通過修改 elasticsearch.yml配置,我們來實現區域網內訪問elasticsearch服務,將host和port相應配置修改成區域網的一個固定IP,然後重新啟動。

# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 172.16.88.35
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.

執行啟動命令 ./bin/elasticsearch 啟動後,會發現報2個錯,如下:

[2018-01-28T23:51:35,180][INFO ][o.e.t.TransportService   ] [qR5cyzh] publish_address {172.19.26.110:9300}, bound_addresses {172.19.26.110:9300}
[2018-01-28T23:51:35,204][INFO ][o.e.b.BootstrapChecks    ] [qR5cyzh] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [2] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

1、報錯 max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]是因為作業系統vm.max_map_count引數設定太小導致的,至於設定多大的數值,我這裡就直接參照報錯資訊的建議直接設定為262144

解決方案一:

切換到root使用者下,執行以下命令:

sysctl -w vm.max_map_count=262144

檢查配置是否生效

[email protected]:~# sysctl -a | grep "vm.max_map_count"
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.ens3.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
vm.max_map_count = 262144
[email protected]:~# 

2、報錯max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]是因為作業系統安全檢測配置影響的,我們需要切換到root使用者下做如下配置:

先做一個配置備份

[root@localhost elasticsearch-6.1.2]# cd /etc/security/
[root@localhost security]# cp limits.conf limits.conf.bak

然後編輯limits.conf增加如下配置:

# elasticsearch config start
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
# elasticsearch config end

執行啟動命令 ./bin/elasticsearch ,會發現指定IP已經配置好了,也正常啟動。
publish_address {172.16.88.35:9200}, bound_addresses {172.16.88.35:9200}

[2018-01-29T01:10:58,076][INFO ][o.e.d.DiscoveryModule    ] [qR5cyzh] using discovery type [zen]
[2018-01-29T01:10:59,124][INFO ][o.e.n.Node               ] initialized
[2018-01-29T01:10:59,125][INFO ][o.e.n.Node               ] [qR5cyzh] starting ...
[2018-01-29T01:10:59,441][INFO ][o.e.t.TransportService   ] [qR5cyzh] publish_address {172.19.26.110:9300}, bound_addresses {172.19.26.110:9300}

接下來 瀏覽器訪問
這裡寫圖片描述

ok,下班了

相關推薦

ElasticSearch 安裝啟動配置

簡介 ElasticSearch是一個開源免費,用Java開發的,基於Lucene框架的,提供RESTful web介面的、分散式多使用者能力的,實時的分散式搜尋分析引擎。簡單高效,開箱即用。 安裝 在安裝ElasticSearch 之前,我們需要先安

Linux下安裝Nginx配置

目錄 openssl oct pan yum安裝 usr 負載均衡 官方 err 一,安裝GCC yum安裝gcc-c ++ -y 二,安裝nginx的所需要的依賴庫 yum -y安裝zlib-devel openssl-devel pcre-devel

ubuntu安裝mysql配置外網訪問

安裝mysql 數據 .cn install 安裝數據庫 joseph html mysq www. linux上安裝數據庫比windows簡單很多,一條命令搞定 sudo apt-get install mysql-server 難的是配置外網訪問與權限設置,我是按照一篇

ubuntu 安裝Git配置SSH key

第一步:安裝git。     用Ctrl+Alt+T開啟終端,輸入命令     sudo apt-getinstall git 第二步:配置本機Git屬性     終端輸入:  &nb

ubuntu安裝nginx配置

pat sha web grep 訪問 cati pan listen 安裝nginx 命令行安裝:(當前時間為2018.11,版本為1.10.3) sudo apt-get install nginx 安裝好的文件位置: /usr/sbin/nginx:

linux mongodb安裝啟動停止

        MongoDB是一個基於分散式檔案儲存的資料庫。旨在為WEB應用提供可擴充套件的高效能資料儲存解決方案。         MongoDB是一個介

Redis啟動配置【精選攻略四 】

  一  Redis啟動 Redis有兩種啟動,分別是:前端啟動、後端啟動。要啟動Redis,就需要到Redis的bin目錄下執行啟動命令,先看看bin目錄結構 直接上啟動命令:注意指定配置檔案 ./redis-server ../redis.con

elasticsearch安裝springboot2.x整合

  關於elasticsearch是什麼、elasticsearch的原理及elasticsearch能幹什麼,就不多說了,主要記錄下自己的一個使用過程。   1、安裝   elasticsearch是用java編寫的,所以它的執行離不開jdk,jdk的安裝這裡不再囉嗦,我使用的是虛擬機器是centos7

CentOS7安裝maven配置

獲取maven安裝包 wget http://mirror.bit.edu.cn/apache/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz 解壓 tar xvf apache-maven-3.

Ngnix 安裝啟動 bind端口出錯解決

                                         

4.8 Sublime Text3 中配置 Python環境 --下之下載安裝Sublime配置Python環境

main 代碼 col 編程 als 數據 -- print 安裝 返回總目錄 目錄: 1.沒有配置之前 2.安裝Package Control插件 3.安裝其他庫: 4.配置其他操作: (一)沒有配置之前: 我們試著運行以下,會效果怎麽樣? 1.首先選擇Python作

Centos7安裝ngnix配置反向代理

一、目的 使用Centos7搭建一個ngnix負載均衡伺服器,為了測試負載均衡 二、測試條件(測試環境) 模擬兩臺伺服器 使用本機跑兩個Web專案: tomcat:8080埠 tomcat:9090埠   Centos7作為nginx負載均衡伺服

Linux Redis的安裝 啟動 連線 配置 重啟

Linux下安裝]# wget http://download.redis.io/releases/redis-2.8.17.tar.gz ]# tar xzf redis-2.8.17.tar.gz ]# cd redis-2.8.17 ]# make啟動redis服務]#

phantomjs(幽靈瀏覽器)的安裝啟動使用

1.下載安裝下載地址:http://phantomjs.org/download.html下載解壓後開啟phantomjs-2.1.1-windows資料夾,找到bin資料夾並開啟,將phantomjs.exe複製到和python.exe放在同一目錄下.可以在cmd.exe中

NginX之一:window下安裝部署配置負載均衡

下載完成,比如放在C盤根目錄下: cd c:\ unzip nginx-1.15.3.zip //解壓檔案 cd nginx-1.15.3 //進入目錄 start nginx //啟動服務 此時視窗一閃而過,如何檢測服務是否啟動了呢?(中文路徑可能有問題) 執行t

nginx伺服器安裝啟動配置檔案詳解

1.安裝Nginx 1.1 選擇穩定nginx版本 centos的yum不提供nginx安裝,通過配置官方yum源的方式獲取到的也只是原始碼包。所以我們找到了Nginx官網看下官方提供的安裝方式:Nginx原始碼包下載的官網地址(http://nginx

elasticsearch安裝啟動

         2.2  下載壓縮包 解壓 在解壓目錄裡開啟dos視窗.              輸入:node –v   驗證node.js是否安裝                               2.4         3.修改elasticsearch 

(一)elasticsearch-5.x安裝配置

head(一)平臺所需的環境OS:CentOS 7.x minimalelasticsearch :elasticsearch-5.4.0版本jdk: 1.8已上版本創建普通用戶:appuser最新的下載路徑地址為:https://www.elastic.co/downloads (二)配置操作系統的環境並

Apache Tomcat安裝配置啟動後續操作步驟

文件解壓 相對 ref 自己的 控制臺 應用 為我 。。 start 1.第一,我們在安裝Apache Tomcat之前,我們首先安裝和配置好jdk; 2.第二,我們要清楚自己的jdk版本。因為我們Apache Tomcat配置的成功的前提是版本相對應。在這裏,博主是用下圖

ELK學習記錄二 :elasticsearch、logstash及kibana的安裝配置

jre_home 支持 number yml num des 安裝包 soft filters 註意事項: 1.ELK版本要求5.X以上,本人使用版本:elasticsearch-6.0.0、kibana-6.0.0-linux-x86_64、logstash-6.0.0.