0%

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
used_memory:由 Redis 分配器分配的内存总量,包含了redis进程内部的开销和数据占用的内存,以字节(byte)为单位
used_memory_human:已更直观的单位展示分配的内存总量。
used_memory_rss:向操作系统申请的内存大小。与 top 、 ps等命令的输出一致。
used_memory_rss_human:已更直观的单位展示向操作系统申请的内存大小。
used_memory_peak:redis的内存消耗峰值(以字节为单位)
used_memory_peak_human:以更直观的格式返回redis的内存消耗峰值
used_memory_peak_perc:使用内存达到峰值内存的百分比,即(used_memory/ used_memory_peak) *100%
used_memory_overhead:Redis为了维护数据集的内部机制所需的内存开销,包括所有客户端输出缓冲区、查询缓冲区、AOF重写缓冲区和主从复制的backlog。
used_memory_startup:Redis服务器启动时消耗的内存
used_memory_dataset:数据占用的内存大小,即used_memory-sed_memory_overhead
used_memory_dataset_perc:数据占用的内存大小的百分比,100%*(used_memory_dataset/(used_memory-used_memory_startup))
total_system_memory:整个系统内存
total_system_memory_human:以更直观的格式显示整个系统内存
used_memory_lua:Lua脚本存储占用的内存
used_memory_lua_human:以更直观的格式显示Lua脚本存储占用的内存
maxmemory:Redis实例的最大内存配置
maxmemory_human:以更直观的格式显示Redis实例的最大内存配置
maxmemory_policy:当达到maxmemory时的淘汰策略
mem_fragmentation_ratio:碎片率,used_memory_rss/ used_memory
mem_allocator:内存分配器
active_defrag_running:表示没有活动的defrag任务正在运行,1表示有活动的defrag任务正在运行(defrag:表示内存碎片整理)
lazyfree_pending_objects:0表示不存在延迟释放的挂起对象

本文地址: https://github.com/maxzhao-it/blog/post/28d95dfe/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
LATEST_VERSION=$(curl -s https://packages.clickhouse.com/tgz/stable/ | \
grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | sort -V -r | head -n 1)
export LATEST_VERSION

case $(uname -m) in
x86_64) ARCH=amd64 ;;
aarch64) ARCH=arm64 ;;
*) echo "Unknown architecture $(uname -m)"; exit 1 ;;
esac

for PKG in clickhouse-common-static clickhouse-common-static-dbg clickhouse-server clickhouse-client clickhouse-keeper
do
curl -fO "https://packages.clickhouse.com/tgz/stable/$PKG-$LATEST_VERSION-${ARCH}.tgz" \
|| curl -fO "https://packages.clickhouse.com/tgz/stable/$PKG-$LATEST_VERSION.tgz"
done

tar -xzvf "clickhouse-common-static-$LATEST_VERSION-${ARCH}.tgz" \
|| tar -xzvf "clickhouse-common-static-$LATEST_VERSION.tgz"
sudo "clickhouse-common-static-$LATEST_VERSION/install/doinst.sh"

tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION-${ARCH}.tgz" \
|| tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION.tgz"
sudo "clickhouse-common-static-dbg-$LATEST_VERSION/install/doinst.sh"

tar -xzvf "clickhouse-server-$LATEST_VERSION-${ARCH}.tgz" \
|| tar -xzvf "clickhouse-server-$LATEST_VERSION.tgz"
sudo "clickhouse-server-$LATEST_VERSION/install/doinst.sh" configure
sudo /etc/init.d/clickhouse-server start

tar -xzvf "clickhouse-client-$LATEST_VERSION-${ARCH}.tgz" \
|| tar -xzvf "clickhouse-client-$LATEST_VERSION.tgz"
sudo "clickhouse-client-$LATEST_VERSION/install/doinst.sh"

rpm

1
2
3
4
5
6
7
8
9
10
11
12
13
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://packages.clickhouse.com/rpm/clickhouse.repo
sudo yum install -y clickhouse-server clickhouse-client
sudo systemctl enable clickhouse-server
sudo systemctl start clickhouse-server
sudo systemctl status clickhouse-server
clickhouse-client # or "clickhouse-client --password" if you set up a password.
# 单独服务器安装
sudo yum install -y clickhouse-keeper
sudo systemctl enable clickhouse-keeper
sudo systemctl start clickhouse-keeper
sudo systemctl status clickhouse-keeper

本文地址: https://github.com/maxzhao-it/blog/post/78c07643/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
package com.maxzhao;


import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Stack;
import java.util.function.BiFunction;
import java.util.function.Function;

