标签 青云 下的文章

大数据迁移,10tb青云elasticsearch数据迁移阿里云elasticsearch

总的来说elasticsearch数据迁移有两种方法:
1,使用elasticdump 按条迁移,优点是被迁移的index可以写入,迁移中产生的新数据会一并迁移,缺点是速度比较慢;
2,使用elasticsearch自带的快照功能,优点是快,速度取决于网络或者硬盘速度,缺点迁移过程中产生的新数据不会迁移。

这里以elasticsearch的快照为例讲一下青云elasticsearch上10tb数据迁移到阿里云的过程。

1,在青云生成有对象存储权限的access_key和secret_key,在青云对象存储新建bucket:es-trans
2,在青云elasticsearch上创建使用对象存储的快照仓库

curl -XPUT 'http://192.168.150.3:9200/_snapshot/backup/' -d' {"type": "s3","settings": {"endpoint": "s3.pek3b.qingstor.com","access_key": "***","secret_key": "***","bucket": "es-trans","compress":"true"}}'

3,创建需要迁移的index的快照
3.1正常创建快照

curl -XPUT 'http://192.168.150.3:9200/_snapshot/backup/20180505' -d '{"indices": "index1,index2"}'

3.2强制创建快照(有未分配的主分片时需要强制创建快照)

curl -XPUT 'http://192.168.150.3:9200/_snapshot/backup/20180505' -d '{"indices": "index1,index2","partial": "true"}'

4,在阿里云生成有对象存储权限的access_key_id和secret_access_key,在阿里云创建对象存储bucket:es-trans
5,使用阿里云对象存储迁移工具ossimport把青云对象存储bucket:es-trans迁移到阿里云的对象存储bucket:es-trans,参考:https://help.aliyun.com/document_detail/57053.html?spm=a2c4g.11186623.6.1209.51f4663eMbJcKo
6,阿里云elasticsearch创建使用对象存储的快照仓库

curl -XPUT 'http://elastic:***@es-cn-***.elasticsearch.aliyuncs.com:9200/_snapshot/backup/' -d' {"type": "oss","settings": {"endpoint": "http://oss-cn-beijing-internal.aliyuncs.com","access_key_id": "***","secret_access_key": "***","bucket": "es-trans","compress":"true"}}'

7,恢复快照到阿里云es
7.1快照中的index全部原样恢复

curl -XPUT 'http://elastic:***@es-cn-***.elasticsearch.aliyuncs.com:9200/_snapshot/backup/20180505/_restore'

7.2原样恢复快照中部分index

curl -XPUT 'http://elastic:***@es-cn-***.elasticsearch.aliyuncs.com:9200/_snapshot/backup/20180505/_restore' -d '{"indices":"index1"}'

7.3恢复到新名字的index,并不包含原index的别名

curl -XPUT 'http://elastic:***@es-cn-***.elasticsearch.aliyuncs.com:9200/_snapshot/backup/20180505/_restore' -d '{"indices":"index1","include_aliases": false,"rename_pattern": "index1","rename_replacement": "new_index1"}'

8,其他可能用到的命令
8.1删除多个无用index

curl -XDELETE 'http://192.168.150.3:9200/index1,index2'

8.2设置集群磁盘写入阈值为95%,默认值为85%

curl -XPUT 'http://elastic:***@es-cn-***.elasticsearch.aliyuncs.com:9200/_cluster/settings' -d '{"transient": {"cluster.routing.allocation.disk.watermark.low": "95%"}}'

8.3设置index副本为0个

curl -XPUT 'http://elastic:***@es-cn-***.elasticsearch.aliyuncs.com:9200/index1/_settings' -d '{"number_of_replicas": 0}'

9,本次迁移数据约10tb,其中青云es快照写入对象存储约1000mbps,青云对象存储到阿里云对象存储约400mbps,阿里云对象存储的快照写入阿里云es约700mbps,可一个分成多个任务,同步进行,本次迁移约2天完成,如果使用elsaticdump迁移至少8天才能完成。

青云主机安装routeros,附一键安装routeros脚本

20201111更新:routeros chr版本,mount命令offset。

在阿里云安装过routeros,用相同脚本在青云就遇到了坑。
阿里云ecs没有cpu选项,而青云有,创建主机的时候cup高级选项,CPU 体系架构,默认值启动routeros后会cpu100%,选择haswell架构就没有问题,broadwell也不行,再往下的架构没有测试。
附一键安装routeros脚本

wget https://download.mikrotik.com/routeros/6.47.7/chr-6.47.7.img.zip -O chr.img.zip && \
gunzip -c chr.img.zip > chr.img && \
mount -o loop,offset=512 chr.img /mnt && \
ADDRESS0=`ip addr show eth0 | grep global | cut -d' ' -f 6 | head -n 1` && \
GATEWAY0=`ip route list | grep default | cut -d' ' -f 3` && \
echo "/ip address add address=$ADDRESS0 interface=[/interface ethernet find where name=ether1]
/ip route add gateway=$GATEWAY0
" > /mnt/rw/autorun.scr && \
umount /mnt && \
echo u > /proc/sysrq-trigger && \
dd if=chr.img bs=1024 of=/dev/vda && \
reboot