下载安装包
- 进入到Elasticsearch的官网下载页面
https://www.elastic.co/cn/downloads/elasticsearch
-
如果不想安装最新版本,可以选择历史版本
-
本次安装版本号选用6.8.0
- 下载安装包
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.8.0.tar.gz
新增系统用户
- 由于elasticsearch不能使用root用户启动,所以我们创建一个新的用户
# 新建用户
adduser es
# 给新用户添加密码
passwd es
# 切换登陆用户
su es
- 将安装包copy到路径
/home/es/elasticsearch
下
mv elasticsearch-6.8.0.tar.gz /home/es/elasticsearch
解压安装包
cd /home/es/elasticsearch
tar -xzvf elasticsearch-6.8.0.tar.gz
修改配置文件
vi config/elasticsearch.yml
#集群的名称,同一个集群该值必须设置成相同的
cluster.name: okami-application
#该节点的名字
node.name: node-1
#该节点有机会成为master节点
node.master: true
#该节点可以存储数据
node.data: true
#shard的数目
#index.number_of_shards: 5
#数据副本的数目
#index.number_of_replicas: 3
#设置绑定的IP地址,可以是IPV4或者IPV6
network.bind_host: 0.0.0.0
#设置其他节点与该节点交互的IP地址
network.publish_host: 192.168.10.1
#该参数用于同时设置bind_host和publish_host
network.host: 192.168.10.1
#设置节点之间交互的端口号
transport.tcp.port: 9300
#设置是否压缩tcp上交互传输的数据
transport.tcp.compress: true
#设置对外服务的http端口号
http.port: 9200
#设置http内容的最大大小
http.max_content_length: 100mb
#是否开启http服务对外提供服务
http.enabled: true
#设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4)
discovery.zen.minimum_master_nodes: 1
#设置集群中自动发现其他节点时ping连接的超时时间
discovery.zen.ping_timeout: 120s
#设置是否打开多播发现节点
#discovery.zen.ping.multicast.enabled: true
#设置集群中的Master节点的初始列表,可以通过这些节点来自动发现其他新加入集群的节点
discovery.zen.ping.unicast.hosts: ["192.168.10.1:9300"]
path.data: /usr/hdp/2.5.0.0-1245/esdata
path.logs: /usr/hdp/2.5.0.0-1245/eslog
http.cors.enabled: true
http.cors.allow-origin: "*"
#--------------------------------------------------------------------------------
#index.analysis.analyzer.ik.type: "ik"
启动ES
- ES要求Java版本至少1.8,所以要检查Java版本,如果版本过低的话需要更新
[es@okami elasticsearch-7.1.1]# java -version
java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)
- 启动ES(添加参数-d,后台启动)
./home/es/elasticsearch/elasticsearch-6.8.0/bin/elasticsearch -d
- 检查ES节点是否部署成功
[es@okami ~]# curl http://127.0.0.1:9200
{
"name" : "node-1",
"cluster_name" : "okami-application",
"cluster_uuid" : "Q00-w01oQT6vsXx7E6KIeA",
"version" : {
"number" : "6.8.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "65b6179",
"build_date" : "2019-05-15T20:06:13.172855Z",
"build_snapshot" : false,
"lucene_version" : "7.7.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
安装部署其他主机
- 在同一个局域网段内的其他主机按照以上步骤安装部署ES
检查集群的部署情况
[es@okami ~]# curl http://127.0.0.1:9200/_cluster/health
{"cluster_name":"okami-application","status":"green","timed_out":false,"number_of_nodes":3,"number_of_data_nodes":3,"active_primary_shards":0,"active_shards":0,"relocating_shards":0,"initializing_shards":0,"unassigned_shards":0,"delayed_unassigned_shards":0,"number_of_pending_tasks":0,"number_of_in_flight_fetch":0,"task_max_waiting_in_queue_millis":0,"active_shards_percent_as_number":100.0}
安装中遇到的问题
-
- max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
- 每个进程最大同时打开文件数太小,可通过下面2个命令查看当前数量
ulimit -Hn ulimit -Sn
- 修改/etc/security/limits.conf文件,增加配置,用户退出后重新登录生效
* soft nofile 65536 * hard nofile 65536
-
- max number of threads [3818] for user [es] is too low, increase to at least [4096]
- 问题同上,最大线程个数太低。修改配置文件/etc/security/limits.conf,增加配置
可通过命令查看* soft nproc 4096 * hard nproc 4096
ulimit -Hu ulimit -Su
- max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
- 修改/etc/sysctl.conf文件,增加配置vm.max_map_count=262144
vi /etc/sysctl.conf sysctl -p
- max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]