tonglin0325的个人主页

docker安装和使用

1.安装的docker版本

1
2
3
docker -v
Docker version 17.03.2-ce

2.查看本地的镜像

1
2
docker images

3.拉取镜像

1
2
docker pull centos:7

4.编写Dockerfile

1
2
3
FROM nginx
RUN echo '<h1>Hello, Docker!</h1>' > /usr/share/nginx/html/index.html

5.build Dockerfile

1
2
docker build -t . xxx # 镜像的名字

或者

1
2
docker build -f ./Dockerfile . -t xxx:xxxx

bash

1
2
docker run -i -t ubuntu:15.10 /bin/bash

将容器中的8080端口映射到本机的18080端口

1
2
docker run -p 18080:8080 -it xxxx:v1.0.0dev /bin/bash

如果是多个端口,使用多个-p

1
2
-p 18080:8080 -p 18081:8081

参数

1
2
3
-it:这是两个参数,一个是 -i:交互式操作,一个是 -t 终端。我们这里打算进入 bash 执行一些命令并查看返回结果,因此我们需要交互式终端。
--rm:这个参数是说容器退出后随之将其删除。默认情况下,为了排障需求,退出的容器并不会立即删除,除非手动 docker rm。我们这里只是随便执行个命令,看看结果,不需要排障和保留结果,因此使用 --rm 可以避免浪费空间

6.运行

1
2
docker run xxx # 镜像的名字

7.查看自己镜像的id

1
2
docker ps

8.列出所有的容器,包括exit状态的容器

1
2
docker ps -a

9.查看内网ip地址等运行情况

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
docker inspect id | grep IP 
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.5",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"IPAMConfig": null,
"IPAddress": "172.17.0.5",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,

9.请求nginx

1
2
3
curl 172.17.0.5:80
<h1>Hello, Docker!</h1>

10.如果想要镜像不退出,然后进行镜像中

1
2
3
# run
ENTRYPOINT ["/bin/bash","-c","cat /hosts.txt >> /etc/hosts &amp;&amp; bash /sleep.sh"]

sleep.sh内容

1
2
3
4
5
6
7
#!/usr/bin/env bash

while true;
do
sleep 10000;
done

或者

1
2
ENTRYPOINT ["/bin/bash","-c","while true; do sleep 10000; done"]

然后执行

1
2
docker run  --network=host xxxx

查看id

1
2
docker ps

进入镜像中

1
2
docker exec -it xxxx bash

11.删除container,先停再删

1
2
3
docker stop 3f6822d8f262
docker rm 3f6822d8f262

12.使用docker命令从pod向宿主机拷贝文件

1
2
docker cp pod_id:/tmp/abc /tmp/

使用docker命令从宿主机向pod中拷贝文件

1
docker cp ./xx-xx pod_id:/home/xxx  

13.mac使用docker的时候配置仓库

1
2
3
4
https://registry.docker-cn.com
http://docker.mirrors.ustc.edu.cn
http://hub-mirror.c.163.com

注意:mac版本docker升级到高版本后Daemon选项没了,需要在docker engine中填写json配置

14.ubuntu配置docker仓库,在/etc/docker目录下新建daemon.json,内容

1
2
3
4
{
"registry-mirrors": ["https://registry.docker-cn.com","http://docker.mirrors.ustc.edu.cn","http://hub-mirror.c.163.com","https://3laho3y3.mirror.aliyuncs.com","http://f1361db2.m.daocloud.io"]
}

重启docker服务

1
2
sudo systemctl restart docker

15.查看docker的磁盘使用情况

1
2
3
4
5
6
7
lintong@master:~$ docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 31 1 19.17GB 19.11GB (99%)
Containers 1 1 0B 0B
Local Volumes 48 0 0B 0B
Build Cache 0 0 0B 0B

清理磁盘,删除关闭的容器、无用的数据卷和网络,以及dangling镜像(即无tag的镜像)

1
2
3
4
5
6
7
8
9
docker system prune
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all build cache
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B

如果有2个镜像的id相同,则删除的时候会报

