DataX 刷历史任务脚本 (串行/并行)

刷历史的脚本,下面的脚本是按照顺序刷历史使用,一天跑完才能跑下一天,存在依赖

(注意:dataX跑数的环境:如果是生产:路径为/opt/datax/bin/datax.py  如果是预发布环境,路径为/opt/software/datax/bin/datax.py)

#/bin/bash
 
# 安全验证
 
 # 往历史数据的分区加载数据
    startDate=$1 # 输入格式如:2019-01-01
    endDate=$2 # 输入格式如:2020-01-01
 
     echo "------------------ $1 ----------------- "
     echo "------------------ $2 ----------------- "
 
    # 获取两个日期区间的所有日期
    startSec=`date -d "$startDate" "+%s"`
    endSec=`date -d "$endDate" "+%s"`
    for((i=$startSec;i<=$endSec;i+=86400));do
        yesterday=`date -d "@$i" "+%Y-%m-%d"`
        echo "------------------ ${yesterday} ----------------- "
 
        python /opt/software/datax/bin/datax.py /opt/export/server/db_name/table_name.json -p "-Ddt=${yesterday}"
 
    done

并行跑,可以设置并行度,如果并行度设置为6,那么一次起6个任务,6个任务执行完,才会继续启动6个,任务之间不存在依赖

(注意:dataX跑数的环境:如果是生产:路径为/opt/datax/bin/datax.py  如果是预发布环境,路径为/opt/software/datax/bin/datax.py),假设该脚本名为test.sh,则使用方式为sh test.sh json配置文件绝对路径(不含.json) 起始日期 结束日期,如果需要设置并行度,可以将其作为一个传参来使用

#/bin/bash
 
 # 安全验证
 
 # 往历史数据的分区加载数据
    startDate=$2 # 输入格式如:2019-01-01
    endDate=$3 # 输入格式如:2020-01-01
 
     echo "------------------ json_name=$1  startDate=$2  endDate=$3----------------- "
     echo "------------------  ----------------- "
     echo "------------------  ----------------- "
##每批15天
parall_num=6 #设置并行度
max_times=3  #尝试多少次读取日志判断是否做完
dataX_script=/opt/software/datax/bin/datax.py   #dataX脚本的绝对路径 左边是预发布的DataX执行路径 右边是 生产DataX执行路径 /opt/datax/bin/datax.py  #dataX脚本的绝对路径
json_name=${1} #传入json配置文件的绝对路径
json_file=${1}.json
log_dir=${json_name}_log
  
  
mkdir ${log_dir}
    startSec=`date -d "$startDate" "+%s"`
    endSec=`date -d "$endDate" "+%s"`
    index=0
for((i=$startSec;i<=$endSec;i+=86400));do
    yesterday=`date -d "@$i" "+%Y-%m-%d"`
    yes_format=`date -d ${yesterday} +%Y%m%d`
   echo "${yes_format}"
 echo "nohup python dataX_script $json_file  -p "-Ddt=${yesterday}" > ${log_dir}/${yesterday}.log &"
 nohup python ${dataX_script} $json_file  -p "-Ddt=${yesterday} -Ddt_format=${yes_format}"  > ${log_dir}/${yesterday}.log &   #左边-D表示传入的参数=值,如果有多个变量用空格隔开即可
  
     index=`expr $index + 1`
   if [ $index -eq $parall_num ]
    then
   echo "判断是否做完  index=${index}"
## 判断是否做完 
      times=0
      old_lines=0
      while [ 1 -eq 1 ]
      do
        echo "判断是否做完 while times=${times}"
         now_lines=`cat ${log_dir}/*.log|wc -l `
     echo "daociyiyou- ${now_lines}-----------------" 
         if [ $now_lines -eq $old_lines ]
         then
                 times=`expr $times + 1`
                 if [ $times -eq ${max_times} ]
                 then
                  break
                 fi
         fi
         old_lines=${now_lines}
         sleep 5
      done
      index=0
  fi
 
done

DataX3.0说明文档及Quick Start

1 DataX的说明文档(DataX-Introduction): https://github.com/alibaba/DataX/blob/master/introduction.md

说明文档描述的主要内容:
    1、DataX3.0的框架设计
    2、支持哪些异构数据源的数据同步
    3、每一种reader/writer的具体使用文档链接:配置样例,参数说明,功能描述等
    4、运行原理
    5、核心优势

2 DataX Github主页地址: https://github.com/alibaba/DataX

