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 告诉你
很多情况大数据集群需要获取业务数据,用于分析.通常有两种方式: 业务直接或间接写入的方式 业务的关系型数据库同步到大数据集群的方式 第一种可以是在业务中编写代码,将觉得需要发送的数据发送到消息队列,最 ...
随机推荐
- python爬虫--爬虫与反爬
爬虫与反爬 爬虫:自动获取网站数据的程序,关键是批量的获取. 反爬虫:使用技术手段防止爬虫程序的方法 误伤:反爬技术将普通用户识别为爬虫,从而限制其访问,如果误伤过高,反爬效果再好也不能使用(例如封i ...
- Django大纲
Django框架 ........ 2.聚合查询 分组 F与Q查询 字段 及其 参数 | 数据库的三大范式 3.orm查询优化 MTV与MVC模型 choice参数 ajax serializers ...
- spring boot 2 全局统一返回RESTful风格数据、统一异常处理
全局统一返回RESTful风格数据,主要是实现ResponseBodyAdvice接口的方法,对返回值在输出之前进行修改.使用注解@RestControllerAdvice拦截异常并统一处理. 开发环 ...
- CSS样式 解决文字过长显示省略号问题
一.CSS样式 解决文字过长显示省略号问题 1.一般样式 一般 css 样式,当宽度不够时,可能会出现换行的效果.这样的效果在某些时候肯定是不行的,可以修改 css 样式来解决这个问题. <!D ...
- iOS底层实现原理【高级进阶】
想要进阶,想要提升自己一个更高档次,想要拥有更高比格的iOS开发攻城狮们,请关注 ↓↓↓ 我的简书:https://www.jianshu.com/u/3adf2f8593b8 我的掘金:https: ...
- SVN服务器和客户端的下载和安装
一.SVN服务器VisualSVN下载和安装 当前版本:4.1.3下载地址:https://www.visualsvn.com/server/download/下载下来的文件:VisualSVN-Se ...
- Stm32使用串口空闲中断,基于队列来接收不定长、不定时数据
串口持续地接收不定长.不定时的数据,把每一帧数据缓存下来且灵活地利用内存空间,下面提供一种方式供参考.原理是利用串口空闲中断和DMA,每当对方发来一帧完整的数据后,串口接收开始空闲,触发中断,在中断处 ...
- Linux - CentOS 7 通过Yum源安装 MySql 5.7
添加MySQL Yum存储库 从官网下载最新的mysql源 官网地址:https://dev.mysql.com/downloads/repo/yum/ 选择并下载适用于平台的发行包. 然后,在Lin ...
- Java继承之方法重写
目录 Java继承之方法重写 代码体现 概念 注意事项 "两同两小一大" 其他注意点 重写与重载 @Override注解 Java继承之方法重写 在Java继承中,子类可以获得父类 ...
- 初窥R(基本说明、获取帮助、工作空间、输入输出、包)
本篇简要介绍使用R的一些基本概念,包括基本说明.获取帮助.工作空间.输入输出,每个知识点中都会通过一个例子来练习. 一.R基本情况说明 1.R是一种区分大小写的解释性语言. 2.控制台默认使用命令提示 ...