1.es集群搭建
docker-compose.yml
version: '3.6'
services:
es_master_180_10:
image: elasticsearch:7.6.1
container_name: es_master_180_10
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
volumes:
- /www/wwwroot/2007_SRM/elasticsearch/master_10/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- /www/wwwroot/2007_SRM/elasticsearch/master_10/data:/usr/share/elasticsearch/data
privileged: true
ports:
- 9210:9200
- 9310:9300
networks:
es:
ipv4_address: 180.200.7.10
es_slave_180_11:
image: elasticsearch:7.6.1
container_name: es_slave_180_11
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
volumes:
- /www/wwwroot/2007_SRM/elasticsearch/slave_11/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- /www/wwwroot/2007_SRM/elasticsearch/slave_11/data:/usr/share/elasticsearch/data
privileged: true
ports:
- 9211:9200
- 9311:9300
networks:
es:
ipv4_address: 180.200.7.11
es_slave_180_12:
image: elasticsearch:7.6.1
container_name: es_slave_180_12
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
volumes:
- /www/wwwroot/2007_SRM/elasticsearch/slave_12/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- /www/wwwroot/2007_SRM/elasticsearch/slave_12/data:/usr/share/elasticsearch/data
privileged: true
ports:
- 9212:9200
- 9312:9300
networks:
es:
ipv4_address: 180.200.7.12
kibana:
image: kibana:7.6.1
container_name: kibana
environment:
- "ELASTICSEARCH_HOSTS=http://180.200.7.12:9200"
- "SERVER_PORT=5601"
- "SERVER_HOST=0.0.0.0"
ports:
- 5601:5601
networks:
es:
ipv4_address: 180.200.7.13
networks:
es:
driver: bridge
ipam:
config:
- subnet: "180.200.7.0/24"
docker-compose up -d 后台启动容器后如下图所示
,其中可能出现内存不足,文件权限等问题,需将目录映射文件的权限改成777
chmod 777 -R /www/wwwroot/2007_SRM/docker/compose/elasticsearch
一个es的容器在构建的时候是需要系统提供200M的内存(建议实现)
系统需要配置 sysctl -w vm.max_map_count=262144
设置索引,
添加一条记录到es
2.安装mysql,我使用的是宝塔一键安装lnmp,mysql版本5.6
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh
mysql配置文件设置开启binlog,在宝塔控制面板-》安全里面放行端口9210(es master 主节点端口,提供外部访问)
建立srm库,test表,id字段自增且为主键
go env -w GOPROXY=https://goproxy.cn
go get go get github.com/siddontang/go-mysql-elasticsearch
cd $GOPATH/src/github.com/siddontang/go-mysql-elasticsearch
make
配置river.toml
# MySQL 配置:地址,用户名,密码
my_addr = "192.168.1.100:3306"
my_user = "root"
my_pass = "root"
# Elasticsearch地址
es_addr = "192.168.1.100:9210"
# 存储数据的位置
data_dir = "/var/test"
# Inner Http status address
stat_addr = "192.168.1.100:12800"
stat_path = "/es"
# pseudo server id like a slave
server_id = 101
# mysql or mariadb
flavor = "mysql"
# mysqldump execution path
# mysqldump = "mysqldump"
# minimal items to be inserted in one bulk
bulk_size = 128
# force flush the pending requests if we don't have enough items >= bulk_size
flush_bulk_time = "200ms"
# Ignore table without primary key
skip_no_pk_table = false
# elasticsearch 与 mysql 同步时对应的数据库名称
# mysql的数据源
[[source]]
schema = "srm"
tables = ["test"]
# es 映射的mapping
[[rule]]
schema = "srm"
table = "test"
# es的索引名
index = "srm_goods"
type = "list"
启动服务
$GOPATH/src/github.com/siddontang/go-mysql-elasticsearch/bin/go-mysql-elasticsearch -config=/www/wwwroot/2007_SRM/elasticsearch/rivert.toml(修改的文件地址)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?