本文内容脑图以下:
文章共 747字,阅读大约须要 2分钟 !
最近学 Elasticsearch,既然学之,怎么能没有实际的集群来把玩呢,所以本身必须动手搭一个!node
注: 本文首发于 My Personal Blog:CodeSheep·程序羊,欢迎光临 小站
本文准备搭建 双节点 Elasticsearch集群,所以这里准备了两台 Linux CentOS 7.4 64bit 机器:git
- 节点1:
192.168.31.8
- 节点2:
192.168.31.9
这里下载的是截止到当前日期的最新版:6.4.2
github
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.2.tar.gz
这里拟将 Elasticsearch安装在 /opt/elasticsearch
目录下:数据库
mkdir /opt/elasticsearch 将压缩包复制到该目录下并解压
须要修改两个节点上的配置文件 elasticsearch.yml跨域
cluster.name: codesheep # 集群名称 node.name: sheep1 # 节点名 network.host: 192.168.31.8 # 绑定的节点1地址 network.bind_host: 0.0.0.0 # 此项不设置你试试本机可能访问不了啊 discovery.zen.ping.unicast.hosts: ["192.168.31.8","192.168.31.9"] # hosts列表 discovery.zen.minimum_master_nodes: 1 ## 以下配置是为了解决 Elasticsearch可视化工具 dejavu的跨域问题!若不用可视化工具则可省略之 http.port: 9200 http.cors.allow-origin: "http://192.168.199.76:1358" http.cors.enabled: true http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization http.cors.allow-credentials: true
cluster.name: codesheep # 集群名称 node.name: sheep1 # 节点名 network.host: 192.168.31.9 # 绑定的节点2地址 network.bind_host: 0.0.0.0 discovery.zen.ping.unicast.hosts: ["192.168.31.8","192.168.31.9"] # hosts列表 discovery.zen.minimum_master_nodes: 1 ## 以下配置是为了解决 Elasticsearch可视化工具 dejavu的跨域问题!若不用可视化工具则可省略之 http.port: 9200 http.cors.allow-origin: "http://192.168.199.76:1358" http.cors.enabled: true http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization http.cors.allow-credentials: true
因为 Elasticsearch不能以 root用户启动,所以须要添加非 root用户:浏览器
groupadd es useradd es -g es chown -R es:es ./elasticsearch-6.4.2
systemctl stop firewalld systemctl disable firewalld
su es
cd bin ./elasticsearch // 若要后台启动,则加-d参数
关于 Elasticsearch集群可视化管理工具的上手,能够参考个人前文:《一文上手 Elasticsearch经常使用可视化管理工具》cors
curl -X PUT 'localhost:9200/accounts/person/1' -d ' { "user": "张三", "title": "工程师", "desc": "数据库管理" }' curl -X PUT 'localhost:9200/accounts/person/1' -d ' { "user": "赵四", "title": "设计师", "desc": "UI设计" }'
OK,索引 / 类型 / 文档 一目了然!curl
若在 Elasticsearch集群 安装/启动 过程 中有任何奇葩 问题/错误 的话,就参考个人这篇文章: 《CentOS7上ElasticSearch安装填坑记》吧,里面的坑我都一个个填过了!
在 Elasticsearch的世界中,插件是很重要的一部分,不少功能均可以经过插件来实现,所以下面就以经常使用的 IK分词器插件 的安装为例,来操做一下 Elasticsearch插件的安装
分词技术是搜索技术的基石,而 IK分词器是比较经典的一个,接下来尝试安装一下吧elasticsearch
IK分词器版本与 ES版本对应,不能搞错,可在 这里查看工具
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.2/elasticsearch-analysis-ik-6.4.2.zip
新建目录 /opt/elasticsearch/elasticsearch-6.4.2/plugins/elasticsearch-analysis-ik-6.4.2
再将 zip包置于上述目录下并解压:
unzip elasticsearch-analysis-ik-6.4.2.zip
重启 Elasticsearch集群,若发现以下内容,这说明插件安装成功:
怎么样,很简单吧,就是一个解压放置的过程嘛!
因为能力有限,如有错误或者不当之处,还请你们批评指正,一块儿学习交流!