## 安装 - 传统方式安装 下载安装包---> 平台 window macos linux(ubuntu) - Docker 方式安装 推荐 ### 传统方式安装 ```markdown # 0.环境准备 - centos7.x+、ubuntu、windows、macos - 安装jdk11.0+ 并配置环境变量 jdk8 # 1.下载ES - https://www.elastic.co/cn/start ``` ![![image-20210816103401531](ElasticSearch%207.14.assets/image-20210816103401531.png)](images/screenshot_1647398044180.png) ```markdown # 2.安装ES不用使用root用户,创建普通用户 ``` ```shell # 添加用户名 $ useradd chenyn # 修改密码 $ passwd chenyn # 普通用户登录 ``` ```markdown # 3.解压缩ES安装包 ``` ```shell $ tar -zxvf elasticsearch-7.14.0-linux-x86_64.tar.gz $ ll 总用量 650168 drwxr-xr-x. 10 chenyn chenyn 167 8月 16 11:07 elasticsearch-7.14.0 ``` ```markdown # 4.查看ES解压包中目录结构 ``` ```shell [chenyn@localhost elasticsearch-7.14.0]$ ll - bin 启动ES服务脚本目录 - config ES配置文件的目录 - data ES的数据存放目录 - jdk ES提供需要指定的jdk目录 - lib ES依赖第三方库的目录 - logs ES的日志目录 - modules 模块的目录 - plugins 插件目录 ``` ![](https://img.kancloud.cn/35/8f/358f9977f74b750dc4d366582962deb5_945x237.png) ```markdown # 5.启动ES服务 ``` ```shell [chenyn@localhost ~]$ ./elasticsearch-7.14.0/bin/elasticsearch ``` ![](https://img.kancloud.cn/2d/bd/2dbd464a1f1ad9b02bad6c45b20258ea_945x91.png) ```markdown - 这个错误时系统jdk版本与es要求jdk版本不一致,es默认需要jdk11以上版本,当前系统使用的jdk8,需要从新安装jdk11才行! - 解决方案: 1.安装jdk11+ 配置环境变量、 2.ES包中jdk目录就是es需要jdk,只需要将这个目录配置到ES_JAVA_HOME环境变即可、 ``` ```markdown # 6.配置环境变量 ``` ```shell $ vim /etc/profile - export ES_JAVA_HOME=指定为ES安装目录中jdk目录 - source /etc/profile ``` ![](https://img.kancloud.cn/43/76/437679cb8c4637971705895283539019_845x99.png) ```markdown # 7.从新启动ES服务 ``` ![](https://img.kancloud.cn/b5/31/b53138de3c1a4084a7a9aae5cb5cb7cc_825x72.png) ```markdown # 8.ES启动默认监听9200端口,访问9200 ``` ```shell $ curl http://localhost:9200 ``` ![](https://img.kancloud.cn/31/23/3123cc783c439b28e4572ea155e64782_902x359.png) ##### 开启远程访问 ```markdown # 1.默认ES无法使用主机ip进行远程连接,需要开启远程连接权限 - 修改ES安装包中config/elasticsearch.yml配置文件 ``` ```shell $ vim elasticsearch.yml ``` ![](https://img.kancloud.cn/b9/04/b9049d710ecb5ce94d2013249d0054b6_948x249.png) ```markdown # 2.重新启动ES服务 - ./elasticsearch - 启动出现如下错误: `bootstrap check failure [1] of [4]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535] `bootstrap check failure [2] of [4]: max number of threads [3802] for user [chenyn] is too low, increase to at least [4096] `bootstrap check failure [3] of [4]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] `bootstrap check failure [4] of [4]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers ``` ![](https://img.kancloud.cn/5a/ba/5abae03b72eb294d82ae350f42f264c8_950x100.png) ```markdown # 3.解决错误-1 ``` ```shell $ vim /etc/security/limits.conf ``` ```markdown # 在最后面追加下面内容 * soft nofile 65536 * hard nofile 65536 * soft nproc 4096 * hard nproc 4096 # 退出重新登录检测配置是否生效: ulimit -Hn ulimit -Sn ulimit -Hu ulimit -Su ``` ```markdown # 3.解决错误-2 ``` ```shell #进入limits.d目录下修改配置文件。 $ vim /etc/security/limits.d/20-nproc.conf # 修改为 启动ES用户名 soft nproc 4096 ``` ```markdown # 3.解决错误-3 ``` ```shell # 编辑sysctl.conf文件 $ vim /etc/sysctl.conf vm.max_map_count=655360 #centos7 系统 vm.max_map_count=262144 #ubuntu 系统 # 执行以下命令生效: $ sysctl -p ``` ```markdown # 3.解决错误-4 ``` ```shell # 编辑elasticsearch.yml配置文件 $ vim conf/elasticsearch.yml cluster.initial_master_nodes: ["node-1"] ``` ```markdown # 4.重启启动ES服务,并通过浏览器访问 ``` ```json { "name": "localhost.localdomain", "cluster_name": "elasticsearch", "cluster_uuid": "OWh3xLYwR-6lZ_fQNhVY3A", "version": { "number": "7.14.0", "build_flavor": "default", "build_type": "tar", "build_hash": "dd5a0a2acaa2045ff9624f3729fc8a6f40835aa1", "build_date": "2021-07-29T20:49:32.864135063Z", "build_snapshot": false, "lucene_version": "8.9.0", "minimum_wire_compatibility_version": "6.8.0", "minimum_index_compatibility_version": "6.0.0-beta1" }, "tagline": "You Know, for Search" } ``` ### Docker方式安装 ```markdown # 1.获取镜像 - docker pull elasticsearch:7.14.0 # 2.运行es - docker run -d -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.14.0 # 3.访问ES - http://10.15.0.5:9200/ ``` ---