環(huán)境準(zhǔn)備
1.虛擬機(jī)CentOS7.6
2.elasticsearch7.8.0:https://www.elastic.co/cn/downloads/past-releases/elasticsearch-7-8-0
將tar包解壓到指定目錄
配置文件
1.Linux環(huán)境安裝了jdk的,會(huì)和es自帶jdk沖突,需要指定使用自帶jdk,修改es的bin目錄下elasticsearch如下:
# ES_JAVA_OPTS="-Xms8g -Xmx8g" ./bin/elasticsearch
#=======添加配置解決jdk版本問(wèn)題=====
export JAVA_HOME=/app/software/elasticsearch/elasticsearch-7.8.0-target/jdk
export PATH=$JAVA_HOME/bin:$PATH
#============
source "`dirname "$0"`"/elasticsearch-env
ES_JAVA_OPTS=`export ES_TMPDIR; "$JAVA" "$XSHARE" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.JvmOptionsParser "$ES_PATH_CONF"`
#=======添加配置解決jdk版本問(wèn)題=====
if [ -x "$JAVA_HOME/bin/java" ]; then
JAVA="/app/software/elasticsearch/elasticsearch-7.8.0-target/jdk/bin/java"
else
JAVA=`which java`
fi
#============
# manual parsing to find out, if process should be detached
2.如果機(jī)器內(nèi)存不夠用,需要調(diào)小啟動(dòng)內(nèi)存,在es的config目錄下jvm.options文件:
默認(rèn)配置如下:
-Xms2g
-Xmx2g
默認(rèn)的配置占用內(nèi)存太多了,調(diào)小一些:
-Xms256m
-Xmx256m
3.創(chuàng)建啟動(dòng)用戶:es不允許用root啟動(dòng),創(chuàng)建一個(gè)user-es用戶:
①useradd user-es
②chown user-es:user-es -R /app/software/elasticsearch/elasticsearch-7.8.0
4.修改屬性值:在config目錄下的elasticsearch.yml
①path.data和path.log不指定會(huì)默認(rèn)在es目錄下
②network.host: 0.0.0.0
③cluster.name: elasticsearch
node.name: node1
cluster.initial_master_nodes: [“node1”]
④http.port: 9200
啟動(dòng)Elasticsearch
①切換到user-es:su user-es
②進(jìn)入es的bin目錄,./elasticsearch啟動(dòng)es,觀察啟動(dòng)日志
遇到的兩個(gè)錯(cuò)誤:
1.ERROR: [1] bootstrap checks failed. You must address the points described in the following [1] lines before starting Elasticsearch.
bootstrap check failure [1] of [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解決方法:在 /etc/sysctl.conf 文件最后添加如下內(nèi)容,即可永久修改
切換到root用戶
執(zhí)行命令:su root
執(zhí)行命令
vim /etc/sysctl.conf
添加如下內(nèi)容
vm.max_map_count=262144
保存退出,刷新配置文件
sysctl -p
切換user-es用戶,繼續(xù)啟動(dòng)
su user-es
啟動(dòng)es服務(wù)
./bin/elasticsearch
2.[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
解決方法:切換到root用戶,執(zhí)行命令:
vi /etc/security/limits.conf
#<domain> <type> <item> <value>
#
#* soft core 0
#* hard rss 10000
* soft nofile 65536
* hard nofile 65536
#@student hard nproc 20
reboot重啟服務(wù)器,再./bin/elasticsearch重啟es
瀏覽器訪問(wèn)http://虛擬機(jī)ip:9200/后看到類似如下信息,表示ES啟動(dòng)成功文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-600297.html
{
"name": "node1",
"cluster_name": "elasticsearch",
"cluster_uuid": "SRwJX4sYQ8el4N5wj4tOmA",
"version": {
"number": "7.8.0",
"build_flavor": "default",
"build_type": "tar",
"build_hash": "4d960a0733be83dd2543ca018aa4ddc42e956800",
"build_date": "2021-06-10T21:01:55.251515791Z",
"build_snapshot": false,
"lucene_version": "8.8.2",
"minimum_wire_compatibility_version": "6.8.0",
"minimum_index_compatibility_version": "6.0.0-beta1"
},
"tagline": "You Know, for Search"
}
集群搭建
1.克隆兩臺(tái)機(jī)器,將剛剛的es壓縮包解壓到相同路徑
2.修改配置文件:
①cluster.name: elasticsearch7.8.0(三個(gè)節(jié)點(diǎn)名字要相同)
②node.name: node1(各不相同)
③節(jié)點(diǎn)類型node.master負(fù)責(zé)調(diào)度,node.data負(fù)責(zé)存儲(chǔ)數(shù)據(jù),正式環(huán)境一般主節(jié)點(diǎn)不要存儲(chǔ)數(shù)據(jù),每個(gè)節(jié)點(diǎn)單一功能整體效率更高。我的三個(gè)配置:
第一臺(tái)
node.master: true
node.data: false
node.ingest: false
第二臺(tái)
node.master: true
node.data: true
node.ingest: false
第三臺(tái)
node.master: true
node.data: true
node.ingest: false
④寫入候選主節(jié)點(diǎn):discovery.seed_hosts: [“192.168.32.1”, “192.168.32.2”,“192.168.32.3”]
⑤初始化集群選舉master:cluster.initial_master_nodes: [“node2”]
配置完逐臺(tái)重啟即可。我是啟動(dòng)es單獨(dú)一個(gè)窗口,要退出直接ctrl+c,其他操作在新的窗口。
連接linux推薦SSH工具:MobaXterm,開源免費(fèi),相當(dāng)于xshell和xftp的合體,操作命令時(shí)能同時(shí)傳輸文件,功能十分強(qiáng)大。
驗(yàn)證:瀏覽器訪問(wèn)http://192.168.32.2:9200/_cat/nodes?v(任意集群節(jié)點(diǎn)),出現(xiàn)類似以下信息則證明集群搭建完成文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-600297.html
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
192.168.32.1 19 71 2 29.07 10.51 4.49 lmr - node1-source
192.168.32.2 8 61 0 7.07 2.58 0.99 dlmrt * node2-source
192.168.32.3 8 96 1 0.04 0.04 0.05 dlmrt - node3-source
到了這里,關(guān)于Linux搭建ElasticSearch單節(jié)點(diǎn)及集群的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!