Elasticsearch-核心篇(2)-下载安装

一、Elasticsearch安装

1.1 Linux安装

  1. 下载地址
  2. 其他软件下载页面
  3. 注意先要安装java环境(es7要求JDK11+),如果未安装也可以,es已经自带JDK11,运行前配置前即可
  4. 解压elasticsearch并重命名
tar -zxvf elasticsearch-7.8.0-linux-x86_64.tar.gz -C /opt
cd /opt
mv elasticsearch-7.8.0 es
  1. 创建es用户和用户组,es不允许使用root用户运行
group add es
useradd es -g es
passwd es
chown -R es:es es
  1. elasticsearch解压完成之后修改config/elasticsearch.yml文件
    • 如果是单机节点则可以不需要修改
    • 下面配置了允许外网访问
cluster.name: elasticsearch
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
cluster.initial_master_nodes: ["node-1"]
http.cors.enabled: true
http.cors.allow-origin: "*"
  1. 直接运行即可bin/elasticsearch即可
cd /opt/es/bin
su es
./elasticsearch -d
  1. 如果想把 Elasticsearch 作为一个守护进程在后台运行,那么可以在后面添加参数 -d
  2. 默认启动后将会占用9200和9300端口,如果有防火墙或者安全组需要运行通过
    • 9300:通信端口
    • 9200:http端口
  3. es7+要求JDK版本至少是11,所以当启动时可能报错,所以要么升级JDK版本,要么配置ES运行JDK版本
  • 在ES安装目录中已经自带了JDK11

  • 修改bin/elasticsearch-env,在此目录中配置JAVA_HOME路径为ES下的jdk路径即可

目录含义
bin可执行脚本目录
config配置目录
jdk内置JDK目录
lib类库
logs日志目录
modules模块目录
plugins插件目录

1.2 Windows安装

  1. 下载windows版本的elasticsearch
  2. 解压压缩包
  3. 运行bin/elasticsearch.bat即可启动

1.3 Docker安装

  1. 下载docker elasticsearch文件
docker pull elasticsearch:7.8.0
  1. 参考文档
  2. 启动es
    • 如果是单节点则必须加入**-e “discovery.type=single-node”**,否则需要指定节点名称
    • 具体可以参考es官方docker文档
docker run -d --name es -p 9200:9200 -p 9300:9300 -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -e "discovery.type=single-node" <ImageId>
  1. 启动结果

1.4 连接测试

  1. 浏览器:http://localhost:9200/?pretty
  2. Linux:
curl http://localhost:9200/?pretty
{
	"name": "tianxin",
	"cluster_name": "elasticsearch",
	"cluster_uuid": "aTt3P85JRhW85BmIUJWpjw",
	"version": {
		"number": "7.8.0",
		"build_flavor": "default",
		"build_type": "tar",
		"build_hash": "757314695644ea9a1dc2fecd26d1a43856725e65",
		"build_date": "2020-06-14T19:35:50.234439Z",
		"build_snapshot": false,
		"lucene_version": "8.5.1",
		"minimum_wire_compatibility_version": "6.8.0",
		"minimum_index_compatibility_version": "6.0.0-beta1"
	},
	"tagline": "You Know, for Search"
}

二、Elasticsearch外网访问

  1. ES安装完成之后默认只能在本机进行访问,如果需要能通过外部访问,则需要配置外网访问
  2. 修改es目录下config/elasticsearch.yml文件,将network.host设置为机器ip
    • network.host: <ip地址>
      • 如果需要所有地址都能访问,则可以配置0.0.0.0
    • cluster.initial_master_nodes: [“node-1”]
      • 配置单节点启动
cluster.name: elasticsearch
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
cluster.initial_master_nodes: ["node-1"]
http.cors.enabled: true
http.cors.allow-origin: "*"
  1. 配置完成后重启ES,然后通过外网访问

三、Elasticsearch插件安装

3.1 head插件安装

  1. 由于elasticsearch-head插件是由nodejs语言编写,所以安装elasticsearch-head前需要先安装nodejs和grunt
  2. 下载nodejs压缩包任意解压目录,然后配置环境变量
    • vim /etc/profile
    • 添加以下环境变量
    • source /etc/profile
export NODE_HOME=/opt/node
export PATH=$PATH:$NODE_HOME/bin
  1. 查看node安装完成之后的版本
[root@tianxin node]# node -v
v14.15.4
  1. 安装grunt,直接使用npm安装即可
npm install -g grunt-cli
[root@tianxin node]# npm install -g grunt-cli
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
/opt/node/bin/grunt -> /opt/node/lib/node_modules/grunt-cli/bin/grunt
+ grunt-cli@1.3.2
added 153 packages from 126 contributors in 31.658s
[root@tianxin node]# grunt --version
grunt-cli v1.3.2
  1. 在es安装目录下新建dashboard/head文件夹(随意为之),拉取elasticsearch-head到head文件夹中
git clone https://gitee.com/tianxincoord/elasticsearch-head.git
  1. 安装head插件
    • 可以安装淘宝镜像
npm install -g cnpm --registry=https://registry.npm.taobao.org
  • head插件安装
# npm安装
cd elasticsearch-head/
npm install
npm run start
  • 淘宝安装
# cnpm安装
cd elasticsearch-head/
cnpm install
cnpm run start
  1. 安装完成之后打开9100端口即可访问

  1. config/elasticsearch.yml需要配置允许跨域,否则无法连接
http.cors.enabled: true
http.cors.allow-origin: "*"

四、Elasticsearch常见问题

  1. java.lang.RuntimeException: can not run elasticsearch as root
    • 不能以root用户运行ES,需要使用es,所以切换 su es之后再运行即可
  2. ERROR: [1] bootstrap checks failed
    [1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
    • es要求discovery.seed_hosts、discovery.seed_providers、 cluster.initial_master_nodes必须要配置其中之一
    • 例如下面配置的配置任选其一,配置之后重新启动即可
      • cluster.initial_master_nodes: [“node-1”]
      • discovery.seed_hosts: [“172.16.127.129”]

  1. Java HotSpot™ 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
    • UseConcMarkSweepGC 垃圾回收器已经不建议使用,在后面会被删除
    • 修改config/jvm.options,修改垃圾回收器
# 注释UseConcMarkSweepGC
# 8-13:-XX:+UseConcMarkSweepGC
# 修改为+UseG1GC
8-13:-XX:+UseG1GC

  1. max file descriptors [4096] for elasticsearch process is too low,increase to at least [65535]
    • 修改**/etc/security/limits.conf**,加入下面配置
    • *表示所有用户,如果需要单个则指定具体用户名即可
es soft nofile 65535
es hard nofile 65535
  • 修改/etc/security/limits.d/20-nproc.conf文件,增加下面配置
# 在文件末尾中增加下面内容
# 每个进程可以打开的文件数的限制
es soft nofile 65536
es hard nofile 65536
# 操作系统级别对每个用户创建的进程数的限制
* hard nproc 4096
# 注:* 带表Linux所有用户名称
  1. max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
    • 配置的虚拟内存太小,需要在**/etc/sysctl.conf**加大虚拟内存
# 编辑配置文件
vim /etc/sysctl.conf
# 加入虚拟内存配置
vm.max_map_count=262144
# 重新加载配置
sysctl -p
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值