1
2
3
docker rmi 85f602b72c3c
Error response from daemon: conflict: unable to delete 85f602b72c3c (must be forced) - image is referenced in multiple repositories

此时应该找到2个id相同的镜像,然后一个个进行删除

1
2
3
4
docker images | grep 85f602b72c3c
xxxxx v0.9.1 85f602b72c3c 6 weeks ago 2.65GB
xxxxx <none> 85f602b72c3c 6 weeks ago 2.65GB

删除第一个

1
2
docker rmi xxxxx:v0.9.1

再删除另一个

1
2
docker rmi 85f602b72c3c

15.使用 Docker 容器应该避免的 10 个事情

1
2
3
4
5
6
7
8
9
10
11
1.不要在容器中存储数据 &ndash;  容器可能被停止,销毁,或替换。
2.不要将你的应用发布两份 &ndash; 一些人将容器视为虚拟机。
3.不要创建超大镜像 &ndash; 一个超大镜像只会难以分发。
4.不要使用单层镜像
5.不要为运行中的容器创建镜像
6.不要只使用&ldquo;最新&rdquo;标签
7.不要在单一容器中运行超过一个进程
8.不要在镜像中存储凭据
9.使用非root用户运行进程
10.不要依赖IP地址

参考:10 things to avoid in docker containers

16.docker设置时区

1
2
3
4
5
6
7
8
ENV TZ=Asia/Shanghai
# ENV TZ=America/Los_Angeles

RUN echo ${TZ} > /etc/timezone \
&amp;&amp; ln -fs /usr/share/zoneinfo/${TZ} /etc/localtime \
&amp;&amp; apt update \
&amp;&amp; apt install -y tzdata

17.ubuntu镜像换源

1
2
3
4
5
RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list &amp;&amp; \
sed -i s@/security.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list &amp;&amp; \
apt-get clean &amp;&amp; \
apt-get update

Thrift关键字

在编译thrift文件的时候发现报了如下的错误

1
2
Cannot use reserved language keyword: "class"

后来查了一下,发现class是thrift的关键字之一,变量起名的时候不能和关键字重复

thrift的全部关键字可以查看thrift的源码

1
2
https://github.com/apache/thrift/blob/master/compiler/cpp/src/thrift/generate/t_py_generator.cc

搜索keywords,下面这些都是thrift关键字,在起名的时候需要注意

全文 >>

ubuntu安装thrift

ubuntu环境下安装thrift-0.10.0

1.解压

2.编译安装

1
2
3
4
./configure -with-cpp -with-boost -without-python -without-csharp -with-java -without-erlang -without-perl -without-php -without-php_extension -without-ruby -without-haskell -without-go
make
sudo make install

3.是否安装成功

1
2
3
thrift -version
Thrift version 0.10.0

全文 >>

xxl-job安装教程

xxl-job是一个开源的分布式调度框架,其他类似的框架还有airflow,oozie等等,需要进行对比

1
2
https://github.com/xuxueli/xxl-job

1.首先git clone工程

1
2
git clone git@github.com:xuxueli/xxl-job.git

打包工程,打包的过程中会下载所需要的jar包

1
2
mvn package

全文 >>

Elasticsearch学习笔记——常用命令

1.创建索引,名字为index

1
2
curl -XPUT http://localhost:9200/index

2.创建一个mapping

