tonglin0325的个人主页

ubuntu16.04安装minikube

使用原生包管理工具安装kubectl

1.更新 apt 包索引,并安装使用 Kubernetes apt 仓库所需要的包

1
2
3
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl

2.下载 Google Cloud 公开签名秘钥,如果有网络问题的话,可以手动下载apt-key.gpg文件,然后将其改名并移动到/usr/share/keyrings/kubernetes-archive-keyring.gpg目录

1
2
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg

3.添加 Kubernetes apt 仓库:

1
2
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

如果报错,可以使用中科大的源

1
2
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] http://mirrors.ustc.edu.cn/kubernetes/apt kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

4.更新 apt 包索引,使之包含新的仓库并安装 kubectl:

全文 >>

使用Presto parser解析SQL

Presto的语法解析器是使用ANTLR生成的

PrestoDB的parser g4语法文件

1
2
https://github.com/prestodb/presto/blob/master/presto-parser/src/main/antlr4/com/facebook/presto/sql/parser/SqlBase.g4

PrestoSQL(Trino)的parser g4语法文件

1
2
https://github.com/trinodb/trino/blob/master/core/trino-grammar/src/main/antlr4/io/trino/grammar/sql/SqlBase.g4

如果想在java代码中使用Presto的parser进行语法解析的话,可以引用下面的依赖

PrestoDB(Facebook版本)

1
2
3
4
5
6
<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-parser</artifactId>
<version>0.285.1</version>
</dependency>

PrestoSQL(社区版本,350及其以下版本叫prestosql,以上改名为Trino)

1
2
3
4
5
6
<dependency>
<groupId>io.prestosql</groupId>
<artifactId>presto-parser</artifactId>
<version>330</version>
</dependency>

全文 >>

使用jmap排查java程序内存泄露

1.使用jmap命令生成内存快照文件(Heap Profile)

1
2
jmap -dump:format=b,file=heap.hprof ${pid}

如果生成快照的时候遇到如下报错

1
2
3
4
5
6
7
8
9
Dumping heap to /mnt/tmp/heap.hprof ...
Exception in thread "main" java.io.IOException: Premature EOF
at sun.tools.attach.HotSpotVirtualMachine.readInt(HotSpotVirtualMachine.java:292)
at sun.tools.attach.LinuxVirtualMachine.execute(LinuxVirtualMachine.java:200)
at sun.tools.attach.HotSpotVirtualMachine.executeCommand(HotSpotVirtualMachine.java:261)
at sun.tools.attach.HotSpotVirtualMachine.dumpHeap(HotSpotVirtualMachine.java:224)
at sun.tools.jmap.JMap.dump(JMap.java:247)
at sun.tools.jmap.JMap.main(JMap.java:142)

添加如下参数就可以解决

1
jmap -J-d64 -dump:format=b,file=/mnt/tmp/heap.hprof ${pid}

参考:jmap -dump导出jvm堆内存信息时报错

2.使用Eclipse Memory Analyzer工具对hprof文件进行分析

如果机器的java版本是java8的话,需要注意MAT 1.12.0版本需要jdk11,所以下载1.10.0版本

1
2
http://www.eclipse.org/downloads/download.php?file=/mat/1.10.0/rcp/MemoryAnalyzer-1.10.0.20200225-linux.gtk.x86_64.zip

否则会出现如下报错

1
Unrecognized option: --add-exports=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. Unable to init server: Could not connect: Connection refused  

全文 >>

Flink学习笔记——Flink SQL

flink官方从1.8.0开始提供Table&SQL API,参考

1
2
https://github.com/apache/flink/tree/release-1.8.0/flink-table

如果想使用Flink SQL的话,可以参考官方的get start文档,如下

1
2
https://nightlies.apache.org/flink/flink-docs-master/docs/dev/table/sql/gettingstarted/

找到flink的安装目录

1
2
cd /usr/lib/flink

首先需要启动一个flink集群,这里使用yarn-session模式来启动一个flink session集群,比如

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

一旦flink集群启动,你就可以访问一个本地的FlinkUI

全文 >>

Flink学习笔记——Standalone模式

Flink的部署方式有如下几种,本文主要介绍standalone模式

1
2
3
4
5
Yarn
Mesos
Docker/Kubernetes
Standalone

standalone模式的官方文档可以参考

1
2
https://nightlies.apache.org/flink/flink-docs-master/docs/deployment/resource-providers/standalone/overview/#standalone

进入flink的安装目录

1
2
/usr/lib/flink

启动一个standalone的flink集群

1
2
./bin/start-cluster.sh

这时可以在默认的8081端口查看FlinkUI

