参考:https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html
前提:安装好了java
步骤:
1.rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
2.sudo vi /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
3.sudo yum install elasticsearch ,至此已经安装好了。
4.启动elastic search
1)查看本机使用的是init还是systemd
ps -p 1
2)若是init,则
sudo chkconfig --add elasticsearch
sudo -i service elasticsearch start#启动
sudo -i service elasticsearch stop#停止
3)若是systemd
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service#启动
sudo systemctl stop elasticsearch.service#停止
5.测试
curl 127.0.0.1:9200
返回结果如下:
{
"name" : "ad1suuQ",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "RLFqfSMYSra7IHR07I9XrQ",
"version" : {
"number" : "6.3.0",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "424e937",
"build_date" : "2018-06-11T23:38:03.357887Z",
"build_snapshot" : false,
"lucene_version" : "7.3.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
6若是安装集群,默认为三个节点,则修改config/elasticsearch.yml
# Use a descriptive name for your cluster:
#设置集群名,三个节点集群名是相同的
cluster.name: testcluster2
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#换个节点名字,三个节点的节点名不同,其他两个节点分别为node2,node3
node.name: node1
network.host: 0.0.0.0
discovery.zen.ping.unicast.hosts: ["10.101.4.1","10.101.4.2","10.101.4.3"] #候选主节点地址
#如果启用了 HTTP 端口,那么此属性会指定是否允许跨源 REST 请求。
http.cors.enabled: true
#如果 http.cors.enabled 的值为 true,那么该属性会指定允许 REST 请求来自何处。
http.cors.allow-origin: "*"
保存后分别启动三个节点,打开elastic-head观察是否成功,当出现以下页面时代表已经搭建成功: