採用RPM包安裝方式
[visitor@localhost ~]$ yum list elasticsearch
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* epel: mirrors.yun-idc.com
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
錯誤:沒有匹配的軟件包可以列出
[visitor@localhost ~]$ sudo vim /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
[visitor@localhost ~]$ yum list elasticsearch
可安裝的軟件包
elasticsearch.x86_64 7.0.1-1 logstash-7.x
[visitor@localhost ~]$ sudo yum -y install elasticsearch
已安裝:
elasticsearch.x86_64 0:7.0.1-1
完畢!
[visitor@localhost ~]$ sudo vim /etc/profile
export PATH=$PATH:/usr/share/elasticsearch/bin
[visitor@localhost ~]$ source /etc/profile
[root@localhost visitor]# elasticsearch -V
Version: 7.0.1
[root@localhost visitor]# elasticsearch-plugin -h
Commands
--------
list - Lists installed elasticsearch plugins
install - Install a plugin
remove - removes a plugin from Elasticsearch
Non-option arguments:
command
Option Description
------ -----------
-h, --help show help
-s, --silent show minimal output
-v, --verbose show verbose outpu
[root@localhost visitor]# elasticsearch-plugin list
(沒有默認自帶的安裝插件)
[visitor@localhost ~]$ systemctl status elasticsearch
● elasticsearch.service - Elasticsearch
Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: http://www.elastic.co
elasticsearch不能用root啓動
[visitor@localhost ~]$ sudo systemctl start elasticsearch
[sudo] password for visitor:
[visitor@localhost ~]$ systemctl status elasticsearch
● elasticsearch.service - Elasticsearch
Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vendor preset: disabled)
Active: active (running) since 二 2019-05-14 11:50:33 CST; 8s ago
移除--quiet參數,使得可查看日誌
[visitor@localhost ~]$ sudo vim /usr/lib/systemd/system/elasticsearch.service
ExecStart=/usr/share/elasticsearch/bin/elasticsearch -p ${PID_DIR}/elasticsearch.pid
[visitor@localhost ~]$ sudo journalctl -f
控制檯查看輸出日誌
[visitor@localhost ~]$ sudo firewall-cmd --zone=public --add-port=9200/tcp --permanent
success
[visitor@localhost ~]$ sudo firewall-cmd --reload
success
[visitor@localhost ~]$ sudo firewall-cmd --list-ports
9200/tcp 3306/tcp 80/tcp
外網地址訪問放開
[visitor@localhost ~]$ sudo vim /etc/elasticsearch/elasticsearch.yml
# 僅配置network.host會啓動失敗
transport.host: localhost
transport.tcp.port: 9300
network.host: 0.0.0.0
http.port: 9200
[visitor@localhost ~]$ sudo systemctl restart elasticsearch
外網訪問
{
"name": "localhost",
"cluster_name": "elasticsearch",
"cluster_uuid": "C8RwVv2WT-mJoxPAydi2ow",
"version": {
"number": "7.0.1",
"build_flavor": "default",
"build_type": "rpm",
"build_hash": "e4efcb5",
"build_date": "2019-04-29T12:56:03.145736Z",
"build_snapshot": false,
"lucene_version": "8.0.0",
"minimum_wire_compatibility_version": "6.7.0",
"minimum_index_compatibility_version": "6.0.0-beta1"
},
"tagline": "You Know, for Search"
}
http://192.168.112.128: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
}
http://192.168.112.128:9200/_cat/nodes?v
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
127.0.0.1 31 96 0 0.02 0.02 0.05 mdi * localhost
http://192.168.112.128:9200/_cat/indices?v
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
[visitor@localhost ~]$ curl -XPUT 'localhost:9200/es_test?pretty' # 新增索引
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "es_test"
}
http://192.168.112.128:9200/_cat/indices?v
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open es_test 2gIxPzQiROiKXIkAtgcYYg 1 1 0 0 230b 230b
[visitor@localhost ~]$ curl -XGET 'localhost:9200/es_test/article/1?pretty' # 查詢記錄
{
"_index" : "es_test",
"_type" : "article",
"_id" : "1",
"found" : false
}
[visitor@localhost ~]$ curl -XGET 'localhost:9200/es_test/_search' # 查詢所有數據
{"took": 411,"timed_out": false,"_shards": {"total": 1,"successful": 1,"skipped": 0,"failed": 0},"hits": {"total": {"value": 62,"relation": "eq"},"max_score": 1,"hits": []}}
[visitor@localhost ~]$ curl -XDELETE 'localhost:9200/es_test?pretty'
{
"acknowledged" : true
}
當elasticsearch的health爲yellow時,使用下面的命名調整:
[visitor@localhost ~]$ curl -H "Content-Type: application/json" -XPUT 'http://localhost:9200/_settings' -d '
{
"index" : {
"number_of_replicas" : 0
}
}'
{"acknowledged":true}
==============================================================================
安裝中文分詞和拼音分詞
查看已安裝插件:http://192.168.112.128:9200/_cat/plugins #沒有默認安裝插件
[visitor@localhost ~]$ sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.0.0/elasticsearch-analysis-ik-7.0.0.zip
-> Downloading https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.0.0/elasticsearch-analysis-ik-7.0.0.zip
[=================================================] 100%
Exception in thread "main" java.lang.IllegalArgumentException: Plugin [analysis-ik] was built for Elasticsearch version 7.0.0 but version 7.0.1 is running
安裝失敗,等待IK分詞版本升級後再安裝。。。