1
2
3
4
5
6
7
8
9
10
11
12
curl -XPOST http://localhost:9200/index/fulltext/_mapping -H 'Content-Type:application/json' -d'
{
"properties": {
"content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}

}'

3.查看mapping

1
2
curl -XPUT http://localhost:9200/xxx/yyy/_mapping

4.删除一个文档,按照id来删除

1
2
curl -XDELETE 'http://localhost:9200/index3/fulltext3/272'

5.通过query来删除文档

不同版本之间的es不太一样,6.2的参考

1
2
https://www.elastic.co/guide/en/elasticsearch/reference/6.2/docs-delete-by-query.html

比如使用kibana里面的dev tool,就可以删掉所有schema字段是“xxxx”的数据

1
2
3
4
5
6
7
8
9
POST xxxxx_2019-12-09/_delete_by_query
{
"query": {
"match": {
"schema": "xxxx"
}
}
}

6.es的task api,参考

1
2
http://xiaorui.cc/archives/3089

7.scroll查看数据,from+size查询最多只能查10000

参考:https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-scroll.html

1
2
curl -XPOST -H 'Content-Type: application/json' http://localhost:9200/_search/scroll -d@data.json

data.json

1
2
3
4
{
"scroll" : "1m",
"scroll_id" : "xxxxxxxx"
}

8.删除一个索引

1
2
curl -XDELETE http://ip:port/xxxx

  

全文 >>

Elasticsearch学习笔记——分词

1.测试Elasticsearch的分词

Elasticsearch有多种分词器(参考:https://www.jianshu.com/p/d57935ba514b)

Set the shape to semi-transparent by calling set_trans(5)

(1)standard analyzer:标准分词器(默认是这种)

set,the,shape,to,semi,transparent by,calling,set_trans,5

(2)simple analyzer:简单分词器

set, the, shape, to, semi, transparent, by, calling, set, trans

(3)whitespace analyzer:空白分词器。大小写,下划线等都不会转换

Set, the, shape, to, semi-transparent, by, calling, set_trans(5)

(4)language analyzer:(特定语言分词器,比如说English英语分词器)

set, shape, semi, transpar, call, set_tran, 5

全文 >>

Ubuntu下安装antlr-4.7.1

简介:antlr工具将语法文件转换成可以识别该语法文件所描述的语言的程序.

例如:给定一个识别json的语法,antlr工具将会根据该语法生成一个程序,该程序可以通过antlr运行库来识别输入的json.

全文 >>

Flink学习笔记——读写hudi

使用flink来读写hudi有2种API,一个是Flink SQL API,另一个是DataStream API,参考

1
https://hudi.apache.org/cn/docs/flink-quick-start-guide

首先启动yarn session

1
2
/usr/lib/flink/bin/yarn-session.sh -n 3 -s 5 -jm 1024 -tm 4096 -d

使用SQL API提交任务到YARN上的方式有以下几种:

1.使用交互式的sql client

不过由于sql client目前处于beta版本,所以建议用于原型验证,不建议在生产环境中使用,参考:Apache Flink 零基础入门(四):客户端操作的 5 种模式

1
2
https://nightlies.apache.org/flink/flink-docs-release-1.13/docs/dev/table/sqlclient/

启动

1
2
/usr/lib/flink/bin/sql-client.sh

首先使用Flink SQL创建hudi表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Flink SQL> CREATE TABLE hudi_test_table(
_id STRING,
xxx STRING,
primary key(_id) not enforced
) WITH (
'connector' = 'hudi',
'path' = 's3a://xxxx/hudi_test_table',
'table.type' = 'MERGE_ON_READ',
'changelog.enabled'= 'true',
'compaction.async.enabled'='true',
'compaction.tasks'= '4',
'compaction.trigger.strategy'= 'time_elapsed',
'compaction.delta_seconds'= '600',
'compaction.max_memory'= '1024',
'write.option' = 'upsert',
'read.streaming.check-interval'= '3',
'hive_sync.enable' = 'true',
'hive_sync.mode' = 'hms',
'hive_sync.metastore.uris' = 'thrift://xxx:9083',
'hive_sync.table'='hudi_test_table',
'hive_sync.db'='default',
'write.tasks'='4'
);

查询该hudi表

1
2
Flink SQL> select * from hudi_test_table limit 10;

查询结果

在生产环境中如果使用FlinkSQL,建议使用

全文 >>

wherehows踩坑记录

wherehows是Linkedin开源的大数据治理框架,提供了元数据管理,数据血缘,数据预览,集成多种数据源的功能,最近在进行调研工作

类似的框架有Netflix的metacat,这个两个开源项目都是坑不少,目前还在踩坑阶段中…由于网上关于这两个项目的文章有价值,本文希望能对你有帮助

其他公司也有很多类似的数据发现系统,参考:Data Discovery Platforms and Their Open Source Solutions

全文 >>