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
查看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的索引名,之前建立的索引和type 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(修改的文件地址)
查看es
后面新加到test表的数据都已经同步过来了,这个es head 是一个可视化界面,我安装在宿主机上,链接虚拟机的es ip+端口号就可以查看es集群数据