3 DataX Quick Start https://github.com/alibaba/DataX/blob/master/userGuid.md

4 不同Reder/Writer的使用说明文档

DataX3.0插件体系(摘自DataX官方文档,具体的使用文档点击相应插件的读和写文字,有超链接)

经过几年积累,DataX目前已经有了比较全面的插件体系,主流的RDBMS数据库、NOSQL、大数据计算系统都已经接入。DataX目前支持数据如下:

类型 数据源 Reader(读) Writer(写) 文档
RDBMS 关系型数据库 MySQL
Oracle
OceanBase
SQLServer
PostgreSQL
DRDS
达梦
通用RDBMS(支持所有关系型数据库)
阿里云数仓数据存储 ODPS
ADS
OSS
OCS
NoSQL数据存储 OTS
Hbase0.94
Hbase1.1
MongoDB
Hive
无结构化数据存储 TxtFile
FTP
HDFS
Elasticsearch

5 dataX的优化

关键参数

job.setting.speed.channel : channel 并发数
➢ job.setting.speed.record : 2 全局配置 channel 的 record 限速
➢ job.setting.speed.byte:全局配置 channel 的 byte 限速
➢ core.transport.channel.speed.record:单个 channel 的 record 限速
➢ core.transport.channel.speed.byte:单个 channel 的 byte 限速

优化 1:提升每个 channel 的速度

在 DataX 内部对每个 Channel 会有严格的速度控制,分两种,一种是控制每秒同步的记
录数,另外一种是每秒同步的字节数,默认的速度限制是 1MB/s,可以根据具体硬件情况设
置这个 byte 速度或者 record 速度,一般设置 byte 速度,比如:我们可以把单个 Channel 的
速度上限配置为 5MB

9.3 优化 2:提升 DataX Job 内 Channel 并发数

并发数 = taskGroup 的数量 * 每个 TaskGroup 并发执行的 Task 数 (默认为 5)。
提升 job 内 Channel 并发有三种配置方式:
9.3.1 配置全局 Byte 限速以及单 Channel Byte 限速
Channel 个数 = 全局 Byte 限速 / 单 Channel Byte 限速
{
 "core": {
 "transport": {
 "channel": {
 "speed": {
 "byte": 1048576
 }
 }
 }
 },
 "job": {
 "setting": {
 "speed": {
 "byte" : 5242880
 }
 },
 ...
 } }

core.transport.channel.speed.byte=1048576,job.setting.speed.byte=5242880,所以 Channel

个数 = 全局 Byte 限速 / 单 Channel Byte 限速=5242880/1048576=5 个

9.3.2 配置全局 Record 限速以及单 Channel Record 限速

Channel 个数 = 全局 Record 限速 / 单 Channel Record 限速

{
 "core": {
 "transport": {
 "channel": {
 "speed": {
 "record": 100
 }
 }
 }
 },
 "job": {
 "setting": {
 "speed": { "record" : 500
 }
 },
 ...
 } }

core.transport.channel.speed.record=100 , job.setting.speed.record=500, 所 以 配 置 全 局

Record 限速以及单 Channel Record 限速,Channel 个数 = 全局 Record 限速 / 单 Channel

Record 限速=500/100=5

9.3.3 直接配置 Channel 个数

只有在上面两种未设置才生效,上面两个同时设置是取值小的作为最终的 channel 数。
{
 "job": {
 "setting": {
 "speed": {
 "channel" : 5
 }
 },
 ...
 } }

直接配置 job.setting.speed.channel=5,所以 job 内 Channel 并发=5 个

9.4 优化 3:提高 JVM 堆内存

当提升 DataX Job 内 Channel 并发数时,内存的占用会显著增加,因为 DataX 作为数据

交换通道,在内存中会缓存较多的数据。例如 Channel 中会有一个 Buffer,作为临时的数据

交换的缓冲区,而在部分 Reader 和 Writer 的中,也会存在一些 Buffer,为了防止 OOM 等错

误,调大 JVM 的堆内存。

建议将内存设置为 4G 或者 8G,这个也可以根据实际情况来调整。

调整 JVM xms xmx 参数的两种方式:一种是直接更改 datax.py 脚本;另一种是在启动

的时候,加上对应的参数,如下:

python datax/bin/datax.py –jvm=”-Xms8G -Xmx8G” XXX.json

frp内网穿透并实现开机自启动

本文中使用到的端口记得在阿里云服务器的安全组中开放该端口

在公网服务器(阿里云服务器)上执行下面的命令,安装frp