/**
* 计算四则运算表达式(含括号),返回计算结果
* 已有合法表达式校验
*
* @author
* @time 2018.12.10
*/
public class CalculatorUtils2 {

/**
* 符号栈:运算符和括号
*/
private static Stack<String> symbolStack = null;

/**
* 解析并计算四则运算表达式(含括号),返回计算结果
*
* @param expression 算术表达式(含括号)
*/
public static BigDecimal caculateBigDecimal(String expression) {
expression = removeStrSpace(expression);
if (expression.length() > 1 && !"=".equals(expression.charAt(expression.length() - 1) + "")) {
expression += "=";
}
if (!isStandard(expression)) {
System.err.println("错误:算术表达式有误!");
return new BigDecimal("-1");
}
Stack<BigDecimal> numStack = new Stack<>();
symbolStack = new Stack<>();
StringBuffer temp = new StringBuffer();
char thisChar;
for (int i = 0; i < expression.length(); i++) {
thisChar = expression.charAt(i);
if (isNumber(thisChar) || thisChar == '.') {
temp.append(thisChar);
continue;
}
if (!temp.toString().isEmpty()) {
numStack.push(new BigDecimal(temp.toString()));
temp = new StringBuffer();
}
if (' ' == thisChar) {
/*忽略空格和 ,*/
continue;
}
/*校验运算符*/
if ('f' == thisChar) {
String floorStr = expression.substring(i, i + 5);
if ("floor".equals(floorStr)) {
i += 4;
symbolStack.push(floorStr);
continue;
}
} else if ('m' == thisChar) {
String floorStr = expression.substring(i, i + 3);
if ("max".equals(floorStr)) {
i += 2;
symbolStack.push(floorStr);
continue;
} else if ("min".equals(floorStr)) {
i += 2;
symbolStack.push(floorStr);
continue;
}
}
int numCount = 1;
BigDecimal a, b;
BigDecimal[] numArr;
while (!compareStackPeek(String.valueOf(thisChar))) {
String top = symbolStack.peek();
switch (top) {
case "+":
b = numStack.pop();
a = numStack.pop();
numStack.push(a.add(b));
symbolStack.pop();
break;
case "-":
b = numStack.pop();
a = numStack.pop();
numStack.push(a.subtract(b));
symbolStack.pop();
break;
case "*":
b = numStack.pop();
a = numStack.pop();
numStack.push(mul(a, b));
symbolStack.pop();
break;
case "/":
b = numStack.pop();
a = numStack.pop();
/*TODO 保留小数位数*/
numStack.push(b.signum() == 0 ? BigDecimal.ZERO : a.divide(b, 10, RoundingMode.CEILING));
symbolStack.pop();
break;
}
if (')' == thisChar) {
switch (top) {
case ",":
numCount++;
symbolStack.pop();
break;
case "floor":
numStack.push(CalculatorMathFunction.functionParamMap.get("floor").apply(numStack.pop()));
symbolStack.pop();
break;
case "max":
numArr = new BigDecimal[numCount];
for (int j = 0; j < numCount; j++) {
numArr[j] = numStack.pop();
}
numStack.push(CalculatorMathFunction.functionParamsMap.get("max").apply(numArr));
symbolStack.pop();
break;
case "min":
numArr = new BigDecimal[numCount];
for (int j = 0; j < numCount; j++) {
numArr[j] = numStack.pop();
}
numStack.push(CalculatorMathFunction.functionParamsMap.get("min").apply(numArr));
symbolStack.pop();
break;
}
if ("(".equals(top)) {
symbolStack.pop();
break;
}
} else {
break;
}
}
if (thisChar != '=') {
if (")".equals(String.valueOf(thisChar))
/* && "(".equals(symbolStack.peek())*/) {
// symbolStack.pop();
} else {
symbolStack.push(String.valueOf(thisChar));
}
}
}
return numStack.pop();
}

/**
* 去除字符串中的所有空格
*
* @param str
* @return
*/
private static String removeStrSpace(String str) {
return str != null ? str.contains(" ") ? removeStrSpace(str.replaceAll(" ", "")) : str.replaceAll(" ", "") : "";
}

/**
* 检查算术表达式的基本合法性
*
* @param expression 计算表达式
* @return 符合返回true,否则false
*/
private static boolean isStandard(String expression) {
if (Optional.ofNullable(expression).orElse("").isEmpty()) {
return false;
}
if (expression.indexOf("=") != expression.length() - 1) {
return false;
}
int countLeftParenthesis = 0;
char thisChar;
for (int i = 0; i < expression.length(); i++) {
thisChar = expression.charAt(i);
/*校验是否为函数*/
if ('f' == thisChar) {
String floorStr = expression.substring(i, i + 5);
if ("floor".equals(floorStr)) {
i += 5;
continue;
}
} else if ('m' == thisChar) {
String floorStr = expression.substring(i, i + 3);
if ("max".equals(floorStr)) {
i += 3;
continue;
} else if ("min".equals(floorStr)) {
i += 3;
continue;
}
}
if (!isNumber(thisChar) && !isOperator(thisChar)) {
return false;
}
if ("(".equals(String.valueOf(thisChar))) {
countLeftParenthesis++;
}
if (")".equals(String.valueOf(thisChar))) {
if (countLeftParenthesis == 0) {
return false;
}
countLeftParenthesis--;
}
}
return countLeftParenthesis == 0;
}

/**
* 判断字符是否为数字
*
* @param num 字符
* @return true 数字
*/
private static boolean isNumber(char num) {
return num >= '0' && num <= '9';
}

/**
* 判断字符是否为运算符
*
* @param num 字符
* @return true 操作符
*/
private static boolean isOperator(char num) {
return "()+-*/=".contains(String.valueOf(num));
}

/**
* 比较优先级:当前运算符比栈顶元素运算符
*
* @param symbol
* @return 优先级高则返回true,否则返回false
*/
private static boolean compareStackPeek(String symbol) {
if (symbolStack.empty()) {
return true;
}
// 符号优先级说明(从高到低):
// 第1级: (
// 第2级: * /
// 第3级: + -
// 第4级: )
String top = symbolStack.peek();
// if ("(".equals(top)) {
// return true;
// }
// 比较优先级
switch (symbol) {
case "(":
return true;
case "*":
case "/":
return ("+".equals(top) || "-".equals(top));
case "+":
case "-":
case ")":
case "=":
return false;
default:
break;
}
return true;
}

/*
*精确加法
*/
public static BigDecimal add(BigDecimal b1, BigDecimal b2) {
return b1.add(b2);
}

/*
*精确减法
*/
public static BigDecimal sub(BigDecimal b1, BigDecimal b2) {
return b1.subtract(b2);
}

/*
*精确乘法
*/
public static BigDecimal mul(BigDecimal b1, BigDecimal b2) {
return b1.multiply(b2);
}

/*
*精确乘法(扩大times倍)
*/
public static BigDecimal mul(BigDecimal b, int times) {
return b.multiply(new BigDecimal(Integer.valueOf(times).toString()));
}

/*
*精确除法(默认精度)
*/
public static BigDecimal div(BigDecimal b1, BigDecimal b2) {
return div(b1, b2, 2);
}

/*
*精确除法
*/
public static BigDecimal div(BigDecimal b1, BigDecimal b2, int scale) {
if (b2.equals(new BigDecimal(0))) {
return new BigDecimal(0);
}
return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP);
}


