Elasticsearch(ES)是一个基于Lucene
构建的开源的、分布式、RESTful接口全文搜索 引擎。Elasticsearch还是一个分布式文档数据库,其中每个字段均是被索引的数据且可被搜索。
接下来讲解下,es的安装。
安装ES
java环境
Elastic 需要 Java 8(以及以上版本) 环境。
下载 & 安装
>wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.1.tar.gz
>tar -zxvf ...gz
##-d 表示daemon执行
>./bin/elasticsearch -d
配置问题
- Elastic 只允许本机访问,如果需要远程访问(上线时,需要设置成具体的IP)
network.host: s157
2.启动报错:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决方法:
#1.切换至root
#2.修改sysctl.conf
> vi /etc/sysctl.conf
#3. 添加如下配置:
vm.max_map_count=655360
#4. 执行命令
> sysctl -p
- 启动报错
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
#1.切换至root,修改imits.conf
> vi /etc/security/limits.conf
#2. 添加内容
* hard nofile 65536
* soft nofile 65536
#3. 此文件修改后需要重新登录用户,才会生效(重要!)
- 正常启动后,访问 http://s157:9200/
端口问题
- 9300端口: 是使用tcp客户端连接使用的端口;
- 9200端口: 是通过http协议连接es使用的端口;
集群配置
服务器规划
- s157: master
- s158: slave
- s161: slave
master节点
修改elasticsearch.ymal
cluster.name: es_bop
node.name: master_s157
node.master: true
discovery.zen.ping.unicast.hosts: ["s157",“s161”]
slave节点
#指定host
network.host: s158
#cluster.name必须与master中配置的一致
cluster.name: es_bop
node.name: slave_s158
#http.port: 默认9200
# 配置可以竞选master的节点清单,
# 如果仅配置一个值,则在master挂了之后,重启,造成该master单独形成一个新的集群, 形成脑裂现象..
discovery.zen.ping.unicast.hosts: ["s157",“s161”]
启动命令
./elasticsearch -d
插件安装
elasticsearch-head
参考:http://www.yanglajiao.com/article/yelllowcong/78787012
1.安装nodejs环境
#1. 首先安装node.js
>wget https://nodejs.org/dist/v10.15.0/node-v10.15.0-linux-x64.tar.xz
>tar -zxvf node-v10.15.0-linux-x64.tar.xz
>cd node-v10.15.0-linux-x64
>./configure
> make
>make install
#检验nodejs是否安装成功
> node -v
> npm -v
#设定nodejs安装软件的代理服务器
> npm config set registry https://registry.npm.taobao.org
#执行npm,安装grunt
> npm install -g grunt
> npm install -g grunt-cli
2.phantomjs安装
> wget https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2
#由于它是bz2格式的包,需要安装bzip2命令
> yum install -y bzip2
> bzip2 -d phantomjs-2.1.1-linux-x86_64.tar.bz2
> tar -xvf phantomjs-2.1.1-linux-x86_64.tar
# 在/usr/bin/目录下生产一个phantomjs的软连接
ln -s xxx/bin/phantomjs /usr/bin/
3.启动服务
下载源码包:https://github.com/mobz/elasticsearch-head
> cd ~/xx/elasticsearch-head-master
> npm install
> grunt server
#3. 打开浏览器:
http://s157:9100/ ,默认开启的端口是9100
4.修改配置
- 修改elasticsearch.yml
#各个节点(master+slave)需要增加如下配置
http.cors.enabled: true
http.cors.allow-origin: "*"
- Gruntfile
....
connect: {
server: {
options: {
port: 9100,
base: '.',
keepalive: true
}
}
}
....
最终插件运行效果图: