CentOS7下安装Elasticsearch及配置

Elasticsearch大家都知道的,全文检索啥的必不可少的服务,来走一波,先跑起来,后面会结合Yii2用Elasticsearch做一些检索工作,也会记录下来,先来安装配置一波。

Elasticsearch查看界面

环境:Virtual Box6.0.6 + CentOS Linux release 7.6.1810

首先确保系统已经安装了JAVA1.8,没有安装的自行搜索去安装先。

[root@localhost /]# java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-b04)
OpenJDK 64-Bit Server VM (build 25.212-b04, mixed mode)

下载并安装ES的yum公钥

rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch

配置Elasticsearch的yum源

vim /etc/yum.repos.d/elasticsearch.repo

输入以下代码:

[elasticsearch-2.x]
name=Elasticsearch repository for 2.x packages
baseurl=http://packages.elastic.co/elasticsearch/2.x/centos
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1

yum缓存

yum makecache

安装 Elasticsearch

yum install elasticsearch

提示安装成功

rpm安装好处是不用担心权限一系列问题,会自动创建elasticsearch用户和组来运行elasticsearch;

Creating elasticsearch group... OK
Creating elasticsearch user... OK
  Installing : elasticsearch-2.4.6-1.noarch                                                                                                       1/1 
### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemd
 sudo systemctl daemon-reload
 sudo systemctl enable elasticsearch.service
### You can start elasticsearch service by executing
 sudo systemctl start elasticsearch.service
  Verifying  : elasticsearch-2.4.6-1.noarch                                                                                                       1/1 

Installed:
  elasticsearch.noarch 0:2.4.6-1                                                                                                                      
Complete!

按照提示加入开机启动

sudo systemctl daemon-reload
sudo systemctl enable elasticsearch.service

可尝试的操作服务(启动停止等)

service elasticsearch {start|stop|status|restart|condrestart|try-restart|reload|force-reload}

启动服务并测试成功

service elasticsearch start
curl -X GET localhost:9200
{
  "name" : "Kymaera",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "xPBDux2WQvSRkbbwg1FPTg",
  "version" : {
    "number" : "2.4.6",
    "build_hash" : "5376dca9f70f3abef96a77f4bb22720ace8240fd",
    "build_timestamp" : "2017-07-18T12:17:44Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.4"
  },
  "tagline" : "You Know, for Search"
}

安装目录

elasticsearch实例目录: /usr/share/elasticsearch
elasticsearch配置文件目录: /etc/elasticsearch/

IP访问

配置文件 vim /etc/elasticsearch/elasticsearch.yml

# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 9200
#

添加开放端口并重启防火墙

# centos 6
iptables -I INPUT -p tcp --dport 9200 -j ACCEPT
service iptables restart
# centos 7
firewall-cmd --zone=public --add-port=9200/tcp --permanent
firewall-cmd --reload

到此就可以局域网ip之类的而不仅仅是localhost访问了。

安装一个可视化插件head

/usr/share/elasticsearch/bin/plugin install mobz/elasticsearch-head

访问head插件

http://192.168.0.88:9200/_plugin/head/

elasticsearch-head插件该如何使用?可以参考:elasticsearch-head的使用

至此elasticsearch服务已经搭建好,并且还配备可视化了,嘿嘿。

标题:CentOS7下安装Elasticsearch及配置

原文链接:https://beltxman.com/2500.html

若无特殊说明本站内容为 行星带 原创,未经同意请勿转载。

Scroll to top