/*
*精确比较(与零比较)
*/
public static int comparetoZero(BigDecimal b1) {
BigDecimal b2 = new BigDecimal("0");

return b1.compareTo(b2);//b1>b2返回1 b1=b2 返回0 1<b2返回-1.
}

public static void main(String[] args) {
String expression = "((10+5) *3.7-4)/2.2";
BigDecimal result = CalculatorUtils2.caculateBigDecimal(expression);
System.out.println(expression + " = " + result);
}
}

class CalculatorMathFunction {

public static final Map<String, Function<BigDecimal, BigDecimal>> functionParamMap = new HashMap<>();
public static final Map<String, Function<BigDecimal[], BigDecimal>> functionParamsMap = new HashMap<>();
public static final Map<String, BiFunction<BigDecimal, BigDecimal, BigDecimal>> biFunctionMap = new HashMap<>();

static {
functionParamMap.put("floor", new FloorFunction());
functionParamsMap.put("max", new MaxFunction());
functionParamsMap.put("min", new MinFunction());
}

static class FloorFunction implements Function<BigDecimal, BigDecimal> {
@Override
public BigDecimal apply(BigDecimal bigDecimal) {
return bigDecimal.setScale(0, RoundingMode.FLOOR);
}
}

static class MaxFunction implements Function<BigDecimal[], BigDecimal> {
@Override
public BigDecimal apply(BigDecimal[] numArr) {
if (numArr.length == 0) {
return null;
} else if (numArr.length == 1) {
return numArr[0];
}
BigDecimal max = numArr[0];
for (int i = 1; i < numArr.length; i++) {
max = max.max(numArr[i]);
}
return max;
}
}

static class MinFunction implements Function<BigDecimal[], BigDecimal> {
@Override
public BigDecimal apply(BigDecimal[] numArr) {
if (numArr.length == 0) {
return null;
} else if (numArr.length == 1) {
return numArr[0];
}
BigDecimal min = numArr[0];
for (int i = 1; i < numArr.length; i++) {
min = min.min(numArr[i]);
}
return min;
}
}
}

