PHP+Elisticsearch-7.15+Dejavu综合使用教程
一:安装
1:安装ES 之前必须安装jdk,最好安装jdk11 或者以上版本(要求服务器内存要高于2g,生产必须要大于4g)
#查看jdk 版本,如果没有或者版本低于1.8则重新安装,已有则不需要安装
java -version
安装jdk11
yum -y install java-11-openjdk
2:下载es压缩包,在你适合的目录里下载
wget:https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.15.2-linux-x86_64.tar.gz
3:解压
tar -zxvf elasticsearch-7.15.2-linux-x86_64.tar.gz
4:创建新用户 es(es不能用root 用户运行,需要先创建用户)
useradd es
5:将解压的es文件归属于新用户
chown -R es elasticsearch-7.15.2
切换用户,并进入es文件夹
su es
cd elasticsearch-7.15.2
6:修改jvm配置根据自己机器 这里修改为1g,保证这2个值相等(这里要求设备内存最少2g以上,不然可能会运行失败)
-Xms1g
-Xmx1g
7:单机运行:修改完上面的 就可以启动了
用es 用户 在 elasticsearch-7.15.2 文件夹运行
./bin/elasticsearch
第二:配置外网访问
配置外网访问,目的是方便我们操作;
修改配置:elasticsearch.yml
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#集群名称
#cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#节点名称
#node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#绑定地址
#network.host: 192.168.0.1
network.host: 0.0.0.0
#
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#节点发现
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#主节点,这个绑定外网必须要配置,并且得保证跟上面节点名称一致
#cluster.initial_master_nodes: ["node-1", "node-2"]
cluster.initial_master_nodes: ["node-1"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true#控制面板需要跨域
http.cors.allow-origin: "*"
http.cors.enabled: true
http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization
http.cors.allow-credentials: true
解决错误:
ERROR: [N] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536][2]: max number of threads [1024] for user [uaren] is too low, increase to at least [4096][3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144][4]: 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[5]:future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/nlp/java/jdk1.8.0_162/jre] does not meet this requirement[6]:Exception in thread "main" SettingsException[Failed to load settings from [elasticsearch.yml]]; nested: MarkedYAMLException[mapping values are not allowed here
1:原因: 每个进程最大同时打开文件数太小,可通过下面2个命令查看当前数量
查看 进程数
ulimit -Hn
ulimit -Sn
解决:max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
修改 /etc/security/limits.conf配置文件
sudo vim /etc/security/limits.conf在配置文件加上(已经有或者大于这个数则不需要修改):
* hard nofile 65536
* soft nofile 65536
解决:max number of threads [1024] for user [uaren] is too low, increase to at least [4096]
# sudo vim /etc/security/limits.conf在配置文件加上:
* hard nproc 4096
* soft nproc 4096
解决: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
# 修改/etc/sysctl.conf文件,增加配置vm.max_map_count=655360sudo vim /etc/sysctl.conf在配置文件加上:
vm.max_map_count=655360#保存之后 生效
sysctl -p# 注意:增加配置,用户退出后重新登录生效
解决: 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
修改elasticsearch.yml配置,参照上面即可解决
完成之后启动es即可在浏览器访问;这里要把对应端口访问放开( 9200 跟1358 Dejavu面板用的)
#启动
./bin/elasticsearch
#浏览器访问,正常就会返回信息
http://ip:9200
三:安装监控面Dejavu
1、先修改Elasticsearch配置文件,增加如下配置(上面的参考配置已经增加)
http.cors.allow-origin: "*"
http.cors.enabled: true
http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization
http.cors.allow-credentials: true
2:安装docker
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
3:运行docker
systemctl start docker.service
4:运行Dejavu 镜像
docker run -p 1358:1358 -d appbaseio/dejavu
5:浏览器访问
http://ip:1358
6:链接es 前需要给es 建立至少一个索引,这里直接用postman 添加
#http put 方式
http://1.14.197.220:9200/megacorp/employee/1#body raw
{"first_name" : "John","last_name" : "Smith","age" : 25,"about" : "I love to go rock climbing","interests": [ "sports", "music" ]
}
添加成功即可用dejavu链接了
ps:如果发现浏览器链接不了1358 这端口,可能是服务器的Dejavu 服务挂了,可以重启下docker服务即可访问,这里注意需要安全组放开端口1358
#查找docker 进程信息
ps -aux|grep docker#找到绑定1358端口的进程 并杀死
root 8855 0.1 1.6 1108104 31740 ? Ssl 09:50 0:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root 9122 0.0 0.0 808636 1172 ? Sl 09:51 0:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 1358 -container-ip 172.17.0.2 -container-port 1358
root 10277 0.0 0.0 112708 984 pts/2 R+ 09:53 0:00 grep --color=auto dockerkill -9 9122#重启Dejavu 服务
docker run -p 1358:1358 -d appbaseio/dejavu
四:安装php拓展并使用
1:安装拓展直接用compose 即可
composer require elasticsearch/elasticsearch
安装完后简单封装一个EsModel 即可使用
<?php
/*** Created by PhpStorm.* 05* 封装es 操作模型,非完整*/
namespace app\common\model;use Elasticsearch\ClientBuilder;
class ElasticSearch{private $cline=null;public function __construct($host="127.0.0.1",$port="9200"){$host=[$host.":".$port];$this->cline = ClientBuilder::create()->setHosts($host)->build();}public function addIndex($pms){return $this->cline->indices()->create($pms);}public function addIndexData($index,$data){$pms=['index'=>$index,'body'=>$data];return $this->cline->index($pms);}/*** @param $pms* @return array*/public function search($pms){return $this->cline->search($pms);}
}
下面是简单使用测试
//测试es使用public function testes(){$index_params = ['index' => 'my_index','body' => ['mappings' => ['properties' => ['user_id' => ['type' => 'string','ignore_above' => 20,],'keyword' => ['type' => 'string','ignore_above' => 20,],],],],];// 添加索引echo json_encode(model("ElasticSearch")->addIndex($index_params));exit();//添加数据$add_data_pms=['keyword'=>'测试工程师','user_id'=>'1001'];echo json_encode(model("ElasticSearch")->addIndexData("my_index",$add_data_pms));exit();//搜索测试$sparams = ['index' => 'my_index','type' => '_doc','body' => ['query' => ['match' => ['keyword' => '测试']]]];$d=model("ElasticSearch")->search($sparams);echo json_encode($d);exit();}
PS:操作demo 可以在es拓展源码里找
es一些名词解析
index:索引,一般一个索引是一个类型,比如员工索引,书籍索引等 索引里可以分类型就是 type
type:索引类型,新版本可能会弃用,默认不设置就可以
Document Index 里面单条的记录称为Document(文档)。等同于关系型数据库表中的行。
properties:属性,每个文档都有属性,就像数据库表的字段,es里属性里也可以有属性,可以多层嵌套下面是实例解析$index_params = ['index' => 'my_index', //这个是索引名称'body' => [//这是索引内容'mappings' => [ //这个只是代表映射关系表述'properties' => [//索引拥有的属性'user_id' => [ //属性 字段 'type' => 'string',//字段类型'ignore_above' => 20,//字段限制],'keyword' => [//另一个字段'type' => 'string','ignore_above' => 20,],],],],];
简单使用先分享到这里,下面是es官网全文指南文档,深入学习请自觉…
ES官方指南
PHP+Elisticsearch-7.15+Dejavu综合使用教程相关推荐
- QR扫码综合示例教程(二十二)Qt5.15.2+Qt6.2.1(qml)+opencv4.5.4解决扫码聚焦、闪光灯(多线程、微信扫码)
前言: 因笔者前期设备限制,并没有考虑摄像头聚焦.闪光灯相关,有小伙伴问到相关问题,所以笔者就测试了下.结果有点失望,但仍然共享给小伙伴们,以减少走弯路 本教程是在 Qt5.15.2+Qt6.2.1( ...
- QR扫码综合示例教程
前言: 计划通过本教程,让读者掌握使用Qt实现扫描二维码的功能.整个教程从最简单的取数据开始,借用多个开源库,实现扫描功能 QR扫码综合示例教程(一)Qt5.15.2(widget)摄像头显示 QR扫 ...
- spring学习指南 第4版_邹为诚《综合英语教程(1)》(第3版)学习指南词汇短语课文精解全文翻译练习答案电子版学习资料...
邹为诚<综合英语教程(1)>(第3版)学习指南[词汇短语+课文精解+全文翻译+练习答案] Unit 1 一.词汇短语 二.课文精解 三.全文翻译 四.练习答案 Unit 2 一.词汇短语 ...
- 视频教程-新版全面系统完整的电信客服综合案例教程-大数据
新版全面系统完整的电信客服综合案例教程 张长志技术全才.擅长领域:区块链.大数据.Java等.10余年软件研发及企业培训经验,曾为多家大型企业提供企业内训如中石化,中国联通,中国移动等知名企业.拥有丰 ...
- fifa15服务器位置,《FIFA 15》全系统教程图文攻略
<FIFA 15>全系统教程图文攻略 2014-09-23 11:04:14来源:3DM论坛编辑:评论(0) <FIFA 15>为EA旗下足球模拟游戏,游戏使用了<UFC ...
- mysql8.0.15下载后怎么打开_mysql8.0.15下载安装详细教程新手必备!
本文记录了mysql 8.0.15 下载安装的具体步骤,供大家参考,具体内容如下 背景:作为一个热爱技术但不懂代码的产品写的教程 1.环境 系统:windows 64位 mysql版本:mysql 8 ...
- navicat premium 15 下载安装详细教程
navicat premium 15 下载安装详细教程 一.准备安装文件 首先我们要准备好 navicat premium 15 官网:http://www.navicat.com.cn 下载地址:N ...
- 2017.2.15 开涛shiro教程-第二十一章-授予身份与切换身份(二) controller
原博客地址:http://jinnianshilongnian.iteye.com/blog/2018398 根据下载的pdf学习. 开涛shiro教程-第二十一章-授予身份与切换身份(二) 1.回顾 ...
- 计算机组成与体系结构乘法指令设计,基于Quartus II的计算机组成与体系结构综合实验教程...
基于Quartus II的计算机组成与体系结构综合实验教程 语音 编辑 锁定 讨论 上传视频 <基于Quartus II的计算机组成与体系结构综合实验教程>是2011年科学出版出版的图书, ...
- 分享本年度最佳的15个 Photoshop 实例教程
毫无疑问,Photoshop 是任何其类型的设计相关工作的最佳工具.有这么多东西,你可以用它来设计,发挥你的想象力,一切皆有可能. 现在,几乎所有的封面图像都会用 Photoshop 来修饰. 您可能 ...
最新文章
- 使用Kryo的序列化方式提升Netty性能
- NanoPi NEO Air使用十五:使用V4L2驱动USB摄像头
- CentOS 7 为firewalld添加开放端口及相关资料
- HDLBits答案(24)_由波形图描述电路
- 《恋上数据结构第1季》二叉树基础、真二叉树、满二叉树、完全二叉树、二叉树的遍历(重点)
- PCL Lesson5: 直通滤波+空间平面拟合+提供原始点云数据集PCD文件
- 15.卷1(套接字联网API)---Unix域协议
- RabbitMQ消息确认机制之Confirm模式总结
- 前端模拟数据(mock数据)的方法一:访问该项目的静态资源目录
- excel 工作表保护密码破解代码
- 如何用c语言批量替换字符串,[C/C++]急速批量替换字符串
- oracle如何恢复被误误删除的pdb
- 计算机芯片级维修包括哪些,计算机芯片级维修1
- mysql count判断_【MySQL】COUNT
- 职场002:什么是可迁移能力
- No pyvenv.cfg file
- 全球排名前四的眼药水,第一款来自欧洲老牌安瞧AGEPHA Pharma,眼科医生自留!
- 易语言教程数据库替换
- 大学计算机期末总结范文,大学计算机课期末总结.doc
- 粒子摇摆 shader