玩转ElasticSearch
玩转ElasticSearch的背景
早几年前玩过Elasticsearch2.x,
针对新版本的ES了解甚少,程序员本应不断追求新技术,所以来玩玩ES7.x,当然ES8.x今年也新出了,但是生态还是7.x好。
安装ElasticSearch服务端
-
安装ElasticSearch服务端,ElasticSearch下载页
1
2
3
4cd /usr/local/
mkdir es
cd es/
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.6-linux-x86_64.tar.gz -
解压并启动搞起
1
2
3
4tar -zxvf elasticsearch-7.17.6-linux-x86_64.tar.gz
cd elasticsearch-7.17.6/
./bin/elasticsearch #启动成功
./bin/elasticsearch -d #后台启动 -
不能用root身份进行启动
1
2
3
4
5
6useradd es #创建es用户,并设置密码
passwd es
chown -R es:es /usr/local/es/* #授权
su es #切换成es用户
./bin/elasticsearch #启动成功
./bin/elasticsearch -d #后台启动 -
问题
1
2#针对上面问题可参考以下配置
vi config/elasticsearch.yml1
2
3
4
5
6
7cluster.name: my-application
node.name: node-1
network.host: 10.0.12.4
http.port: 9200
transport.profiles.default.port: 9300
cluster.initial_master_nodes: ["node-1"]终于启动成功:
安装elasticsearch-head客户端
- 安装NodeJs环境
具体访问教程 CentOS7上安装Node.js和npm
- 安装elasticsearch-head插件,
1 | git clone https://github.com/mobz/elasticsearch-head.git |
- 配置head插件
修改Gruntfile.js配置,增加hostname: '*'配置
1 | vi Gruntfile.js |
修改head/_site/app.js文件
1 | vi app.js |
ES 配置 修改elasticsearch.yml ,增加跨域的配置(需要重启es才能生效)
1 | vi config/elasticsearch.yml |
以上代表head插件已经成功安装
安装kibana客户端
- 下载kibana客户端,kibana下载页,对应版本kibana-7.17.6为例子
1 | wget https://artifacts.elastic.co/downloads/kibana/kibana-7.17.6-linux-x86_64.tar.gz |
- 解压并启动搞起
1 | tar -zxvf kibana-7.17.6-linux-x86_64.tar.gz |
访问 http://你的ip:5601/ 即可
安装cerebro监控工具
- 下载cerebro监控工具,cerebro下载页,下面以最新版本v0.9.4
1 | wget https://github.com/lmenezes/cerebro/releases/download/v0.9.4/cerebro-0.9.4.tgz |
- 解压并启动搞起
1 | tar xf cerebro-0.9.4.tgz |
访问 http://你的ip:9000/ 即可
安装其他常用插件
插件是用来增强 Elasticsearch 功能的方法,分为 核心插件(官方) & 社区插件。
参考文章《Elasticsearch6.x和7.x版本常用插件汇总》
- 安装 analysis-icu ICU 分析插件
1 | ./bin/elasticsearch-plugin install analysis-icu |
- 安装 elasticsearch-analysis-ik 分词插件,具体请参考https://github.com/medcl/elasticsearch-analysis-ik
1 | ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.17.6/elasticsearch-analysis-ik-7.17.6.zip |
- 查看已安装的插件
1 | ./bin/elasticsearch-plugin list |
常用的DSL语句
REST APIs:https://www.elastic.co/guide/en/elasticsearch/reference/7.17/rest-apis.html
Java High Level REST Client:https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high.html