个人专题目录
快速入门
1. 安装包下载
- Elasticsearch官网: https://www.elastic.co/products/elasticsearch
2. 安装Elasticsearch(单节点Linux环境)
- 解压elasticsearch-5.2.2.tar.gz到/opt/module目录下
$ tar -zxvf elasticsearch-5.2.2.tar.gz -C /opt/module/
- 在/opt/module/elasticsearch-5.2.2路径下创建data和logs文件夹
$ mkdir data
$ mkdir logs
#因为安全问题,Elasticsearch 不允许root用户直接运行,所以要创建新用户,在root用户中创建新用户,执行如下命令
useradd elasticsearch # 新增elasticsearch用户
passwd elasticsearch # 为elasticsearch用户设置密码
chown -R elasticsearch:elasticsearch /opt/module/ #文件夹所有者
- 修改配置文件/opt/module/elasticsearch-5.2.2/config/elasticsearch.yml
$ pwd
/opt/module/elasticsearch-5.2.2/config
$ vi elasticsearch.yml
#配置elasticsearch的集群名称,默认是elasticsearch。建议修改成一个有意义的名称
# ---------------------------------- Cluster -----------------------------------
cluster.name: my-application
# ------------------------------------ Node ------------------------------------
#节点名,elasticsearch会默认随机指定一个名字,建议指定一个有意义的名称,方便管理
node.name: node-102
# ----------------------------------- Paths ------------------------------------
path.data: /opt/module/elasticsearch-5.2.2/data
path.logs: /opt/module/elasticsearch-5.2.2/logs
# ----------------------------------- Memory -----------------------------------
# 设置为true可以锁住ES使用的内存,避免内存与swap分区交换数据。
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
# ---------------------------------- Network -----------------------------------
#设置为0.0.0.0允许外网访问
network.host: 192.168.1.102
# --------------------------------- Discovery ----------------------------------
discovery.zen.ping.unicast.hosts: ["hadoop102"]
#Elasticsearch的http访问端口
http.port: 9200
#初始化新的集群时需要此配置来选举master
cluster.initial_master_nodes: ["node-1"]
(1)cluster.name
如果要配置集群需要两个节点上的elasticsearch配置的cluster.name相同,都启动可以自动组成集群,这里如果不改cluster.name则默认是cluster.name=my-application,
(2)nodename随意取但是集群内的各节点不能相同
(3)修改后的每行前面不能有空格,修改后的“:”后面必须有一个空格
- 配置linux系统环境(参考:http://blog.csdn.net/satiling/article/details/59697916)
(1)切换到root用户,编辑limits.conf 添加类似如下内容
# vi /etc/security/limits.conf
添加如下内容:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
(2)切换到root用户,进入limits.d目录下修改配置文件。
# vi /etc/security/limits.d/90-nproc.conf
修改如下内容:
* soft nproc 1024
#修改为
* soft nproc 2048
(3)切换到root用户修改配置sysctl.conf
# vi /etc/sysctl.conf
添加下面配置:最大虚拟内存太小
vm.max_map_count=655360
并执行命令:
# sysctl -p
然后,重新启动elasticsearch,即可启动成功。
- 启动集群
$ bin/elasticsearch
- 测试集群
$ curl http://hadoop102:9200
{
"name" : "node-102",
"cluster_name" : "my-application",
"cluster_uuid" : "v-nwhc7ITsmVHECpNQYzHw",
"version" : {
"number" : "5.2.2",
"build_hash" : "57e20f3",
"build_date" : "2017-09-23T13:16:45.703Z",
"build_snapshot" : false,
"lucene_version" : "6.6.1"
},
"tagline" : "You Know, for Search"
}
$ curl http://localhost:9200/_cluster/health
查询集群状态
{
"cluster_name": "elasticsearch",
"status": "green",
"timed_out": false,
"number_of_nodes": 1,
"number_of_data_nodes": 1,
"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
}
Status:集群状态。Green 所有分片可用。Yellow所有主分片可用。Red主分片不可用,集群不可用。
- 停止集群
kill -9 进程号
3. 安装Elasticsearch(多节点集群Linux环境)



4. Elasticsearch head插件安装
- 下载插件
https://github.com/mobz/elasticsearch-head
elasticsearch-head-master.zip
- nodejs官网下载安装包
node-v6.9.2-linux-x64.tar.xz
-
将elasticsearch-head-master.zip和node-v6.9.2-linux-x64.tar.xz都导入到linux的/opt/software目录。
-
安装nodejs
$ tar -zxvf node-v6.9.2-linux-x64.tar.gz -C /opt/module/
- 配置nodejs环境变量
# vi /etc/profile
export NODE_HOME=/opt/module/node-v6.9.2-linux-x64
export PATH=$PATH:$NODE_HOME/bin
# source /etc/profile
- 查看node和npm版本
# node -v
v6.9.2
# npm -v
3.10.9
- 解压head插件到/opt/module目录下
$ unzip elasticsearch-head-master.zip -d /opt/module/
- 查看当前head插件目录下有无node_modules/grunt目录:
没有:执行命令创建:
$ npm install grunt --save
- 安装head插件:
]$ npm install -g cnpm --registry=https://registry.npm.taobao.org
- 安装grunt:
$ npm install -g grunt-cli
- 编辑Gruntfile.js
$ vim Gruntfile.js
文件93行添加hostname:'0.0.0.0'
options: {
hostname:'0.0.0.0',
port: 9100,
base: '.',
keepalive: true
}
- 检查head根目录下是否存在base文件夹
没有:将 _site下的base文件夹及其内容复制到head根目录下
$ mkdir base
$ cp base/* ../base/
- 启动grunt server:
$ grunt server -d
Running "connect:server" (connect) task
[D] Task source: /opt/module/elasticsearch-head-master/node_modules/grunt-contrib-connect/tasks/connect.js
Waiting forever...
Started connect web server on http://localhost:9100
如果提示grunt的模块没有安装:
Local Npm module “grunt-contrib-clean” not found. Is it installed?
Local Npm module “grunt-contrib-concat” not found. Is it installed?
Local Npm module “grunt-contrib-watch” not found. Is it installed?
Local Npm module “grunt-contrib-connect” not found. Is it installed?
Local Npm module “grunt-contrib-copy” not found. Is it installed?
Local Npm module “grunt-contrib-jasmine” not found. Is it installed?
Warning: Task “connect:server” not found. Use –force to continue.
执行以下命令:
npm install grunt-contrib-clean -registry=https://registry.npm.taobao.org
npm install grunt-contrib-concat -registry=https://registry.npm.taobao.org
npm install grunt-contrib-watch -registry=https://registry.npm.taobao.org
npm install grunt-contrib-connect -registry=https://registry.npm.taobao.org
npm install grunt-contrib-copy -registry=https://registry.npm.taobao.org
npm install grunt-contrib-jasmine -registry=https://registry.npm.taobao.org
最后一个模块可能安装不成功,但是不影响使用。
- 浏览器访问head插件:
http://hadoop102:9100
- 启动集群插件后发现集群未连接
在/opt/module/elasticsearch-5.2.2/config路径下修改配置文件elasticsearch.yml,在文件末尾增加
$ pwd
/opt/module/elasticsearch-5.2.2/config
$ vi elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"
再重新启动elasticsearch。
- 关闭插件服务
ctrl+c
$ netstat -lntp | grep 9100
tcp 0 0 192.168.1.102:9100 0.0.0.0:* LISTEN
网友评论