官方安装文档
[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-6.x]
name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.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.noarch 6.7.2-1 logstash-6.x
[visitor@localhost ~]$ sudo yum -y install elasticsearch
已安装:
elasticsearch.noarch 0:6.7.2-1
完毕!
安装指定版本,第一步下载特定版本RPM包,yum安装本地包:yum localinstall elasticsearch-6.7.1.rpm
[visitor@localhost ~]$ sudo vim /etc/profile
export PATH=$PATH:/usr/share/elasticsearch/bin
[visitor@localhost ~]$ source /etc/profile
[visitor@localhost ~]$ su
密码:
[root@localhost visitor]# elasticsearch -V
Version: 6.7.2, Build: default/rpm/56c6e48/2019-04-29T09:05:50.290371Z, JVM: 1.8.0_20
[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
(没有默认自带的安装插件)
[root@localhost visitor]# exit
[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
[o.e.n.Node ] [g93YnII] initialized
[o.e.n.Node ] [g93YnII] starting ...
[o.e.t.TransportService ] [g93YnII] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
[o.e.h.n.Netty4HttpServerTransport] [g93YnII] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[o.e.n.Node ] [g93YnII] started
[o.e.g.GatewayService ] [g93YnII] recovered [0] indices into cluster_state
[visitor@localhost ~]$ sudo firewall-cmd --zone=public --add-port=9200/tcp --permanent
success
[visitor@localhost ~]$ sudo firewall-cmd --zone=public --add-port=9300/tcp --permanent
success
[visitor@localhost ~]$ sudo firewall-cmd --reload
success
[visitor@localhost ~]$ sudo firewall-cmd --list-ports
9200/tcp 3306/tcp 80/tcp 9300/tcp
外网地址访问放开
[visitor@localhost ~]$ sudo vim /etc/elasticsearch/elasticsearch.yml
# es7仅配置network.host会启动失败
#transport.host: 0.0.0.0
#transport.tcp.port: 9300
network.host: 0.0.0.0
#http.port: 9200
#discovery.seed_hosts: ["127.0.0.1", "[::1]"]
[visitor@localhost ~]$ sudo systemctl restart elasticsearch
http://192.168.112.128:9200/
# 客户端最低版本 >= 5.6.0
{
"name": "g93YnII",
"cluster_name": "elasticsearch",
"cluster_uuid": "Vcp9l3V5SSOUcvxd8-Mdgg",
"version": {
"number": "6.7.2",
"build_flavor": "default",
"build_type": "rpm",
"build_hash": "56c6e48",
"build_date": "2019-04-29T09:05:50.290371Z",
"build_snapshot": false,
"lucene_version": "7.7.0",
"minimum_wire_compatibility_version": "5.6.0",
"minimum_index_compatibility_version": "5.0.0"
},
"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
192.168.112.128 30 96 1 0.14 0.12 0.13 mdi * g93YnII
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 7MA4csctQf2EfAi_9npQZA 5 1 0 0 460b 460b
当elasticsearch的health为yellow时,使用下面的命名调整:
[visitor@localhost ~]$ curl -H "Content-Type: application/json" -XPUT 'http://localhost:9200/_settings' -d '
{
"index" : {
"number_of_replicas" : 0
}
}'
{"acknowledged":true}
[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
}
==============================================================================
==============================================================================
查看已安装插件:http://192.168.112.128:9200/_cat/plugins #没有默认安装插件
注意:IK分词器的版本需要跟ES的版本一致才能安装成功。
[root@localhost visitor]# elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.7.1/elasticsearch-analysis-ik-6.7.1.zip
Continue with installation? [y/N]y
-> Installed analysis-ik
[root@localhost visitor]# elasticsearch-plugin list
analysis-ik
[root@localhost visitor]# elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v6.7.1/elasticsearch-analysis-pinyin-6.7.1.zip
-> Downloading https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v6.7.1/elasticsearch-analysis-pinyin-6.7.1.zip
[=================================================] 100%
-> Installed analysis-pinyin
[root@localhost visitor]# elasticsearch-plugin list
analysis-ik
analysis-pinyin
配置内存
[visitor@localhost ~]$ sudo vim /etc/elasticsearch/jvm.options
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms500m
-Xmx500m