wget https://github.com/fatedier/frp/releases/download/v0.38.0/frp_0.38.0_linux_arm64.tar.gz
-- 解压到/usr/local
cd /usr/local
tar -zxvf frp_0.38.0_linux_amd64.tar.gz
-- 开始编辑frps.ini
vi frps.ini
====>
[common]
bind_port = 5001
vhost_http_port = 3389
vhost_https_port = 3399
auto_token = ******  #这里是自己定义的密钥
dashboard_addr = 0.0.0.0
dashboard_port = 7500
dashboard_user = admin
dashboard_pwd = admin
    
-- 启动frps服务
./frps -c ./frps.ini
=====>后台启动
nohup ./frps -c ./frps.ini &
安装frp客户端  frpc
-- 编辑frpc.ini
vi frpc.ini
====>  每一行后面的空格记得注释都要去掉,否则可能会报错
[common]
server_addr = 公网ip   
server_port = 5001
auto_token = ******  #这里是自己定义的密钥,和上面的需保持一致
admin_addr = 0.0.0.0
admin_port = 7500
admin_user = admin
admin_pwd = admin
log_file = ./frpc.log
log_level = info
custom_domains = www.letitgo.club
[http-info]
type = http
local_ip = 内网服务器ip
local_port = 80
remote_port = 3389
custom_domains = http.letitgo.club
[https-info]
type = https
local_ip = 内网服务器ip
local_port = 8080
remote_port = 3399
custom_domains = https.letitgo.club
[ssh-info]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6000

实现frp的自启动,写一个frpc后台启动的脚本文件 start_frp.sh 在dell服务器(需要穿透的内网服务器),文件放在/home/boot_file目录下

#!/bin/bash
sudo nohup  /home/software/frp_0.38.0_linux_amd64/frpc -c  /home/software/frp_0.38.0_linux_amd64/frpc.ini &

在服务器的/etc/rc.d目录中的rc.local文件中添加下面的内容

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
chmod +x /etc/rc.d/rc.local
/home/boot_file/add_bridge.sh
#开机自启动frpc服务
chmod +x /home/boot_file/start_frp.sh
chmod +x /etc/rc.d/rc.local
su - root -c '/home/boot_file/start_frp.sh'

在具有公网ip的服务器中的/usr/local/boot_file目录下创建一个脚本start_frp.sh

sudo nohup /usr/local/frp_0.38.0_linux_amd64/frps -c /usr/local/frp_0.38.0_linux_amd64/frps.ini &

在服务器的/etc/rc.d目录中的rc.local文件中添加下面的内容

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
chmod +x /usr/local/boot_file/start_frp.sh
chmod +x /etc/rc.d/rc.local
su - root -c '/usr/local/boot_file/start_frp.sh'

尝试将dell服务器重启,重启完毕后,在随便一个shell远程工具中执行下面的操作,如果能够正确的ssh到内网服务器中,就说明自启动成功了

ssh userName@公网ip -p tcp连接方式的remote_port

navicate清除注册表,重新启动试用

1 win + R 输入 regedit 打开注册表

2 删除HKEY_CURRENT_USER\SOFTWARE\PremiumSoft\Data这个目录

3 进入这个目录HKEY_CURRENT_USER\SOFTWARE\Classes\CLSID,打开下面的一级目录,如果包含info的,将整个一级目录删除

===> 最后重新打开navicate,就可以重新试用了

在github上使用hexo搭建个人博客网站

1 注册一个github账号,设置用户名和邮箱,创建ssh密钥

-- 配置用户名和邮箱
git config --global user.name "GitHub 用户名"
git config --global user.email "GitHub 邮箱"
-- 创建ssh 私钥  一路回车即可
ssh-keygen -t rsa -C "上面配置的邮箱"   
-- 将 ~/.ssh/id_rsa.pub 文件中的公钥复制

2 点击 setting ,添加ssh key,title随便取个名字,然后将刚才粘贴的公钥放在里面

img

3 验证连接

使用git工具,输入ssh -T git@github.com,出现are you sure you want ... 输入回车即可  返回successfully表示连接成功
=====》
Hi follow-the-heard! You've successfully authenticated, but GitHub does not provide shell access.

4 创建一个repository,仓库的命名是 github用户名.github.io

img

5 安装node.js

下载官网地址 https://nodejs.org/zh-cn/

img

下载下来是一个.msi文件

img

双击后一路next即可完成安装

img

6 安装hexo