本文地址: https://github.com/maxzhao-it/blog/post/cc2eebaa/

下载JDK1.8

1
keytool -genkey -alias maxzhaoapp -keyalg RSA -keysize 2048 -validity 36500 -keystore com.maxzhao
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Enter keystore password:  //输入证书文件密码,输入完成回车  
Re-enter new password: //再次输入证书文件密码,输入完成回车
What is your first and last name?
[Unknown]: //输入名字和姓氏,输入完成回车
What is the name of your organizational unit?
[Unknown]: //输入组织单位名称,输入完成回车
What is the name of your organization?
[Unknown]: //输入组织名称,输入完成回车
What is the name of your City or Locality?
[Unknown]: //输入城市或区域名称,输入完成回车
What is the name of your State or Province?
[Unknown]: //输入省/市/自治区名称,输入完成回车
What is the two-letter country code for this unit?
[Unknown]: //输入国家/地区代号(两个字母),中国为CN,输入完成回车
Is CN=XX, OU=XX, O=XX, L=XX, ST=XX, C=XX correct?
[no]: //确认上面输入的内容是否正确,输入y,回车

Enter key password for <testalias>
(RETURN if same as keystore password): //确认证书密码与证书文件密码一样(HBuilder|HBuilderX要求这两个密码一致),直接回车就可以
1
keytool -list -v -keystore com.maxzhao
1
keytool -importkeystore -srckeystore com.maxzhao -destkeystore com.maxzhao -deststoretype pkcs12

本文地址: https://github.com/maxzhao-it/blog/post/a1c1999c/

Docker安装Kafka

先安装zk

1
docker pull bitnami/kafka:2.7.0

启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
mkdir -p /opt/maxzhao/kafka/data
mkdir -p /opt/maxzhao/kafka/config
mkdir -p /opt/maxzhao/kafka/logs
sudo docker stop kafka1
sudo docker remove kafka1
sudo docker run --hostname kafka1 --name kafka1 \
-e "KAFKA_CFG_NODE_ID=1" \
-e "KAFKA_CFG_PROCESS_ROLES=controller,broker" \
-e "KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093" \
-e "KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://:9092" \
-e "ALLOW_PLAINTEXT_LISTENER=true" \
-e "KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT" \
-e "KAFKA_ZOOKEEPER_PROTOCOL=PLAINTEXT" \
-e "KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@kafka1:9093" \
-e "KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER" \
-e "KAFKA_CFG_INTER_BROKER_LISTENER_NAME=PLAINTEXT" \
-e "KAFKA_CFG_ZOOKEEPER_CONNECT=zk1:2181" \
-e "KAFKA_KRAFT_CLUSTER_ID=eflow-kafka-cluster" \
-e "KAFKA_HEAP_OPTS=-Xmx8192m -Xms1024m" \
-p 59092:9092 \
-p 59093:9093 \
-p 59094:9094 \
-v /opt/maxzhao/kafka/data/:/bitnami/kafka/data \
-v /opt/maxzhao/kafka/config/:/bitnami/kafka/config \
-v /opt/maxzhao/kafka/logs/:/kafka-logs \
--restart always -d bitnami/kafka:2.7.0
sudo docker ps

查询端口占用

1
sudo netstat -tulpn | grep 59092

“ALLOW_PLAINTEXT_LISTENER=true” 线上环境不能使用

本文地址: https://github.com/maxzhao-it/blog/post/4179414/

Docker安装Zookeeper

1
docker pull zookeeper:3.5.9-openjdk

启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
sudo mkdir -p /opt/maxzhao/zk/config
sudo mkdir -p /opt/maxzhao/zk/data
sudo mkdir -p /opt/maxzhao/zk/datalog
sudo mkdir -p /opt/maxzhao/zk/logs
sudo docker stop zk1
sudo docker remove zk1
sudo docker run --hostname zk1 --name zk1 \
-e "JVMFLAGS=-Xmx4096m" \
-e "ZOO_MAX_CLIENT_CNXNS=0" \
-p 2181:2181 \
-p 2888:2888 \
-p 3888:3888 \
-p 58080:8080 \
-v /opt/maxzhao/zk/config/zoo.cfg:/conf/zoo.cfg \
-v /opt/maxzhao/zk/data/:/data \
-v /opt/maxzhao/zk/datalog/:/datalog \
-v /opt/maxzhao/zk/logs/:/logs \
--restart always -d zookeeper:3.5.9-openjdk
sudo docker ps
  • ZOO_MAX_CLIENT_CNXNS=0 不限制连接数

查询端口占用

1
sudo netstat -tulpn | grep 58080

本文地址: https://github.com/maxzhao-it/blog/post/4179413/