查看当前centos服务器版本
cat /etc/redhat-release
版本太低,更新
yum -y update
yum -y upgrade
一、安装jdk8以上版本
yum install java -y
java -version 查看java版本
官网 https://www.elastic.co/guide/en/elasticsearch/reference/7.9/install-elasticsearch.html
rpm安装
https://www.elastic.co/guide/en/elasticsearch/reference/7.9/rpm.html#rpm-running-init
targz安装
https://www.elastic.co/guide/en/elasticsearch/reference/7.9/targz.html
二、yum安装elasticsearch
下载并安装GPG key
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
添加yum仓库
vim /etc/yum.repos.d/elasticsearch.repo
加入下面的代码
从官网复制的
[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
安装elasticsearch
yum install elasticsearch -y
三、配置 elasticsearch
# 配置文件都在 /etc/elasticsearch/ 目录下
vim /etc/elasticsearch/elasticsearch.yml
# 集群名称
cluster.name: my-application
# 节点名称
node.name: node-1
# 数据文件与日志文件存放目录
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
# 网络设置
network.host: 0.0.0.0
http.port: 9200
# 集群设置
cluster.initial_master_nodes: ["node-1"]
四、启动 elasticsearch
# 启动
systemctl start elasticsearch.service
# 开机自启
systemctl enable elasticsearch.service
# 查看状态
systemctl status elasticsearch.service
测试
curl -X GET localhost:9200
如何开放端口可以用浏览器访问 ip + 9200/?pretty 查看状态
elasticsearch在服务器启动后过一段时间会自动关闭解决方法
内存不够了编辑jvm.options文件 改小内存(要根据机子内存修改)
vi /etc/elasticsearch/jvm.options
-Xms8g
-Xmx8g
启动时添加守护进程
su elasticsearch
cd /usr/share/elasticsearch/bin/
./elasticsearch -d
或用脚本
1、脚本内容如下:
vi /root/es-monitor.sh
#! /bin/bash
#by yuanzelin8
#2018-07-26
#9200是es监听的端口;
port=`netstat -an | grep 9200 | wc -l`
#上述代码表示如果9200起来了,就会显示一行,$port=1;如果es没有起来,就是9200没有被监听,就不会有显示,所以$port=0
#判断:如果$port小于1,说明es服务没有起来,重启es服务 -ne表示不等于 -lt表示小于 启动了默认显示为1 没启动显示为0
if [ $port -lt 1 ]; then
systemctl restart elasticsearch
fi
chmod +x /root/es-monitor.sh
2、contab中设置定时执行脚本
30 0 * * * /root/es-monitor.sh
(上述表示30秒执行一次脚本)
正确配置:
elasticsearch服务自动关闭解决方法_yuanzelin8的博客-CSDN博客_elasticsearch启动后自动关闭
五、安装 kibana,elasticsearch 的可视化界面(这步可以省略不安装)
kibana功能介绍 Elastic Stack:Elasticsearch、Kibana、Beats 和 Logstash | Elastic
# 下载并安装公共签名密钥
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
# 添加源
vim /etc/yum.repos.d/kibana.repo
[kibana-7.x]
name=Kibana repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
# 安装
yum install -y kibana
# 配置
vim /etc/kibana/kibana.yml
server.host: "0.0.0.0"
# 不要用 127.0.0.1,可能会提示 Kibana server is not ready yet
elasticsearch.hosts: ["http://198.13.x.x:9200"]
i18n.locale: "zh-CN"
# 刷新服务配置
systemctl daemon-reload
# 开机自启
systemctl enable kibana.service
# 启动
systemctl start kibana.service
# 查看状态
systemctl status kibana.service
复制代码
默认端口为 5601
访问地址http://198.13.x.x:5601
https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html
https://www.elastic.co/guide/en/kibana/current/rpm.html
六、apache配置elasticsearch
说明文档Configure Apache for your search engine | Adobe Commerce Developer Guide
1.apache配置代理
LoadModule proxy_http_module modules/mod_proxy_http.so
2.apache添加监听端口8080
3.配置8080
<VirtualHost *:8080>
ProxyPass "/" "http://localhost:9200/"
ProxyPassReverse "/" "http://localhost:9200/"
</VirtualHost>
4.重新启动Apache:
service apache2 restart
nginx下配置代理
官方说明:Configure nginx for your search engine | Adobe Commerce Developer Guide
vi /www/server/panel/vhost/nginx/magento_es_auth.conf
server {
listen 8080;
location /_cluster/health {
proxy_pass http://localhost:9200/_cluster/health;
}
}
service nginx restart
5.验证 curl -i http://localhost:<proxy port>/_cluster/health
curl -i http://localhost:8080/_cluster/health
七、magento后台配置Elasticsearch
更新缓存
php bin/magento cache:clean
更新索引
php bin/magento indexer:reindex