《Elastic Stack 实战手册》——三、产品能力——3.4.入门篇——3.4.1.Elastic Stack 安装部署—— 3.4.1.1.安装Elasticsearch(本地及docker)(2) https://developer.aliyun.com/article/1231512
小结
本节对 ES 节点/集群部署所需环境参数及其意义进行了阐述,同时提供了最简初始化脚本和完整版初始化流程供参考。
安装实战
本节将对几个主流的 ES 安装部署的方式进行阐述,并会对节点的安装、部署、启动、停机等流程进行详细描述。
tar 包安装
下载链接(后面以 ES_DOWNLOAD_URL 指代):
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.10.0-linux-x86_64.tar.gz
下载并解压:
l mkdir -p /usr/local/elasticsearch
l cd /usr/local/elasticsearch
l wget -c ${ES_DOWNLOAD_URL}
l tar vxf elasticsearch-7.10.0-linux-x86_64.tar.gz
88 > 三、产品能力
解压出来的文件:
[elasticsearch@esteam7001 elasticsearch]# ls -ltr elasticsearch-7.10.0 总用量 584 -rw-r--r-- 1 elasticsearch elasticsearch 7313 11月 10 05:28 README.asciidoc -> 项目说明文档 -rw-r--r-- 1 elasticsearch elasticsearch 13675 11月 10 05:28 LICENSE.txt -> 协议 drwxr-xr-x 2 elasticsearch elasticsearch 4096 11月 10 05:32 plugins -> 插件文件夹,目前为空,自定义插件会放置在这里 drwxr-xr-x 2 elasticsearch elasticsearch 4096 11月 10 05:32 logs -> 日志文件夹 -rw-r--r-- 1 elasticsearch elasticsearch 544318 11月 10 05:32 NOTICE.txt -> 一些协议的说明以及违反后果的警告 drwxr-xr-x 3 elasticsearch elasticsearch 4096 11月 10 05:34 lib -> 基础依赖库 drwxr-xr-x 2 elasticsearch elasticsearch 4096 11月 10 05:34 bin -> ES内置的命令行工具,包括启动、密码生成等 drwxr-xr-x 9 elasticsearch elasticsearch 4096 11月 10 05:34 jdk -> ES自带的jdk drwxr-xr-x 53 elasticsearch elasticsearch 4096 11月 10 05:34 modules -> ES内置的各种功能模块,包括Xpack等 drwxr-xr-x 3 elasticsearch elasticsearch 4096 4月 15 19:02 config -> ES的配置目录
最简启动
1、确认自己处于 非 root 用户,否则后续启动会报错
2、cd elasticsearch-7.10.0
3、./bin/elasticsearch
4、如果要后台启动,只需在启动命令后面加上 -d
l ./bin/elasticsearch -d
l 完整路径 ./usr/local/elasticsearch/elasticsearch-7.10.0/bin/elasticsearch -d
5、在出现类似这些日志的时候,代表节点启动完成:
[2021-04-15T19:57:24,720][INFO ][o.e.c.c.CoordinationState] [esteam7002] cluster UUID set to [rZ5dFfDWTTO3AUimscISOg] -> 声明集群ID [2021-04-15T19:57:24,931][INFO ][o.e.c.s.ClusterApplierService] [esteam7002] master node changed {previous [], current [{esteam7002}{FBzZRCUQR1K0o8JEVpyfqg}{ikWQPL1TSAav5SSA0eqyZg}{127.0.0.1}{127.0.0.1:9300}{cdhilmrstw}{ml.machine_memory=1927176192, xpack.installed=true, transform.node=true, ml.max_open_jobs=20}]}, term: 1, version: 1, reason: Publication{term=1, version=1} [2021-04-15T19:57:25,059][INFO ][o.e.h.AbstractHttpServerTransport] [esteam7002] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200} -> 开始监听当前地址+端口 [2021-04-15T19:57:25,059][INFO ][o.e.n.Node ] [esteam7002] started -> 节点启动完成
ES 启动状态校验
You Know, for Search
[root@esteam7002 ~]# curl localhost:9200 { "name" : "esteam7002", "cluster_name" : "elasticsearch", "cluster_uuid" : "rZ5dFfDWTTO3AUimscISOg", "version" : { "number" : "7.10.0", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "51e9d6f22758d0374a0f3f5c6e8f3a7997850f96", "build_date" : "2020-11-09T21:30:33.964949Z", "build_snapshot" : false, "lucene_version" : "8.7.0", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" }
集群状态
[root@esteam7002 ~]# curl localhost:9200/_cat/health 1618488038 12:00:38 elasticsearch green 1 1 0 0 0 0 0 0 - 100.0%
节点停机
1、ps -ef | grep elasticsearch | grep -v grep | awk '{ print$2 }' | xargs kill -15
2、没有后台启动的话,直接 ctrl + c 会输出类似以下的日志:
[2021-04-15T20:05:47,962][INFO ][o.e.x.m.p.NativeController] [esteam7002] Native controller process has stopped - no new native processes can be started [2021-04-15T20:05:47,964][INFO ][o.e.n.Node ] [esteam7002] stopping ... [2021-04-15T20:05:47,968][INFO ][o.e.x.w.WatcherService ] [esteam7002] stopping watch service, reason [shutdown initiated] [2021-04-15T20:05:47,969][INFO ][o.e.x.w.WatcherLifeCycleService] [esteam7002] watcher has stopped and shutdown [2021-04-15T20:05:48,218][INFO ][o.e.n.Node ] [esteam7002] stopped [2021-04-15T20:05:48,218][INFO ][o.e.n.Node ] [esteam7002] closing ... [2021-04-15T20:05:48,234][INFO ][o.e.n.Node ] [esteam7002] closed
rpm 包安装
下载链接(后面以 ES_DOWNLOAD_URL 指代):
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.10.0-x86_64.rpm
下载并安装:
1、切换到 root 账户(否则无法进行安装)sudo -i
2、mkdir -p /usr/local/elasticsearch
3、cd /usr/local/elasticsearch
4、wget -c ${ES_DOWNLOAD_URL}
5、rpm -ivh elasticsearch-7.10.0-x86_64.rpm
安装成功日志
日志会根据当前操作系统的语言而显示不同的语言提示,本示例系统为中文:
[root@esteam7002 elasticsearch]# rpm -ivh elasticsearch-7.10.0-x86_64.rpm 警告:elasticsearch-7.10.0-x86_64.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID d88e42b4: NOKEY 准备中... ################################# [100%] 正在升级/安装... 1:elasticsearch-0:7.10.0-1 ################################# [100%] ### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemd sudo systemctl daemon-reload sudo systemctl enable elasticsearch.service ### You can start elasticsearch service by executing sudo systemctl start elasticsearch.service Created elasticsearch keystore in /etc/elasticsearch/elasticsearch.keystore
最简启动
1、确认自己处于 root 用户,否则命令需要加 sudo 前缀
2、通过命令 systemctl start elasticsearch 启动
3、没有报错表明节点启动完成
ES 启动状态校验
1、同上节
节点停机
1、通过命令 systemctl stop elasticsearch 停止服务
2、没有报错表明节点停机完成
Docker 安装
下载对应镜像
docker pull elasticsearch:7.10.1
(可选)如果目标机器无法上网,可以尝试通过其他机器下载并导入镜像
1、在宿主机下载镜像 docker pull elasticsearch:7.10.1
2、把镜像导出为文件 docker save -o elasticsearch-7.10.1-image.tar docker.io/elasticsearch:7.10.1
3、把导出的文件拷贝到目标机器 scp elasticsearch-7.10.1-image.tar root@192.168.10.221:/tmp
4、登陆目标机器 ssh root@192.168.10.221
5、导入目标镜像 docker load < elasticsearch-7.10.1-image.tar
《Elastic Stack 实战手册》——三、产品能力——3.4.入门篇——3.4.1.Elastic Stack 安装部署—— 3.4.1.1.安装Elasticsearch(本地及docker)(4) https://developer.aliyun.com/article/1231510