-- 在windows中打开cmd命令窗口,安装hexo本地环境
npm install -g hexo
-- 检查hexo环境是否安装成功
输入 hexo  列出一系列的使用方法,就说明hexo环境安装成功了

7 windows中创建一个目录MyBlog ,在该目录下打开cmd

img

并在cmd中执行下面的命令

-- 初始化hexo博客工程
hexo init
-- 编译博客工程
hexo g
-- 在本地启动hexo服务
hexo s

img

在浏览器中访问 http://localhost:4000 就可以看到hexo原始页面

img

需要将博客部署到github远程服务器还需要

1 安装hexo部署插件

npm install hexo-develoyer-git --save

2 修改配置文件:位于项目MyBlog根目录下的_config.yml

img

repository: git@github.com:username/git仓库地址
type: git
barnch: master

3 重新编译,然后部署

hexo g
hexo d

4 浏览器中访问 https://username.github.io

到这里hexo的博客就搭建并且部署完成了

更换hexo主题的教程:

hexo主题下载网站: https://hexo.io/themes/index.html

目前有300多种博客模板供选择

img

两种方式可供下载

1 git clone 复制链接  
2 下载zip包,然后解压到themes目录下使用

img

img

修改配置文件中的主题 _config.yml

img

清除缓存文件(db.json)和已生成的静态文件(public)

-- 当更换主题后,本地是可以看到更换后主题的效果,但是部署上去之后,会发现云端还是之前的主题,就可以执行下面的命令
hexo clean

生成静态文件

hexo g  或 hexo generate

部署博客

hexo d 或 hexo deploy

重新访问 https://username.github.io 即可看到新的博客主题

创建文章

hexo n 文章title
 

为了在文章中能插入图片,需要做下面的事情

1 将配置文件中的参数修改如下‘

-- 该参数设置为true后,创建文章时,会创建一个和文章同名的文件夹
post_asset_folder: true

2 安装插件并替换js内部的代码

1 安装插件
npm install https://github.com/CodeFalling/hexo-asset-image --save
2 这个插件的代码有bug,需要将/node_modules/hexo-asset-image/index.js中的内容替换成下面的
'use strict';
var cheerio = require('cheerio');
// http://stackoverflow.com/questions/14480345/how-to-get-the-nth-occurrence-in-a-string
function getPosition(str, m, i) {
  return str.split(m, i).join(m).length;
}
var version = String(hexo.version).split('.');
hexo.extend.filter.register('after_post_render', function(data){
  var config = hexo.config;
  if(config.post_asset_folder){
        var link = data.permalink;
    if(version.length > 0 && Number(version[0]) == 3)
       var beginPos = getPosition(link, '/', 1) + 1;
    else
       var beginPos = getPosition(link, '/', 3) + 1;
    // In hexo 3.1.1, the permalink of "about" page is like ".../about/index.html".
    var endPos = link.lastIndexOf('/') + 1;
    link = link.substring(beginPos, endPos);
    var toprocess = ['excerpt', 'more', 'content'];
    for(var i = 0; i < toprocess.length; i++){
      var key = toprocess[i];
 
      var $ = cheerio.load(data[key], {
        ignoreWhitespace: false,
        xmlMode: false,
        lowerCaseTags: false,
        decodeEntities: false
      });
      $('img').each(function(){
        if ($(this).attr('src')){
            // For windows style path, we replace '\' to '/'.
            var src = $(this).attr('src').replace('\\', '/');
            if(!/http[s]*.*|\/\/.*/.test(src) &&
               !/^\s*\//.test(src)) {
              // For "about" page, the first part of "src" can't be removed.
              // In addition, to support multi-level local directory.
              var linkArray = link.split('/').filter(function(elem){
                return elem != '';
              });
              var srcArray = src.split('/').filter(function(elem){
                return elem != '' && elem != '.';
              });
              if(srcArray.length > 1)
                srcArray.shift();
              src = srcArray.join('/');
              $(this).attr('src', config.root + link + src);
              console.info&&console.info("update link as:-->"+config.root + link + src);
            }
        }else{
            console.info&&console.info("no src attr, skipped...");
            console.info&&console.info($(this));
        }
      });
      data[key] = $.html();
    }
  }
});
3 打开_config.yml文件,修改下述内容
post_asset_folder: true

====> 博客中的图片放在和文章同名的文件夹内,并且引用的时候这样:

![图片描述](./图片名称)

  • Copyrights © 2021-2022 Kaneki Ken
  • Visitors: | Views:

^_^ 感谢您的肯定和支持 ^_^

支付宝
微信