关于ElasticSearch就不介绍了,文档可以参考官方
sudo apt install openjdk-8-jdk
parallels@parallels-vm:~$ java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
108M大小
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.1.tar.gz
tar -xzf elasticsearch-6.5.1.tar.gz
cd elasticsearch-6.5.1/
需要校验的话
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.1.tar.gz.sha512
shasum -a 512 -c elasticsearch-6.5.1.tar.gz.sha512
运行
./bin/elasticsearch
关闭是ctrl+C
运行一下请求,可以看到如下信息,如果显示连接拒绝可能是localhost设置过不是127.0.0.1,替换localhost为127.0.0.1试试
parallels@parallels-vm:~$ curl 'http://localhost:9200/?pretty'
{
"name" : "P06U0G2",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "bRWDtULfQc6vFBsmU8sLlA",
"version" : {
"number" : "6.5.1",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "8c58350",
"build_date" : "2018-11-16T02:22:42.182257Z",
"build_snapshot" : false,
"lucene_version" : "7.5.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
195M,kibana的dev tool提供交互式的控制台,通过浏览器直接向 Elasticsearch 提交请求
需要先安装kibana,下面的步骤错误,正确的往后翻,这里是记录错误
curl -O https://artifacts.elastic.co/downloads/kibana/kibana-6.5.1-darwin-x86_64.tar.gz
tar -xzf kibana-6.5.1-darwin-x86_64.tar.gz
cd kibana-6.5.1-darwin-x86_64/
运行
./bin/kibana
报错
parallels@parallels-vm:~/kibana-6.5.1-darwin-x86_64$ ./bin/kibana
./bin/../node/bin/node: 1: ./bin/../node/bin/node: �����H: not found
./bin/../node/bin/node: 2: ./bin/../node/bin/node: __ustring__TEXTu,�: not found
./bin/../node/bin/node: 2: ./bin/../node/bin/node: ���H__PAGEZERO__TEXTPJPJ: not found
@: not founde/bin/node: 2: ./bin/../node/bin/node: ��
./bin/../node/bin/node: 3: ./bin/../node/bin/node: u,__dof_node__TEXT�,�,__unwind_info__TEXT��,TV��,__eh_frame__TEXT��-�l��-__DATAPJ�
PJ�: not found
./bin/../node/bin/node: 4: ./bin/../node/bin/node: Syntax error: word unexpected (expecting ")")
是没有node???
sudo apt install npm
sudo apt install nodejs-legacy
修改bin/kibana
原 NODE="${DIR}/node/bin/node"
修改 NODE="/usr/bin/nodejs"
运行结果
parallels@parallels-vm:~/kibana-6.5.1-darwin-x86_64$ ./bin/kibana
/usr/bin/nodejs: bad option: --no-warnings
版本太低?node 4.2.6 npm 3.5.2
用npm方法升不上
sudo npm install npm@latest -g
这一句坑爹啊,升级了npm但是node还没上去,npm就不能用了啊
parallels@parallels-vm:~$ npm --version
/usr/local/lib/node_modules/npm/bin/npm-cli.js:85
let notifier = require('update-notifier')({pkg})
^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:442:10)
at startup (node.js:136:18)
at node.js:966:3
解决步骤如下
cd /usr/local/lib/node_modules
mv npm/ /tmp/usr_local_lib_node_modules_npm
sudo npm install -g n
sudo n stable
parallels@parallels-vm:/usr/local/lib/node_modules$ sudo n stable
install : node-v11.2.0
mkdir : /usr/local/n/versions/node/11.2.0
fetch : https://nodejs.org/dist/v11.2.0/node-v11.2.0-linux-x64.tar.gz
######################################################################## 100.0%
installed : v11.2.0
但是查询node -v还是没变,需要修改/etc/profile,source一下
export NODE_HOME=/usr/local/n/versions/node/11.2.0
export PATH=$NODE_HOME/bin:PATH
全部卸载,apt remove,重新安装
结果是太高了版本,重新装吧,NODE=“/usr/local/n/versions/node/11.2.0”
parallels@parallels-vm:~/kibana-6.5.1-darwin-x86_64$ ./bin/kibana
Kibana does not support the current Node.js version v11.2.0. Please use Node.js v8.11.4.
parallels@parallels-vm:/usr/local/lib/node_modules$ sudo n v8.11.4
install : node-v8.11.4
mkdir : /usr/local/n/versions/node/8.11.4
fetch : https://nodejs.org/dist/v8.11.4/node-v8.11.4-linux-x64.tar.gz
######################################################################## 100.0%
installed : v8.11.4
重写配置,不是no-warnings的错误了,启动错误
log [06:56:05.271] [error][reporting] Failed to install browser. See kibana logs for more details.
log [06:56:05.280] [error][status][plugin:spaces@6.5.1] Status changed from yellow to red - Failed to extract the phantom.js archive
error [06:56:05.289] [fatal][root] ExtractError: Failed to extract the phantom.js archive
at err (/home/parallels/kibana-6.5.1-darwin-x86_64/node_modules/x-pack/plugins/reporting/server/browsers/extract/unzip.js:14:23)
at /home/parallels/kibana-6.5.1-darwin-x86_64/node_modules/extract-zip/index.js:20:23
at /home/parallels/kibana-6.5.1-darwin-x86_64/node_modules/extract-zip/node_modules/yauzl/index.js:29:21
at FSReqWrap.oncomplete (fs.js:135:15)
FATAL ExtractError: Failed to extract the phantom.js archive
npm 5.6.0 node 8.11.4
phantom.js没有找到,有一个phantom_options.js
也许是我装错了,上面装的是darwin版本de,接下来装linux的197M
wget https://artifacts.elastic.co/downloads/kibana/kibana-6.5.1-linux-x86_64.tar.gz
cd
服了,还真的是装错了的问题,访问
http://localhost:5601/app/kibana
可喜可贺,花了我大半天
es装在虚拟机上了,想通过外网访问ip来访问
首先修改config/elasticsearch.yml的network.host: 0.0.0.0(:后一个空格),重新启动报错
ERROR: [1] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
修改
sudo vim /etc/sysctl.conf//增加以下内容
vm.max_map_count=655360
parallels@parallels-vm:~$ sudo sysctl -p
vm.max_map_count = 655360
我用的是Spring boot为整体框架,整合elasticsearch,支持几种不同的客户端
1.REST
两种REST,“low level"和"high level”
依赖 org.elasticsearch.client:elasticsearch-rest-client 客户端 RestClient
https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-low.html
依赖 org.elasticsearch.client:elasticsearch-rest-high-level-client 客户端 RestHighLevelClient
https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high.html
spring.elasticsearch.rest.uris=http://search.example.com:9200
spring.elasticsearch.rest.username=user
spring.elasticsearch.rest.password=secret
2.Jest
Jest JestClient
https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/index.html
spring.elasticsearch.jest.uris=http://search.example.com:9200
spring.elasticsearch.jest.read-timeout=10000
spring.elasticsearch.jest.username=user
spring.elasticsearch.jest.password=secret
3.sring data
https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/
在github上spring-data-elasticsearch有相对全的资料:https://github.com/spring-projects/spring-data-elasticsearch
版本问题,现在装上的是6.5.1,Java内的Spring-data-elasticsearch 3.1.2,对应elasticsearch6.4.2
Spring data elasticsearch | elasticsearch |
---|---|
3.1.x | 6.2.2 |
3.0.x | 5.5.0 |
2.1.x | 2.4.0 |
2.0.x | 2.2.0 |
1.3.x | 1.5.2 |
spring.data.elasticsearch.cluster-nodes=localhost:9300
注入ElasticsearchTemplate或TransportClient
@Component
public class MyBean {
private final ElasticsearchTemplate template;
public MyBean(ElasticsearchTemplate template) {
this.template = template;
}
// ...
}