CentOS 6.x下安装py-mysql-elasticsearch-sync

栏目:Linux 作者:小天 点击: 7,242 次

py-mysql-elasticsearch-sync 是一个将MySQL数据同步到Elasticsearch上的小工具

采用python实现   项目主页

基本原理是,初始化同步中,利用mysqldump输出xml,在python中进行xml解析,通过es的bulk api提交给es进行索引,增量同步部分,通过解析binlog,将数据的更新提交给es。使用的时候可以自己写多个配置文件,多启动几个脚本,使用不同的配置文件,从而同步不同的表。

下一阶段开发计划是实现同一张表分到不同的索引,以及多个表同步到一个索引中。

1、先升级你的Python,请查看:http://www.quyu.net/info/485.html

2、安装:setuptools
wget https://bootstrap.pypa.io/ez_setup.py -O - | python

3、安装:pip
下载地址:https://pypi.python.org/pypi/pip/
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py

4、安装相关组件
sudo yum install libxml2 libxml2-devel libxslt libxslt-devel python-devel gcc gcc-c++
pip install future pyyaml requests lxml mysql-replication

5、安装:py-mysql-elasticsearch-sync
pip install py-mysql-elasticsearch-sync
下载地址:https://github.com/zhongbiaodev/py-mysql-elasticsearch-sync/blob/master/README_CN.md

注意:如果安装时发生错误,很可能是gcc和python-devel没有安装,解决办法:http://www.quyu.net/info/523.html

最新版本获取网址:https://pypi.python.org/pypi/py-mysql-elasticsearch-sync/0.4.0

如果要升级相关的组件,可以执行以下命令:
pip install --upgrade future pyyaml requests lxml mysql-replication py-mysql-elasticsearch-sync

主程序所在位置:/usr/local/lib/python3.5/site-packages/es_sync/__init__.py

优化:
以centos下,以rpm包安装的es为例,

1.编辑 环境变量文件 /etc/sysconfig/elasticsearch

将 ES_HEAP_SIZE 设置为内存的一半

将 MAX_LOCKED_MEMORY=unlimited 一句取消注释

2.编辑es的配置文件 /etc/elasticsearch/elasticsearch.yml

将 bootstrap.mlockall: true 一句取消注释

3.关闭swap(或者修改fstab来永久性关闭)

4.重启elasticsearch
参考文章:http://farer.org/2015/08/05/elasticsearch-notes/



声明: 本文由( 小天 )原创编译,转载请保留链接: CentOS 6.x下安装py-mysql-elasticsearch-sync

------====== 本站公告 ======------
欢迎使用趣域网域名百科,我们将长期提供域名使用相关知识和投资域名的方法和技巧;并提供主机、服务器的解决问题和网站运营方法。