Elasticsearch 安装与卸载

1. Elasticsearch 安装

1.1 添加普通用户ben到sudo

adduser ben
[root@ip-172-31-8-38 ~]# id benuid=1001(ben) gid=1001(ben) groups=1001(ben)
[root@ip-172-31-8-38 ~]# usermod -a -G wheel ben
[root@ip-172-31-8-38 ~]# id benuid=1001(ben) gid=1001(ben) groups=1001(ben),10(wheel)
[root@ip-172-31-8-38 ~]# sudo passwd benChanging password for user ben.

1.2 安装 Elasticsearch

官方安装地址: https://www.elastic.co/guide/en/elasticsearch/reference/7.13/rpm.html#rpm-running-systemd

进入系统根目录下面的 local ,在普通用户(ben) 下面执行安装操作:

###下载
cd /local
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.13.4-x86_64.rpm
sudo wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.13.4-x86_64.rpm.sha512 shasum -a 512 -c elasticsearch-7.13.4-x86_64.rpm.sha512
###安装
sudo rpm --install elasticsearch-7.13.4-x86_64.rpm
warning: elasticsearch-7.13.4-x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID d88e42b4: NOKEY
Creating elasticsearch group... OK
Creating elasticsearch user... OK
### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemd
### 安装时不启动,请执行以下语句将elasticsearch服务配置为使用systemd自动启动
 sudo systemctl daemon-reload
 sudo systemctl enable elasticsearch.service
### You can start elasticsearch service by executing
 sudo systemctl start elasticsearch.service
Created elasticsearch keystore in /etc/elasticsearch/elasticsearch.keystore

安装如下图所示:

1.3 常见使用命令

要配置Elasticsearch以在系统启动时自动启动,请运行以下命令:

sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service

Elasticsearch可以按以下方式启动和停止:

sudo systemctl start elasticsearch.service
sudo systemctl stop elasticsearch.service

检查Elasticsearch是否运行

您可以通过向以下端口发送 HTTP 请求来测试您的 Elasticsearch 节点是否正在9200运行localhost

curl -X GET "localhost:9200/?pretty"

正常结果:

[ben@ip-172-31-8-38 local]$ curl -X GET "localhost:9200/?pretty"
{
  "name" : "ip-172-31-8-38.eu-central-1.compute.internal",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "EISWOsRkSkaFu2XIS-OUIg",
  "version" : {
    "number" : "7.13.4",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "c5f60e894ca0c61cdbae4f5a686d9f08bcefc942",
    "build_date" : "2021-07-14T18:33:36.673943207Z",
    "build_snapshot" : false,
    "lucene_version" : "8.8.2",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

2. 卸载Elasticsearch

ben@ip-172-31-2-29 src]$ rpm -qa |grep elasticsearch
 
rpm -qa |grep elasticsearch
elasticsearch-7.13.4-1.x86_64
[ben@ip-172-31-2-29 src]$ rpm -e  --nodeps elasticsearch
error: can't create transaction lock on /var/lib/rpm/.rpm.lock (Permission denied)

[ben@ip-172-31-2-29 src]$ sudo rpm -e  --nodeps elasticsearch
[sudo] password for ben: 
Stopping elasticsearch service... OK
warning: /etc/elasticsearch/jvm.options saved as /etc/elasticsearch/jvm.options.rpmsave
warning: /etc/elasticsearch/elasticsearch.yml saved as /etc/elasticsearch/elasticsearch.yml.rpmsave
Deleting log directory... OK

3.常见问题

3.常见问题

3.1 端口问题

如果Elasticsearch启动时候,9200端口已经被占用,Elasticsearch会自动占用9201端口。如果需要指定一个特别端口,只需要把config/elasticsearch.yml中的http.port注释去掉,重新定义一个端口数值即可:

3.2 连接不上elasticsearch

elasticearch 已经安装,正常但是使用9200端口测试没有反应,我们就使用9201试试。

3.3 M2 An exception occurred on ‘sales_model_service_quote_submit_failure’ event: Could not ping search engine: No alive nodes found in your cluster {“exception”:”[objec。。。]

这个原因是 因为M2与elasticsearch没有连接上。

Leave a comment

您的电子邮箱地址不会被公开。 必填项已用 * 标注