提交任务

全文 >>

Java程序开启JMX以及配置Promethus exporter

Java程序开启JMX的方法有2种:

第1种是在启动参数中添加如下配置

 

第2种是在环境变量中添加

 

官方JMX exporter

1
2
https://github.com/prometheus/jmx_exporter

  

jmxConnector.yaml配置如下

1
2
3
4
5
lowercaseOutputName: false
lowercaseOutputLabelNames: false
blacklistObjectNames: [ "java.lang:*", "java.nio:*", "metrics:name=my_test_job.driver.BlockManager.disk.diskSpaceUsed_MB,*"]
whitelistObjectNames: [ "*:*" ]

或者

全文 >>

linux os参数调优

1、net.core.somaxconn

net.core.somaxconn是Linux中的一个kernel参数,表示socket监听(listen)的backlog上限。什么是backlog呢?backlog就是socket的监听队列,当一个请求(request)尚未被处理或建立时,他会进入backlog。而socket server可以一次性处理backlog中的所有请求,处理后的请求不再位于监听队列中。当server处理请求较慢,以至于监听队列被填满后,新来的请求会被拒绝。在Hadoop 1.0中,参数ipc.server.listen.queue.size控制了服务端socket的监听队列长度,即backlog长度,默认值是128。而Linux的参数net.core.somaxconn默认值同样为128。当服务端繁忙时,如NameNode或JobTracker,128是远远不够的。这样就需要增大backlog,例如我们的3000台集群就将ipc.server.listen.queue.size设成了32768,为了使得整个参数达到预期效果,同样需要将kernel参数net.core.somaxconn设成一个大于等于32768的值。

参考:关于linux内核参数的调优,你需要知道

 

2、net.ipv4.tcp_max_syn_backlog

表示SYN队列长度,默认1024,改成8192,可以容纳更多等待连接的网络连接数。

参考:Linux内核参数调优

 

3、编辑/etc/sysctl.conf

net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30

然后执行/sbin/sysctl -p让参数生效。

net.ipv4.tcp_syncookies = 1表示开启SYN Cookies。当出现SYN等待队列溢出时,启用cookies来处理,可防范少量SYN攻击,默认为0,表示关闭;

net.ipv4.tcp_tw_reuse = 1表示开启重用。允许将TIME-WAIT sockets重新用于新的TCP连接,默认为0,表示关闭;

全文 >>

字符编码

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import org.omg.CORBA.portable.OutputStream;

public class code_demo {

public static void main(String[] args) throws Exception {
// TODO 自动生成的方法存根
System.out.println("系统默认编码:"+System.getProperty("file.encoding")); //获取系统当前的编码
File file = new File("/home/common/software/coding/HelloWord/HelloWord/b.txt");//路径
FileOutputStream out = new FileOutputStream(file);
byte b[] = "中国".getBytes("ISO8859-1");
out.write(b);
out.close();
}

}

 

Presto学习笔记——Python客户端连接Presto

参考:三种客户端连接Presto

1.使用 presto-client

1
2
pip install presto-client==0.302.0

查询

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import presto

# demo about the usage of presto-python-client
conn = presto.dbapi.connect(
host='localhost',
port=8889,
user='hadoop',
catalog='xx_catalog',
schema='default'
)
cur = conn.cursor()
sql = "select * from xxx.xxx limit 10"
cur.execute(sql)
rows = cur.fetchall()
print(rows)

Prometheus使用教程

官方文档:https://prometheus.io/docs/prometheus/latest/getting_started/

其他参考:CentOS7安装部署Prometheus+Grafana 

1.安装Prometheus

官方网站下载二进制安装包:https://prometheus.io/download/

可以选择mac,linux和Windows版本

1
2
3
https://github.com/prometheus/prometheus/releases/download/v2.36.1/prometheus-2.36.1.linux-amd64.tar.gz
tar -zxvf prometheus-2.36.1.linux-amd64.tar.gz

  

2.修改prometheus配置

配置文件为prometheus.yml

prometheus采集数据的方法分成推和拉

1.prometheus定时通过exporter暴露的HTTP端口主动去采集监控数据的方式就是拉

下面就是配置一个exporter采集任务的例子

1
2
3
4
5
6
7
8
9
10
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"

# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.

static_configs:
- targets: ["xx:xx"]

2.程序主动上报metrics给prometheus的pushgateway则是推

要主动上报metrics首先要安装pushgateway,参考:prometheus-pushgateway安装

在官方的文档当中,pushgateway唯一推荐使用的场景是在批处理作业运行结果的采集上,其他的建议使用exporter:when-to-use-the-pushgateway

全文 >>