0. 首先需要安装jdk,因为elasticsearch是Java写的,默认需要Java环境,且安装elasticsearch 7.x需要使用jdk 1.8或更高版本
1. 执行以下命令,创建elasticsearch仓库(计划安装7.x版本的elasticsearch)
cat <<EOF | sudo tee /etc/yum.repos.d/elasticsearch.repo [elasticsearch-7.x] name=Elasticsearch repository for 7.x packages baseurl=https://artifacts.elastic.co/packages/oss-7.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md EOF
2. 建立elasticsearch仓库之后,需要刷新yum索引
sudo yum clean all sudo yum makecache
3. 安装elasticsearch
sudo yum -y install elasticsearch-oss
4. 编辑文件: /etc/elasticsearch/jvm.options, 设置内存大小:
默认是:-Xms1g -Xmx1g
可以设置为:-Xms256m -Xmx512m
5. 启动elasticsearch
sudo systemctl enable --now elasticsearch.service
使用如下命令也可以启动
/etc/init.d/elasticsearch start
6. 检验一下是否启动起来了
[root@localhost ~]# curl http://localhost:9200 { "name" : "localhost.localdomain", "cluster_name" : "elasticsearch", "cluster_uuid" : "Ybtkma76SSKOmXw89fMnuQ", "version" : { "number" : "7.3.2", "build_flavor" : "oss", "build_type" : "rpm", "build_hash" : "1c1faf1", "build_date" : "2019-09-06T14:40:30.409026Z", "build_snapshot" : false, "lucene_version" : "8.1.0", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" } [root@localhost ~]# curl http://127.0.0.1:9200 { "name" : "localhost.localdomain", "cluster_name" : "elasticsearch", "cluster_uuid" : "Ybtkma76SSKOmXw89fMnuQ", "version" : { "number" : "7.3.2", "build_flavor" : "oss", "build_type" : "rpm", "build_hash" : "1c1faf1", "build_date" : "2019-09-06T14:40:30.409026Z", "build_snapshot" : false, "lucene_version" : "8.1.0", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" } [root@localhost ~]#
7. 目前只可以在服务器上使用127.0.0.1与localhost进行访问,如果需要对elasticsearch使用公网访问,还需要将elasticsearch.yum配置添加如下内容:
network.host: 0.0.0.0 http.port: 9200 http.cors.enabled: true http.cors.allow-origin: "*" cluster.initial_master_nodes: ["node-1"]
8. 服务器上访问结果:
[root@localhost elasticsearch]# curl http://192.168.1.27:9200/ { "name" : "localhost.localdomain", "cluster_name" : "elasticsearch", "cluster_uuid" : "Ybtkma76SSKOmXw89fMnuQ", "version" : { "number" : "7.3.2", "build_flavor" : "oss", "build_type" : "rpm", "build_hash" : "1c1faf1", "build_date" : "2019-09-06T14:40:30.409026Z", "build_snapshot" : false, "lucene_version" : "8.1.0", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" }
本地访问结果
C:UsersYFZX-MY-1715>curl http://192.168.1.27:9200 { "name" : "localhost.localdomain", "cluster_name" : "elasticsearch", "cluster_uuid" : "Ybtkma76SSKOmXw89fMnuQ", "version" : { "number" : "7.3.2", "build_flavor" : "oss", "build_type" : "rpm", "build_hash" : "1c1faf1", "build_date" : "2019-09-06T14:40:30.409026Z", "build_snapshot" : false, "lucene_version" : "8.1.0", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" } C:UsersYFZX-MY-1715>
9. 配置过程中,启动elasticsearch怎么着都启动不起来,去看了启动日志(日志文件位置再elasticsearch.yum文件中有描述),报错如下:
[localhost.localdomain] no plugins loaded [2019-09-19T02:26:21,325][INFO ][o.e.d.DiscoveryModule ] [localhost.localdomain] using discovery type [zen] and seed hosts providers [settings] [2019-09-19T02:26:22,172][INFO ][o.e.n.Node ] [localhost.localdomain] initialized [2019-09-19T02:26:22,173][INFO ][o.e.n.Node ] [localhost.localdomain] starting ... [2019-09-19T02:26:22,508][INFO ][o.e.t.TransportService ] [localhost.localdomain] publish_address {192.168.1.27:9300}, bound_addresses {[::]:9300} [2019-09-19T02:26:22,517][INFO ][o.e.b.BootstrapChecks ] [localhost.localdomain] bound or publishing to a non-loopback address, enforcing bootstrap checks [2019-09-19T02:26:22,520][ERROR][o.e.b.Bootstrap ] [localhost.localdomain] node validation exception [1] bootstrap checks failed [1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured [2019-09-19T02:26:22,549][INFO ][o.e.n.Node ] [localhost.localdomain] stopping ... [2019-09-19T02:26:22,596][INFO ][o.e.n.Node ] [localhost.localdomain] stopped [2019-09-19T02:26:22,597][INFO ][o.e.n.Node ] [localhost.localdomain] closing ... [2019-09-19T02:26:22,618][INFO ][o.e.n.Node ] [localhost.localdomain] closed
去elasticsearch.yum文件里面添加:
#cluster.initial_master_nodes: ["node-1", "node-2"] cluster.initial_master_nodes: ["node-1"] 这个的话,这里的node-1是上面一个默认的记得打开就可以了