Elasticsearch 官網:https://www.elastic.co
Elasticsearch封裝了支持索引和全文搜索的Lucene的強大且復雜難以使用功能,同時,Elasticsearch提供分布式實時文件存儲和實時分析搜索引擎,具有可擴展性。這些功能全部集成在ES服務里,支持各種語音的應用、客戶端、命令行只需要調用它提供的操作簡單的REST API 的接口,就可以與之交互。它開箱即用,就是說安裝即可用。
安裝准備
Linux操作系統(我的是CentOS 7.6 x86_64)
JDK1.8.*(我的是系統自帶的 V1.8.0_181)
創建用戶
#創建組 [root@bogon ~]# groupadd es #創建用戶 [root@bogon ~]# useradd es -g es #設置密碼 [root@bogon ~]# echo "自定義密碼"|passwd es --stdin 更改用戶 es 的密碼 。 passwd:所有的身份驗證令牌已經成功更新。 #切換到es用戶 [root@bogon ~]# su - es
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.1.tar.gz
tar -zxvf elasticsearch-6.4.1.tar.gz
/home/es/elasticsearch-6.4.1

[es@bogon ~]$ elasticsearch-6.4.1/bin/elasticsearch [2019-10-17T09:43:29,363][INFO ][o.e.n.Node ] [] initializing ... [2019-10-17T09:43:29,409][INFO ][o.e.e.NodeEnvironment ] [uyS3a_p] using [1] data paths, mounts [[/home (/dev/mapper/centos-home)]], net usable_space [140.6gb], net total_space [141.5gb], types [xfs] [2019-10-17T09:43:29,409][INFO ][o.e.e.NodeEnvironment ] [uyS3a_p] heap size [989.8mb], compressed ordinary object pointers [true] [2019-10-17T09:43:29,410][INFO ][o.e.n.Node ] [uyS3a_p] node name derived from node ID [uyS3a_pATBG5NwZNzfpWJQ]; set [node.name] to override [2019-10-17T09:43:29,410][INFO ][o.e.n.Node ] [uyS3a_p] version[6.4.1], pid[24171], build[default/tar/e36acdb/2018-09-13T22:18:07.696808Z], OS[Linux/3.10.0-957.el7.x86_64/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/1.8.0_181/25.181-b13] [2019-10-17T09:43:29,410][INFO ][o.e.n.Node ] [uyS3a_p] 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, -Djava.io.tmpdir=/tmp/elasticsearch.kJBGHbPY, -XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=data, -XX:ErrorFile=logs/hs_err_pid%p.log, -XX:+PrintGCDetails, -XX:+PrintGCDateStamps, -XX:+PrintTenuringDistribution, -XX:+PrintGCApplicationStoppedTime, -Xloggc:logs/gc.log, -XX:+UseGCLogFileRotation, -XX:NumberOfGCLogFiles=32, -XX:GCLogFileSize=64m, -Des.path.home=/home/es/elasticsearch-6.4.1, -Des.path.conf=/home/es/elasticsearch-6.4.1/config, -Des.distribution.flavor=default, -Des.distribution.type=tar] [2019-10-17T09:43:30,461][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [aggs-matrix-stats] [2019-10-17T09:43:30,461][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [analysis-common] [2019-10-17T09:43:30,462][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [ingest-common] [2019-10-17T09:43:30,462][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [lang-expression] [2019-10-17T09:43:30,462][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [lang-mustache] [2019-10-17T09:43:30,462][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [lang-painless] [2019-10-17T09:43:30,462][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [mapper-extras] [2019-10-17T09:43:30,462][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [parent-join] [2019-10-17T09:43:30,462][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [percolator] [2019-10-17T09:43:30,462][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [rank-eval] [2019-10-17T09:43:30,462][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [reindex] [2019-10-17T09:43:30,462][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [repository-url] [2019-10-17T09:43:30,462][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [transport-netty4] [2019-10-17T09:43:30,462][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [tribe] [2019-10-17T09:43:30,463][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [x-pack-core] [2019-10-17T09:43:30,463][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [x-pack-deprecation] [2019-10-17T09:43:30,463][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [x-pack-graph] [2019-10-17T09:43:30,463][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [x-pack-logstash] [2019-10-17T09:43:30,463][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [x-pack-ml] [2019-10-17T09:43:30,463][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [x-pack-monitoring] [2019-10-17T09:43:30,463][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [x-pack-rollup] [2019-10-17T09:43:30,463][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [x-pack-security] [2019-10-17T09:43:30,463][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [x-pack-sql] [2019-10-17T09:43:30,463][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [x-pack-upgrade] [2019-10-17T09:43:30,463][INFO ][o.e.p.PluginsService ] [uyS3a_p] loaded module [x-pack-watcher] [2019-10-17T09:43:30,464][INFO ][o.e.p.PluginsService ] [uyS3a_p] no plugins loaded [2019-10-17T09:43:33,206][INFO ][o.e.x.s.a.s.FileRolesStore] [uyS3a_p] parsed [0] roles from file [/home/es/elasticsearch-6.4.1/config/roles.yml] [2019-10-17T09:43:33,554][INFO ][o.e.x.m.j.p.l.CppLogMessageHandler] [controller/24250] [Main.cc@109] controller (64 bit): Version 6.4.1 (Build 1df3104bc26648) Copyright (c) 2018 Elasticsearch BV [2019-10-17T09:43:33,785][DEBUG][o.e.a.ActionModule ] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security [2019-10-17T09:43:33,905][INFO ][o.e.d.DiscoveryModule ] [uyS3a_p] using discovery type [zen] [2019-10-17T09:43:34,339][INFO ][o.e.n.Node ] [uyS3a_p] initialized [2019-10-17T09:43:34,339][INFO ][o.e.n.Node ] [uyS3a_p] starting ... [2019-10-17T09:43:34,476][INFO ][o.e.t.TransportService ] [uyS3a_p] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300} [2019-10-17T09:43:37,551][INFO ][o.e.c.s.MasterService ] [uyS3a_p] zen-disco-elected-as-master ([0] nodes joined)[, ], reason: new_master {uyS3a_p}{uyS3a_pATBG5NwZNzfpWJQ}{5saUm0dRTbK0825eT3pO7w}{127.0.0.1}{127.0.0.1:9300}{ml.machine_memory=16358428672, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true} [2019-10-17T09:43:37,556][INFO ][o.e.c.s.ClusterApplierService] [uyS3a_p] new_master {uyS3a_p}{uyS3a_pATBG5NwZNzfpWJQ}{5saUm0dRTbK0825eT3pO7w}{127.0.0.1}{127.0.0.1:9300}{ml.machine_memory=16358428672, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true}, reason: apply cluster state (from master [master {uyS3a_p}{uyS3a_pATBG5NwZNzfpWJQ}{5saUm0dRTbK0825eT3pO7w}{127.0.0.1}{127.0.0.1:9300}{ml.machine_memory=16358428672, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)[, ]]]) [2019-10-17T09:43:37,569][INFO ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [uyS3a_p] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200} [2019-10-17T09:43:37,569][INFO ][o.e.n.Node ] [uyS3a_p] started [2019-10-17T09:43:37,583][WARN ][o.e.x.s.a.s.m.NativeRoleMappingStore] [uyS3a_p] Failed to clear cache for realms [[]] [2019-10-17T09:43:37,612][INFO ][o.e.g.GatewayService ] [uyS3a_p] recovered [0] indices into cluster_state [2019-10-17T09:43:37,715][INFO ][o.e.c.m.MetaDataIndexTemplateService] [uyS3a_p] adding template [.watch-history-9] for index patterns [.watcher-history-9*] [2019-10-17T09:43:37,737][INFO ][o.e.c.m.MetaDataIndexTemplateService] [uyS3a_p] adding template [.triggered_watches] for index patterns [.triggered_watches*] [2019-10-17T09:43:37,756][INFO ][o.e.c.m.MetaDataIndexTemplateService] [uyS3a_p] adding template [.watches] for index patterns [.watches*] [2019-10-17T09:43:37,779][INFO ][o.e.c.m.MetaDataIndexTemplateService] [uyS3a_p] adding template [.monitoring-logstash] for index patterns [.monitoring-logstash-6-*] [2019-10-17T09:43:37,803][INFO ][o.e.c.m.MetaDataIndexTemplateService] [uyS3a_p] adding template [.monitoring-es] for index patterns [.monitoring-es-6-*] [2019-10-17T09:43:37,827][INFO ][o.e.c.m.MetaDataIndexTemplateService] [uyS3a_p] adding template [.monitoring-beats] for index patterns [.monitoring-beats-6-*] [2019-10-17T09:43:37,845][INFO ][o.e.c.m.MetaDataIndexTemplateService] [uyS3a_p] adding template [.monitoring-alerts] for index patterns [.monitoring-alerts-6] [2019-10-17T09:43:37,866][INFO ][o.e.c.m.MetaDataIndexTemplateService] [uyS3a_p] adding template [.monitoring-kibana] for index patterns [.monitoring-kibana-6-*] [2019-10-17T09:43:37,953][INFO ][o.e.l.LicenseService ] [uyS3a_p] license [6e085e8f-9539-4f07-acdb-06ec3793e20e] mode [basic] - valid
啟動遇到問題1
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536] #原因:無法創建本地文件問題,用戶最大可創建文件數太小
需要修改配置文件limits.conf,永久(非暫時性的)改系統的“最大進程數”和“最大文件打開數限制”:
* soft nofile 65536
* hard nofile 65536
* soft nproc 4096
* hard nproc 4096
#切換到root用戶 [es@bogon elasticsearch-6.4.1]$ su - root 密碼: 上一次登錄:四 10月 17 10:15:10 CST 2019pts/1 上 #進入編輯模式 [root@bogon ~]# vim /etc/security/limits.conf
前面的*符號必須帶上。
執行完成后可以使用命令 ulimit -n 查看最大進程數,用ulimit -u查看用戶最大文件打開數
[root@bogon ~]# ulimit -n 65536 [root@bogon ~]# ulimit -u 4096
啟動遇到問題2
ERROR: [1] bootstrap checks failed [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] #原因:最大虛擬內存太小,需要修改系統變量的最大值。
修改配置sysctl.conf 增加配置值: vm.max_map_count=262144
#注意:需要切換到root用戶 #進入編輯模式 [root@bogon ~]# vim /etc/sysctl.conf
執行之后查看
[root@bogon ~]# sysctl -p vm.max_map_count = 262144
啟動遇到問題3
max number of threads [1024] for user [es] likely too low, increase to at least [2048] #原因:無法創建本地線程問題,用戶最大可創建線程數太小
需要切換到root用戶,進入limits.d目錄下,修改90-nproc.conf 或20-nproc.conf配置文件,* soft nproc 1024 改為* soft nproc 2048
但是我的機器不存在這個錯誤,所以沒有作任何修改,查看我的機器信息:
#查看20-nproc.conf文件
[root@bogon ~]# vim /etc/security/limits.d/20-nproc.conf
# Default limit for number of user's processes to prevent # accidental fork bombs. # See rhbz #432903 for reasoning. * soft nproc 4096 root soft nproc unlimited
啟動遇到問題4
system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk #原因:Centos6不支持SecComp,而ES6.4.2默認bootstrap.system_call_filter為true進行檢測,所以導致檢測失敗,失敗后直接導致ES不能啟動。
在es安裝目錄下的./config/elasticsearch.yml中新增配置bootstrap.system_call_filter,設為false,注意要在Memory下面添加:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
如果已經啟動了服務,重新啟動ES服務就可。
我的機器不存在這個錯誤,所以並沒有添加這段配置。
調用RESTful API
前面說了,ES提供了簡單的RESTful API給應用或客戶端調用。默認在9200端口運行,現在打開另一個命令終端,發請求至該端口,會得到以下的jason返回:
[es@bogon elasticsearch-6.3.2]$ curl localhost:9200
{
"name" : "uyS3a_p", "cluster_name" : "elasticsearch", "cluster_uuid" : "mg7654_-T7eUMmtn7RLznQ", "version" : { "number" : "6.4.1", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "e36acdb", "build_date" : "2018-09-13T22:18:07.696808Z", "build_snapshot" : false, "lucene_version" : "7.4.0", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search" }
一個單節點的elasticsearch就啟動成功了!
如果想配一個稍個性化的ES服務,還需要對配置文件做一些簡單設置,如下。
其他ES配置
修改配置文件elasticsearch.yml
#進入ES安裝目錄 [es@bogon ~]$ cd /home/es/elasticsearch-6.4.1 #備份./config/elasticsearch.yml文件 [es@bogon elasticsearch-6.4.1]$ cp -a config/elasticsearch.yml{,_$(date +%F)} #查看./config目錄內容 [es@bogon elasticsearch-6.4.1]$ ls config elasticsearch.keystore jvm.options roles.yml elasticsearch.yml log4j2.properties users elasticsearch.yml_2019-10-17 role_mapping.yml users_roles #進入編輯模式 [es@bogon elasticsearch-6.4.1]$ vim config/elasticsearch.yml
設置集群名稱,節點名,數據路徑和日志路徑;注意格式,所有參數名的冒號的后面都要有個空格!
cluster.name: lsy-application
node.name: node1
path.data: /home/es/elasticsearch-6.4.1/data
path.logs: /home/es/elasticsearch-6.4.1/logs
重啟ES服務
在服務啟動窗口,用Ctrl+C關閉服務
可能會遇到的問題
[es@bogon elasticsearch-6.4.1]$ bin/elasticsearch [2019-10-17T19:09:39,311][INFO ][o.e.n.Node ] [node1] initializing ... [2019-10-17T19:09:39,333][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [node1] uncaught exception in thread [main] org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: failed to obtain node locks, tried [[/home/es/elasticsearch-6.4.1/data/lsy-application]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])? at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:140) ~[elasticsearch-6.4.1.jar:6.4.1] at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.4.1.jar:6.4.1] at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.4.1.jar:6.4.1] at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.4.1.jar:6.4.1] at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.4.1.jar:6.4.1] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.4.1.jar:6.4.1] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.4.1.jar:6.4.1] Caused by: java.lang.IllegalStateException: failed to obtain node locks, tried [[/home/es/elasticsearch-6.4.1/data/lsy-application]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])? at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:243) ~[elasticsearch-6.4.1.jar:6.4.1] at org.elasticsearch.node.Node.<init>(Node.java:274) ~[elasticsearch-6.4.1.jar:6.4.1] at org.elasticsearch.node.Node.<init>(Node.java:256) ~[elasticsearch-6.4.1.jar:6.4.1] at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:213) ~[elasticsearch-6.4.1.jar:6.4.1] at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:213) ~[elasticsearch-6.4.1.jar:6.4.1] at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[elasticsearch-6.4.1.jar:6.4.1] at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.4.1.jar:6.4.1] ... 6 more # 關鍵字是failed to obtain node locks, 就是綁定節點失敗!!!導致的原因可能是因為之前運行的es還沒有正常關閉
解決方案是殺掉進程
#查看elastic進程,建議在root和es用戶下都查一下! [root@bogon ~]# ps -ef | grep elastic es 28377 1 1 18:57 ? 00:00:31 /bin/java -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 -Djava.io.tmpdir=/tmp/elasticsearch.GVB61OVI -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -Xloggc:logs/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=32 -XX:GCLogFileSize=64m -Des.path.home=/home/es/elasticsearch-6.4.1 -Des.path.conf=/home/es/elasticsearch-6.4.1/config -Des.distribution.flavor=default -Des.distribution.type=tar -cp /home/es/elasticsearch-6.4.1/lib/* org.elasticsearch.bootstrap.Elasticsearch -d es 28402 28377 0 18:57 ? 00:00:00 /home/es/elasticsearch-6.4.1/modules/x-pack-ml/platform/linux-x86_64/bin/controller root 29676 29628 0 19:26 pts/0 00:00:00 grep --color=auto elastic #強殺掉進程 [root@bogon ~]# kill -9 28377 28402
用es用戶登陸,在es安裝目錄下,可以用 bin/elasticsearch命令重新啟動服務,也可以加-d在后台啟動
#后台啟動服務 [es@bogon ~]$ elasticsearch-6.4.1/bin/elasticsearch -d #看看ES后台進程是否啟起來了 [es@bogon ~]$ ps -ef |grep elastic es 30281 1 99 19:33 pts/0 00:00:20 /bin/java -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 -Djava.io.tmpdir=/tmp/elasticsearch.adpgCFjE -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -Xloggc:logs/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=32 -XX:GCLogFileSize=64m -Des.path.home=/home/es/elasticsearch-6.4.1 -Des.path.conf=/home/es/elasticsearch-6.4.1/config -Des.distribution.flavor=default -Des.distribution.type=tar -cp /home/es/elasticsearch-6.4.1/lib/* org.elasticsearch.bootstrap.Elasticsearch -d es 30306 30281 0 19:33 pts/0 00:00:00 /home/es/elasticsearch-6.4.1/modules/x-pack-ml/platform/linux-x86_64/bin/controller es 30351 29760 0 19:33 pts/0 00:00:00 grep --color=auto elastic #發送API請求,注意name和cluster_name已經是我們剛剛自定義的名字了 [es@bogon ~]$ curl localhost:9200 { "name" : "node1", "cluster_name" : "lsy-application", "cluster_uuid" : "mg7654_-T7eUMmtn7RLznQ", "version" : { "number" : "6.4.1", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "e36acdb", "build_date" : "2018-09-13T22:18:07.696808Z", "build_snapshot" : false, "lucene_version" : "7.4.0", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search" }
#成功!
在瀏覽器輸入鏈接 localhost:9200,也可以看到相同的內容
這個url可以查看集群的健康狀態: http://localhost:9200/_cluster/health?pretty
網絡配置network.host
在配置文件 network.host參數默認使用local,這也就是為什么我們在調用API的時候使用的localhost:9200。這個參數接受 ip 地址,主機名,指定值或者包含這些值的數組!節點將綁定到一個主機名或者 ip 地址並且會將該這個節點通知集群中的其他節點。
- 如果想通過集群外部機器連接elasticsearch服務,也就是設置外網訪問,需配成 network.host: 0.0.0.0 ,並開通集群硬件防火牆相應端口。
- 如果不需要外網訪問的話, 就配置127.0.0.1或者對應的內網ip就行。
#進入編輯模式
[es@bogon ~]$ vim elasticsearch-6.4.1/config/elasticsearch.yml
#-------------------------------------在文件中設置network.host---------------------------------------------- # ---------------------------------- Network ----------------------------------- # # Set the bind address to a specific IP (IPv4 or IPv6): # #network.host: 192.168.0.1 network.host: 192.168.89.66
保存之后,重啟服務,再調用API,使用192.168.89.66:9200