ElasticSearch 安裝啟動與配置

https://blog.csdn.net/cool__7/article/details/81136987

簡介

ElasticSearch是一個開源免費(fèi)罢绽,用Java開發(fā)的,基于Lucene框架的静盅,提供RESTful web接口的良价、分布式多用戶能力的,實(shí)時的分布式搜索分析引擎。簡單高效棚壁,開箱即用杯矩。

安裝

在安裝ElasticSearch 之前,我們需要先安裝一個java袖外,為什么呢史隆?因為ElasticSearch 是java語言開發(fā)的。

這里要提醒一下曼验,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很方便,解壓就可以直接用了鬓照,下面我們嘗試運(yùn)行一下熔酷。

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

結(jié)果啟動報錯了

 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用戶來創(chuàng)建新的用戶 , groupadd 添加一個用戶組
[root@localhost home]# groupadd elk
# 添加一個用戶臭猜,-g是在用戶組下 -p是密碼
[root@localhost home]# useradd elk -g elk -p elk
# 進(jìn)入es的安裝目錄
[root@localhost home]# cd /home/elasticsearch 
# 給用戶elk授權(quán)
[root@localhost home]# chown -R elk:elk elasticsearch-6.3.1/
# 切換到 elk用戶
[root@localhost elasticsearch]# su elk

到這里新的用戶也創(chuàng)建好了躺酒,也授權(quán)了,接下來我們重新啟動一下

[elasticsearch@localhost 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"
}

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

也沒問題次屠,好了园匹,到現(xiàn)在為止我們的elasticsearch服務(wù)就搭建成功了,接下來我們來看配置

配置

先來看一下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:
# 定義該節(jié)點(diǎn)的名稱劫灶,每個節(jié)點(diǎn)不可以重復(fù)
#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):
# 配置數(shù)據(jù)存放目錄
#path.data: /path/to/data
#
# Path to log files:
# 配置日志目錄
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
# 關(guān)閉鎖定內(nèi)存
#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):
# 指定本機(jī)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部分

在開始之前裸违,我們首先得確保 宿主機(jī)和虛擬機(jī)的網(wǎng)絡(luò)是互相可以ping通的。

注意關(guān)閉宿主機(jī)和虛擬機(jī)的防火墻哦浑此,不然會遇到各種莫名其妙的問題累颂,關(guān)閉防火墻命令

通過修改 elasticsearch.yml配置,我們來實(shí)現(xiàn)局域網(wǎng)內(nèi)訪問elasticsearch服務(wù)凛俱,將host和port相應(yīng)配置修改成局域網(wǎng)的一個固定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.

執(zhí)行啟動命令 ./bin/elasticsearch 啟動后蒲犬,會發(fā)現(xiàn)報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]是因為操作系統(tǒng)vm.max_map_count參數(shù)設(shè)置太小導(dǎo)致的原叮,至于設(shè)置多大的數(shù)值,我這里就直接參照報錯信息的建議直接設(shè)置為262144

解決方案一:

切換到root用戶下,執(zhí)行以下命令:

sysctl -w vm.max_map_count=262144

檢查配置是否生效

root@ubuntu:~# 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
root@ubuntu:~# 

2奋隶、報錯max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]是因為操作系統(tǒng)安全檢測配置影響的擂送,我們需要切換到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

執(zhí)行啟動命令 ./bin/elasticsearch ,會發(fā)現(xiàn)指定IP已經(jīng)配置好了唯欣,也正常啟動嘹吨。

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}

接下來 瀏覽器訪問

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市境氢,隨后出現(xiàn)的幾起案子蟀拷,更是在濱河造成了極大的恐慌,老刑警劉巖萍聊,帶你破解...
    沈念sama閱讀 206,482評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件问芬,死亡現(xiàn)場離奇詭異,居然都是意外死亡寿桨,警方通過查閱死者的電腦和手機(jī)此衅,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,377評論 2 382
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來亭螟,“玉大人挡鞍,你說我怎么就攤上這事∶接叮” “怎么了匕累?”我有些...
    開封第一講書人閱讀 152,762評論 0 342
  • 文/不壞的土叔 我叫張陵,是天一觀的道長默伍。 經(jīng)常有香客問我欢嘿,道長,這世上最難降的妖魔是什么也糊? 我笑而不...
    開封第一講書人閱讀 55,273評論 1 279
  • 正文 為了忘掉前任炼蹦,我火速辦了婚禮,結(jié)果婚禮上狸剃,老公的妹妹穿的比我還像新娘掐隐。我一直安慰自己,他們只是感情好钞馁,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,289評論 5 373
  • 文/花漫 我一把揭開白布虑省。 她就那樣靜靜地躺著,像睡著了一般僧凰。 火紅的嫁衣襯著肌膚如雪探颈。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,046評論 1 285
  • 那天训措,我揣著相機(jī)與錄音伪节,去河邊找鬼光羞。 笑死,一個胖子當(dāng)著我的面吹牛怀大,可吹牛的內(nèi)容都是我干的纱兑。 我是一名探鬼主播,決...
    沈念sama閱讀 38,351評論 3 400
  • 文/蒼蘭香墨 我猛地睜開眼化借,長吁一口氣:“原來是場噩夢啊……” “哼潜慎!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起屏鳍,我...
    開封第一講書人閱讀 36,988評論 0 259
  • 序言:老撾萬榮一對情侶失蹤勘纯,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后钓瞭,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體驳遵,經(jīng)...
    沈念sama閱讀 43,476評論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,948評論 2 324
  • 正文 我和宋清朗相戀三年山涡,在試婚紗的時候發(fā)現(xiàn)自己被綠了堤结。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,064評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡鸭丛,死狀恐怖竞穷,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情鳞溉,我是刑警寧澤瘾带,帶...
    沈念sama閱讀 33,712評論 4 323
  • 正文 年R本政府宣布,位于F島的核電站熟菲,受9級特大地震影響看政,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜抄罕,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,261評論 3 307
  • 文/蒙蒙 一允蚣、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧呆贿,春花似錦嚷兔、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,264評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至竟块,卻和暖如春翩剪,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背彩郊。 一陣腳步聲響...
    開封第一講書人閱讀 31,486評論 1 262
  • 我被黑心中介騙來泰國打工前弯, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人秫逝。 一個月前我還...
    沈念sama閱讀 45,511評論 2 354
  • 正文 我出身青樓恕出,卻偏偏與公主長得像,于是被迫代替她去往敵國和親违帆。 傳聞我的和親對象是個殘疾皇子浙巫,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,802評論 2 345