laravel5+ElasticSearch+go-mysql-elasticsearch MySQL数据实时导入(mac)
1. ElasticSearch安装
直接使用brew install elasticsearch 安装最新版本的es,基本没有障碍。
2.Laravel5 框架添加elasticsearch支持
在composer.json文件中添加elasticsearch-php依赖:
执行composer命令更新es代码加载到当前laravel框架中
composer update
laravel控制器中使用es
use Elasticsearch\ClientBuilder;//引入
$client = ClientBuilder::create()->build();//初始化
$params = [
'index' => 'my_index',
'type' => 'my_type',
'id' => 'my_id',
'body' => ['testField' => 'abc']
];
$response = $client->index($params);//添加索引
print_r($response);
$params = [
'index' => 'my_index',
'type' => 'my_type',
'id' => 'my_id'
];
$response = $client->get($params);//获取my_id对应的数据
print_r($response);
实例:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Elasticsearch\ClientBuilder;
class VideoController extends Controller
{
private $client;
public function __construct()
{
$this->client = ClientBuilder::create()->build();
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
for ($i=0;$i<5000;$i++) {
$params = [
'index' => 'my_index',
'type' => 'my_type',
'id' => 'my_id' . $i,
'body' => ['testField' => $i . '、Kitty,今天气很好!!!']
];
$response = $this->client->index($params);
}
dd($response);
}
/**
* Display the specified resource.
*
* @param string $str
* @return \Illuminate\Http\Response
*/
public function show($str='abc')
{
// $params = [
// 'index' => 'my_index',
// 'type' => 'my_type',
// 'id' => $id
// ];
$params = [
'index' => 'my_index',
'type' => 'my_type',
//"scroll" => "3s",
"from" => 0,
"size" => 100,
'body' => [
'query' => [
'match' => [
'testField' => $str,
]
]
]
];
$response = $this->client->search($params);
dd($response);
}
}
3. 实时导入插件go-mysql-elasticsearch
安装go环境,设置环境变量
brew install go
vi ~/.bash_profile 添加以下PATH和GOPATH,并在命令行中执行这两条命令
export PATH=$PATH:/usr/local/Cellar/go/1.7.4_2/bin/
export GOPATH=/Users/User/go
获取go-mysql-elasticsearch
go get github.com/siddontang/go-mysql-elasticsearch
编译go-mysql-elasticsearch
cd $GOPATH/src/github.com/siddontang/go-mysql-elasticsearch
make
配置elasticsearch的etc目录下的river.toml
# MySQL address, user and password
# user must have replication privilege in MySQL.
my_addr = "192.168.0.1:3306"#mysql地址
my_user = "test"#用户名
my_pass = "test123"#密码
# Elasticsearch address
es_addr = "127.0.0.1:9200"#es安装地址
# Path to store data, like master.info, and dump MySQL data
data_dir = "./var"
# Inner Http status address
stat_addr = "127.0.0.1:12800"
# pseudo server id like a slave
server_id = 1001
# mysql or mariadb
flavor = "mysql"#mysql数据库
# mysqldump execution path
# if not set or empty, ignore mysqldump.
mysqldump = "mysqldump"
# MySQL data source
[[source]]
schema = "dev_cms"#数据库名称
# Only below tables will be synced into Elasticsearch.
# "test_river_[0-9]{4}" is a wildcard table format, you can use it if you have many sub tables, like table_0000 - table_1023
# I don't think it is necessary to sync all tables in a database.
tables = ["test_content"]#数据表名称,可以多个
# Below is for special rule mapping
#[[rule]]
#schema = "test"
#table = "test_river"
#index = "river"
#type = "river"
# only MySQL field in filter will be synced
#filter=["title","tags"]
# title is MySQL test_river field name, es_title is the customized name in Elasticsearch
#[rule.field]
# This will map column title to elastic search my_title
#title="es_title"
# This will map column tags to elastic search my_tags and use array type
#tags="my_tags,list"
# This will map column keywords to elastic search keywords and use array type
#keywords=",list"
# wildcard table rule, the wildcard table must be in source tables
[[rule]]
schema = "dev_cms"#数据库名称
table = "test_content"#数据表名称
index = "es_dev_cms"#生成es数据索引名称,对应schema
type = "es_test_content"#生成es数据类型,对应table
# title is MySQL test_river field name, es_title is the customized name in Elasticsearch
[[rule.fields]]
mysql = "title"
elastic = "es_title"
执行命令,导入数据
cd $GOPATH/src/github.com/siddontang/go-mysql-elasticsearch
./bin/go-mysql-elasticsearch -config=./etc/river.toml &
可以在谷歌浏览器安装sense插件查看es数据
laravel5+ElasticSearch+go-mysql-elasticsearch MySQL数据实时导入(mac)的更多相关文章
- MySQL 到 ES 数据实时同步技术架构
MySQL 到 ES 数据实时同步技术架构 我们已经讨论了数据去规范化的几种实现方式.MySQL 到 ES 数据同步本质上是数据去规范化多种实现方式中的一种,即通过"数据迁移同步" ...
- MySQL数据实时增量同步到Kafka - Flume
转载自:https://www.cnblogs.com/yucy/p/7845105.html MySQL数据实时增量同步到Kafka - Flume 写在前面的话 需求,将MySQL里的数据实时 ...
- mysql数据实时同步到Elasticsearch
业务需要把mysql的数据实时同步到ES,实现低延迟的检索到ES中的数据或者进行其它数据分析处理.本文给出以同步mysql binlog的方式实时同步数据到ES的思路, 实践并验证该方式的可行性,以供 ...
- elasticsearch+logstash_jdbc 实现mysql数据实时同步至es
jdk安装1.8版本,es.ls.ik.kibana版本一致我这里使用的6.6.2版本 安装es tar xf elasticsearch-6.6.2.tar.gz mv elasticsearch- ...
- Mysql数据实时同步
企业运维的数据库最常见的是 mysql;但是 mysql 有个缺陷:当数据量达到千万条的时候,mysql 的相关操作会变的非常迟缓; 如果这个时候有需求需要实时展示数据;对于 mysql 来说是一种灾 ...
- 基于netcore实现mongodb和ElasticSearch之间的数据实时同步的工具(Mongo2Es)
基于netcore实现mongodb和ElasticSearch之间的数据实时同步的工具 支持一对一,一对多,多对一和多对多的数据传输方式. 一对一 - 一个mongodb的collection对应一 ...
- 基于Spark Streaming + Canal + Kafka对Mysql增量数据实时进行监测分析
Spark Streaming可以用于实时流项目的开发,实时流项目的数据源除了可以来源于日志.文件.网络端口等,常常也有这种需求,那就是实时分析处理MySQL中的增量数据.面对这种需求当然我们可以通过 ...
- MySQL 实现将一个库表里面的数据实时更新到另一个库表里面
MySQL 实现将一个库表里面的数据实时更新到另一个库表里面 需求描述:MySQL 里面有很多的数据库,这些数据库里面都有同一种表结构的表 (tb_warn_log),这张表的数据是实时更新的,现在需 ...
- Mysql 到 Hbase 数据如何实时同步,强大的 Streamsets 告诉你
很多情况大数据集群需要获取业务数据,用于分析.通常有两种方式: 业务直接或间接写入的方式 业务的关系型数据库同步到大数据集群的方式 第一种可以是在业务中编写代码,将觉得需要发送的数据发送到消息队列,最 ...
随机推荐
- Centos7使用离线安装包rpm安装MySQL5.6
参考地址: https://blog.csdn.net/ai_64/article/details/100557530 https://dev.mysql.com/doc/refman/5.6/en/ ...
- Linux之CentOS设置别名与屏蔽别名
一.环境 CentOS6.8 二.设置别名 ◆别名功能:让grep符合的关键字高亮 1.临时生效 [root@localhost ~]#alias grep="grep --color=au ...
- C# VS2010 windows服务的安装
可能是太过于懒惰的原因,研究个windows 服务的安装程序都花了大半天时间.在网上看了一些示例,大部分都言过其实,把过程搞得太过复杂,老是需要去研究如何利用InstallUtil.exe及其参数.事 ...
- java程序员面试经历(不忘初心,永不放弃,方得始终)。
其实一直想静下心好好写一点博客,记录下青春,但一直忙于学习,写bug.....转眼间2017只剩下最后几天,岁月无情划过,不留痕迹,唯有稀疏地中海.哈哈,本篇文章主要是想分享下刚毕业入门找工作的一点小 ...
- Python高级应用程序设计任务
Python高级应用程序设计任务要求 用Python实现一个面向主题的网络爬虫程序,并完成以下内容:(注:每人一题,主题内容自选,所有设计内容与源代码需提交到博客园平台) 一.主题式网络爬虫设计方案( ...
- WebGPU学习系列目录
介绍 大家好,本系列从0开始学习WebGPU API,并给出相关的demo. WebGPU介绍 WebGPU相当于DX12/Vulkan,能让程序员更灵活地操作GPU,从而大幅提升性能. 为什么要学习 ...
- 面试连环炮系列(二十一):你们的项目怎么使用kafka
你们的项目怎么使用kafka? 我们采用kafka进行日志采集,准确点说是ELK方案,即elasticsearch + logstash + kibana + kafka.通过Spring AOP的方 ...
- docker 常用命令 以及常见问题
常见命令 windos 在搜索框 输入 windows powershell,打开.然后输入以下命令#查看镜像列表 docker images ls #删除单个镜像 docker rmi image- ...
- [译]C# 7系列,Part 2: Async Main 异步Main方法
原文:https://blogs.msdn.microsoft.com/mazhou/2017/05/30/c-7-series-part-2-async-main/ 你大概知道,C#语言可以构建两种 ...
- C# DataTable to List<T> based on reflection.
From https://www.cnblogs.com/zjbky/p/9242140.html static class ExtendClass { public static List<T ...