Elasticsearch 單機(jī)多節(jié)點(diǎn)
- 下載Elasticsearch安裝包(本文實(shí)驗(yàn)環(huán)境版本為5.5.1)
- 將安裝包復(fù)制多份,然后修改Elasticsearch目錄中
config
下的elasticsearch.yml
文件下列屬性值:
cluster.name: pekxxoo
node.name: node-2
node.max_local_storage_nodes: 2
http.port: 9201
cluster.name: 保證集群名稱一致,再啟動(dòng)時(shí)相同集群名稱的節(jié)點(diǎn)會(huì)自動(dòng)加入到集群中
node.name: 節(jié)點(diǎn)名稱,自己定義,只要相互不沖突就可以;
node.max_local_storage_nodes:最大節(jié)點(diǎn)個(gè)數(shù),按照你準(zhǔn)備部署的個(gè)數(shù)設(shè)置;
http.port: 端口號(hào),只要不沖突就行;
- 進(jìn)入Elasticsearch安裝包
\bin
目錄下,執(zhí)行下列命令將其安裝為本機(jī)服務(wù):
elasticsearch-service.bat install
這里需要注意,因?yàn)槲覀兪沁M(jìn)行單機(jī)多節(jié)點(diǎn)安裝,因此需要修改elasticsearch-service.bat
文件中的服務(wù)名稱,避免本機(jī)服務(wù)名沖突,我的修改如下:
if errorlevel 1 goto x86
set EXECUTABLE=%ES_HOME%\bin\elasticsearch-service-x64.exe
set SERVICE_ID=elasticsearch-service-x64-2
set ARCH=64-bit
goto checkExe
:x86
set EXECUTABLE=%ES_HOME%\bin\elasticsearch-service-x86.exe
set SERVICE_ID=elasticsearch-service-x86-2
set ARCH=32-bit
只需修改上文中set SERVICE_ID
等號(hào)后的值即可;
- 然后在
\bin
目錄下運(yùn)行elasticsearch-service.bat manager
命令,打開服務(wù)管理界面,啟動(dòng)服務(wù);
cat命令
當(dāng)節(jié)點(diǎn)都運(yùn)行起來后,我們可以使用如下命令查詢相關(guān)信息:
curl host:port/_cat
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 493 100 493 0 0 32866 0 --:--:-- --:--:-- --:--:-- 481k=^.^=
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/tasks
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/thread_pool/{thread_pools}
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}
/_cat/templates
以上列出了_cat
命令可以查詢的相關(guān)信息
headers
headers
通過這個(gè)參數(shù)可以指定輸出的字段
curl host:port/_cat/master?h=host,ip,node
Head插件
ES集群管理工具,它是完全油html5編寫的獨(dú)立網(wǎng)頁程序,可視化管理集群狀態(tài)
- https://github.com/mobz/elasticsearch-head
- 命令行安裝:在
Elasticsearch
的bin
目錄下執(zhí)行:plugin install mobz/elasticsearch-head
(5.x以上版本不支持站點(diǎn)插件安裝)
5.x安裝Head插件
Running with built in server
- git clone git://github.com/mobz/elasticsearch-head.git
- cd elasticsearch-head
- npm install
- npm run start
- open http://localhost:9100/
沒有安裝npm
的這里不做詳細(xì)描述,可以參考這里
5.x版本的elasticsearch
可能會(huì)出現(xiàn)訪問http://localhost:9100/后不能連接集群的狀況,需要在配置文件elasticsearch.yml
中加入以下內(nèi)容:
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization
現(xiàn)在就可以成功使用elasticsearch-head
方便的管理集群:
image.png