本篇文章主要講解centos7下es的安裝
下載安裝包
直接訪問es官網,下載
上傳安裝包到虛擬機並解壓
-
上傳到
/home/software/
-
解壓壓縮包
tar -zxvf elasticsearch-7.5.1-linux-x86_64.tar.gz
- 移動解壓后的es文件夾
mv elasticsearch-7.5.1 /usr/local/
es 目錄介紹
- bin:可執行文件在里面,運行es的命令就在這個里面,包含了一些腳本文件等
- config:配置文件目錄
- JDK:java環境
- lib:依賴的jar,類庫
- logs:日志文件
- modules:es相關的模塊
- plugins:可以自己開發的插件
- data:這個目錄沒有,自己新建一下,后面要用 -> mkdir data,這個作為索引目錄
修改核心配置文件elasticearch.yml
- 修改集群名稱
- 修改當前的es節點名稱
- 修改data數據保存地址和日志數據保存地址
- 綁定es網絡ip
- 集群節點修改為之前的節點名稱
修改jvm參數
打開 jvm.options
文件
這里使用的是虛擬機
## JVM configuration
################################################################
## IMPORTANT: JVM heap size
################################################################
##
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
# 修改這里的配置
-Xms128m
-Xmx128m
添加用戶
ES不允許使用root操作es,需要添加用戶,操作如下:
useradd esuser
chown -R esuser:esuser /usr/local/elasticsearch-7.5.1
su esuser
啟動es
./elasticsearch
如果出現如下錯誤:
ERROR: [3] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max number of threads [3795] for user [esuser] is too low, increase to at least [4096]
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
需要切換到root用戶修改配置
- 修改/etc/security/limits.conf 文件
增加下面內容
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
- 修改 /etc/sysctl.conf 增加
vm.max_map_count=262145
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
vm.max_map_count=262145
修改完后 sysctl -p
刷新一下
再次切換到esuser 進行啟動
啟動與暫停
啟動方式1
運行 ./elasticsearch
看到運行結果
[2020-02-02T01:09:51,843][INFO ][o.e.h.AbstractHttpServerTransport] [es-node0] publish_address {192.168.247.8:9200}, bound_addresses {[::]:9200}
[2020-02-02T01:09:51,844][INFO ][o.e.n.Node ] [es-node0] started
[2020-02-02T01:09:52,199][INFO ][o.e.l.LicenseService ] [es-node0] license [9614ee2b-6350-4f99-ad43-5ec0d632f93c] mode [basic] - valid
[2020-02-02T01:09:52,200][INFO ][o.e.x.s.s.SecurityStatusChangeListener] [es-node0] Active license is now [BASIC]; Security is disabled
[2020-02-02T01:09:52,222][INFO ][o.e.g.GatewayService ] [es-node0] recovered [0] indices into cluster_state
訪問 192.168.247.8:9200
這里換成你的ip
訪問結果
{
"name": "es-node0",
"cluster_name": "kevin-elasticsearch",
"cluster_uuid": "sSzLTAt-SDiCbQ57WMPqlg",
"version": {
"number": "7.5.1",
"build_flavor": "default",
"build_type": "tar",
"build_hash": "3ae9ac9a93c95bd0cdc054951cf95d88e1e18d96",
"build_date": "2019-12-16T22:57:37.835892Z",
"build_snapshot": false,
"lucene_version": "8.3.0",
"minimum_wire_compatibility_version": "6.8.0",
"minimum_index_compatibility_version": "6.0.0-beta1"
},
"tagline": "You Know, for Search"
}
當前啟動方式時前端啟動。停止服務的話直接ctrl+c 就好了
啟動方式2
我們可以后端啟動
./elasticsearch -d
稍等片刻,再次訪問地址,還是相同結果
此時,如果想關閉服務
[esuser@localhost bin]$ ps -ef|grep elasticsearch
esuser 3318 3007 0 Feb01 pts/1 00:00:00 vi elasticsearch.yml
esuser 3856 1 21 01:15 pts/0 00:00:18 /usr/local/elasticsearch-7.5.1/jdk/bin/java -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -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 -Dio.netty.allocator.numDirectArenas=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.locale.providers=COMPAT -Xms128m -Xmx128m -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Djava.io.tmpdir=/tmp/elasticsearch-9874251960424438570 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m -XX:MaxDirectMemorySize=67108864 -Des.path.home=/usr/local/elasticsearch-7.5.1 -Des.path.conf=/usr/local/elasticsearch-7.5.1/config -Des.distribution.flavor=default -Des.distribution.type=tar -Des.bundled_jdk=true -cp /usr/local/elasticsearch-7.5.1/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
esuser 3871 3856 0 01:15 pts/0 00:00:00 /usr/local/elasticsearch-7.5.1/modules/x-pack-ml/platform/linux-x86_64/bin/controller
esuser 3921 3521 0 01:16 pts/0 00:00:00 grep --color=auto elasticsearch
[esuser@localhost bin]$ jps
3856 Elasticsearch
3922 Jps
[esuser@localhost bin]$ kill 3856
[esuser@localhost bin]$ jps
3940 Jps
[esuser@localhost bin]$