(存档的时间长了,没有仔细核对,记录仅供备份) #添加虚拟服务 ipvsadm -A -t 9.30.2.201:15027 -s wrr #添加RS服务( ipvsadm -a -t 9.30.2.201:15027 -r 9.30.2.199:15027 -g -w 3 #修改虚拟服务 ipvsadm -E -t 10.58.89.140:15515 -s rr #删除所有 ipvsadmin […]
kafka常用操作
1、启停: ./kafka-server-start.sh -daemon ../config/server.properties ./kafka-server-stop.sh -daemon ../config/server.properties 2、创建topic bin/kafka-topics.sh --create --bootstrap-server localhost:9092 -- […]
tc常用限流配置
#模拟网络延迟 tc qdisc add dev eth1 root netem delay 500ms #模拟丢包 tc qdisc add dev bond1 root netem loss 1% #模拟数据包损坏 tc qdisc add dev eth1 root netem corrupt 0.5% #模拟数据包乱序 tc qdisc change dev enp131s0f1 root […]
iptables
1.拦截特定来访端口 iptables -A INPUT -s 192.168.1.10 -p tcp --sport 4232 -j REJECT iptables -A INPUT -s 192.168.2.10 -p tcp --dport 4045 -j DROP iptables -A INPUT -p tcp --dport 4002 -j REJECT 删除 iptables -L […]
AI是真会编
在搜索引擎时代,查询的结果是从万万千千历史信息中过滤的,当AI来临,结果都是基于历史经验“智能”算出来的,一个是有无,一个是真假。当使用者无法判别结果时,往往就会被“智能化”信息中的坑严重误导 举个栗子,在OCP 908认证中有这么一个关于mysqlcheck的问题,一个选项是mysqlcheck改名为mysqlrepair后执行会自动修复损坏的表,正确or否 看看元宝关于mysqlcheck改名 […]
mysql插件audit_log试用
国产的路感觉越走越远,越走越迷糊 1,在mysql的share目录下找到初始化table/routing/plugin的sql文件,然后在mysql库下执行,文件名是audit_log_filter_linux_install.sql,内容如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# Copyright (c) 2016, 2025, Oracle and/or its affiliates. CREATE TABLE IF NOT EXISTS audit_log_filter(NAME VARCHAR(64) BINARY NOT NULL PRIMARY KEY, FILTER JSON NOT NULL) engine= InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_ci; CREATE TABLE IF NOT EXISTS audit_log_user(USER VARCHAR(32) BINARY NOT NULL, HOST VARCHAR(255) CHARACTER SET ASCII NOT NULL, FILTERNAME VARCHAR(64) BINARY NOT NULL, PRIMARY KEY (USER, HOST), FOREIGN KEY (FILTERNAME) REFERENCES audit_log_filter(NAME)) engine= InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_ci; INSTALL PLUGIN audit_log SONAME 'audit_log.so'; CREATE FUNCTION audit_log_filter_set_filter RETURNS STRING SONAME 'audit_log.so'; CREATE FUNCTION audit_log_filter_remove_filter RETURNS STRING SONAME 'audit_log.so'; CREATE FUNCTION audit_log_filter_set_user RETURNS STRING SONAME 'audit_log.so'; CREATE FUNCTION audit_log_filter_remove_user RETURNS STRING SONAME 'audit_log.so'; CREATE FUNCTION audit_log_filter_flush RETURNS STRING SONAME 'audit_log.so'; CREATE FUNCTION audit_log_read_bookmark RETURNS STRING SONAME 'audit_log.so'; CREATE FUNCTION audit_log_read RETURNS STRING SONAME 'audit_log.so'; CREATE FUNCTION audit_log_encryption_password_set RETURNS INTEGER SONAME 'audit_log.so'; CREATE FUNCTION audit_log_encryption_password_get RETURNS STRING SONAME 'audit_log.so'; CREATE FUNCTION audit_log_rotate RETURNS STRING SONAME 'audit_log.so'; SELECT audit_log_filter_flush() AS 'Result'; |
对应的这里还有一个卸载的脚本audit_log_filter_uninstall.sql […]
minio通过自己生成证书开启tls访问
minio通过自己生成证书开启tls访问
sysbench生成分区表数据的一些操作
人脑要是有个内存,天都能翻了 mysql有各种各样的表类型,基于此的各种变种更是层出不穷,为了应付这种变化,先前曾经基于sysbench1.0做了一些分区表数据生成lua,分享一些基础的函数组合,留个纪念。虽然改变表结构对tps测试会有影响,但是从数据构造来说还是很方便的,不过这里还有很多r/w的流程没有实现,先挂起吧
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 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
require("custom_luas/tdsqlv2/default/oltp_common") function array_range_value_int(table_size, partition_num, enable_maxvalue) local range = math.floor(table_size / partition_num) local min = 1 local max = range local pt_array = {} for i = 1, partition_num do if i == partition_num then if enable_maxvalue then max = "MAXVALUE" else max = table_size + 1 end pt_array[i] = max else pt_array[i] = max min = max + 1 max = min + range - 1 end end return pt_array end function array_range_value_date(partition_num, partition_func) local pt_array = {} if partition_func == nil or partition_func == "" then for i = 1, partition_num do if partition_func == nil or partition_func == "" or partition_func == "day" then pt_array[i] = os.date("%Y%m%d", os.time() + (i - 1) * 86400) end end end if partition_func == "day" then range = math.floor(31 / partition_num) for i = 1, partition_num do if i ~= partition_num then pt_array[i] = i * range else pt_array[i] = 32 end end end if partition_func == "month" then range = math.floor(12 / partition_num) for i = 1, partition_num do if i ~= partition_num then pt_array[i] = i * range else pt_array[i] = 13 end end end if partition_func == "year" then for i = 1, partition_num do pt_array[i] = os.date("%Y", os.time() + (i - 1) * 31536000) end end if partition_func == "tdsql_month" then year = tonumber(os.date("%Y", os.time())) month = tonumber(os.date("%m", os.time())) for i = 1, partition_num do pt_array[i] = string.format("%04d%02d", year, month) if month + 1 > 12 then year = year + 1 month = 1 else month = month + 1 end end end if partition_func == "tdsql_year" then year = tonumber(os.date("%Y", os.time())) for i = 1, partition_num do pt_array[i] = string.format("%04d", year) year = year + 1 end end return pt_array end function range_rand(pt_array, data_type, pt_func) if data_type == "int" then e = math.random(1, #pt_array) if e == 1 then return math.random(1, pt_array[e] - 1) else if pt_array[e] == "MAXVALUE" then return math.random(pt_array[e - 1], 9223372036854775807) end return math.random(pt_array[e - 1], pt_array[e] - 1) end end if data_type == "date" then if pt_func == nil or pt_func == "" then e = math.random(1, #pt_array) min = -90 if e ~= 1 then min = tonumber(pt_array[e-1]) - tonumber(pt_array[e]) end return getNewDate(pt_array[e], math.random(min, -1), "DAY") end if pt_func == "year" then e = math.random(1, #pt_array) min = -3 if e ~= 1 then min = tonumber(pt_array[e-1]) - tonumber(pt_array[e]) end return string.format("%04d%02d%02d",tonumber(pt_array[e]) + math.random(min, -1), math.random(01,12), math.random(01,28)) end if pt_func == "tdsql_month" then e = math.random(1, #pt_array) min = -3 if e ~= 1 then min = tonumber(pt_array[e-1]) - tonumber(pt_array[e]) end return getNewDate(string.format(pt_array[e].."01"), math.random(min, -1)*31, "DAY") end if pt_func == "tdsql_year" then e = math.random(1, #pt_array) min = -3 if e ~= 1 then min = tonumber(pt_array[e-1]) - tonumber(pt_array[e]) end return string.format("%04d%02d%02d", tonumber(pt_array[e]) + math.random(min, -1), math.random(01,12), math.random(01,28)) end end end function range_int(table_size, partition_num, enable_maxvalue) local sub_sql = "" local pt_array = array_range_value_int(table_size, partition_num, enable_maxvalue) for i = 1, partition_num do if string.len(sub_sql) == 0 then sub_sql = string.format("PARTITION p%d VALUES LESS THAN (%s)", i, pt_array[i]) else sub_sql = string.format("%s, PARTITION p%d VALUES LESS THAN (%s)", sub_sql, i, pt_array[i]) end end return sub_sql end function distributed_range_int(table_size, partition_num, enable_maxvalue) local sub_sql = "" local pt_array = array_range_value_int(table_size, partition_num, enable_maxvalue) for i = 1, partition_num do if string.len(sub_sql) == 0 then sub_sql = string.format("s%d VALUES LESS THAN (%s)", i, pt_array[i]) else sub_sql = string.format("%s, s%d VALUES LESS THAN (%s)", sub_sql, i, pt_array[i]) end end return sub_sql end function range_date(partition_num, partition_func) local sub_sql = "" local pt_array = array_range_value_date(partition_num, partition_func) for i = 1, partition_num do if string.len(sub_sql) == 0 then sub_sql = string.format("PARTITION p%d VALUES LESS THAN (%s)", i, pt_array[i]) else sub_sql = string.format("%s, PARTITION p%d VALUES LESS THAN (%s)", sub_sql, i, pt_array[i]) end end return sub_sql end function distributed_range_date(partition_num, partition_func) local sub_sql = "" local pt_array = array_range_value_date(partition_num, partition_func) for i = 1, partition_num do if string.len(sub_sql) == 0 then sub_sql = string.format("s%d VALUES LESS THAN (%s)", i, pt_array[i]) else sub_sql = string.format("%s, s%d VALUES LESS THAN (%s)", sub_sql, i, pt_array[i]) end end return sub_sql end function array_list_value_int(partition_num, partition_values_num) -- print(string.format("[debug]common.lua/array_list_value_int partition_num: %d, partition_values_num: %d",partition_num, partition_values_num)) local pt_array = {} for i = 1, partition_num do pt_array[i] = {} for j = 1, partition_values_num do while (true) do pt_array[i][j] = j + ((i - 1) * partition_values_num) if pt_array[i][j] ~= nill and string.len(pt_array[i][j]) ~= 0 then break end end end end return pt_array end function array_list_value_date(partition_num, partition_values_num, partition_func) print(string.format("[debug] partition_num: %d, partition_values_num: %d, partition_function: %s", partition_num, partition_values_num, partition_func)) local pt_array = {} --无日期函数 if partition_func == "" or partition_func == nil then for i = 1, partition_num do pt_array[i] = {} for j = 1, partition_values_num do pt_array[i][j] = os.date("%Y%m%d", os.time() + (j - 1) * 86400 + (i - 1) * partition_values_num * 86400) end end return pt_array end -- 只考虑mysql的day,tdsql的变种day模式暂时不考虑 if partition_func == "day" then local range = math.floor(31 / partition_num) local day_idx = 1 for i = 1, partition_num do local val_array = {} if i ~= partition_num then for j = 1, range do val_array[j] = day_idx day_idx = day_idx + 1 end else j = 1 while day_idx <= 31 do val_array[j] = day_idx day_idx = day_idx + 1 j = j + 1 end end pt_array[i] = val_array end return pt_array end if partition_func == "month" then local range = math.floor(12 / partition_num) local day_idx = 1 for i = 1, partition_num do local val_array = {} if i ~= partition_num then for j = 1, range do val_array[j] = day_idx day_idx = day_idx + 1 end else j = 1 while day_idx <= 12 do val_array[j] = day_idx day_idx = day_idx + 1 j = j + 1 end end pt_array[i] = val_array end return pt_array end if partition_func == "year" then for i = 1, partition_num do pt_array[i] = {} for j = 1, partition_values_num do while (true) do pt_array[i][j] = os.date("%Y", os.time() + (j - 1) * 31536000 + (i - 1) * partition_values_num * 31536000) if pt_array[i][j] ~= nill and string.len(pt_array[i][j]) ~= 0 then break end end end end return pt_array end if partition_func == "tdsql_month" then for i=1, partition_num do pt_array[i] = {} for j=1, partition_values_num do pt_array[i][j] = os.date("%Y%m", os.time() + (j - 1) * 86400 * 31 + (i - 1) * partition_values_num * 86400 * 31) end end return pt_array end if partition_func == "tdsql_year" then for i=1, partition_num do pt_array[i] = {} for j=1, partition_values_num do while (true) do pt_array[i][j] = os.date("%Y", os.time() + (j - 1) * 31536000 + (i - 1) * partition_values_num * 31536000) if pt_array[i][j] ~= nill and string.len(pt_array[i][j]) ~= 0 then break end end end end return pt_array end return pt_array end function list_int(partition_num, partition_values_num) local sub_sql = "" local pt_array = array_list_value_int(partition_num, partition_values_num) for i = 1, partition_num do if string.len(sub_sql) == 0 then sub_sql = string.format("PARTITION p%d VALUES IN (%s)", i, table.concat(pt_array[i], ",")) else sub_sql = string.format("%s, PARTITION p%d VALUES IN (%s)", sub_sql, i, table.concat(pt_array[i], ",")) end end return sub_sql end function distributed_list_int(partition_num, partition_values_num) local sub_sql = "" local pt_array = array_list_value_int(partition_num, partition_values_num) for i = 1, partition_num do if string.len(sub_sql) == 0 then sub_sql = string.format("s%d VALUES IN (%s)", i, table.concat(pt_array[i], ",")) else sub_sql = string.format("%s, s%d VALUES IN (%s)", sub_sql, i, table.concat(pt_array[i], ",")) end end return sub_sql end function group_partition_alias(partition_num, group_num) if group_num > partition_num then assert(false, "group_num must be equal or less than partition_num") end array_alis = {} alis_num = math.floor(partition_num/group_num) s_idx=1 for i = 1, group_num do array_alis[i] = {} j = 1 if i ~= group_num then while #array_alis[i] ~= alis_num do array_alis[i][j] = string.format("s%d", s_idx) s_idx = s_idx + 1 j = j + 1 end else while s_idx <= partition_num do array_alis[i][j] = string.format("s%d", s_idx) s_idx = s_idx + 1 j = j + 1 end end end return array_alis end function distributed_list_int_multipartition(partition_num, partition_values_num, group_num) local sub_sql = "" local pt_array = array_list_value_int(group_num, partition_values_num) local array_alis = group_partition_alias(partition_num, group_num) for i = 1, group_num do if string.len(sub_sql) == 0 then sub_sql = string.format("WHEN g%d VALUES IN (%s) THEN tdsql_subdistributed by hash(id) (%s)", i, table.concat(pt_array[i], ","), table.concat(array_alis[i], ",")) else sub_sql = string.format("%s, WHEN g%d VALUES IN (%s) THEN tdsql_subdistributed by hash(id) (%s)", sub_sql, i, table.concat(pt_array[i], ","), table.concat(array_alis[i], ",")) end end return sub_sql end function list_date(partition_num, partition_values_num, pt_func) local sub_sql = "" local pt_array = array_list_value_date(partition_num, partition_values_num, pt_func) --debug -- for i=1, partition_num do -- print(string.format("[debug]pt_array[%d]: %s",i, table.concat(pt_array[i], ","))) -- end for i = 1, partition_num do if string.len(sub_sql) == 0 then sub_sql = string.format("PARTITION p%d VALUES IN (%s)", i, table.concat(pt_array[i], ",")) else sub_sql = string.format("%s, PARTITION p%d VALUES IN (%s)", sub_sql, i, table.concat(pt_array[i], ",")) end -- sub_sql = sub_sql .. string.format("PARTITION p%d VALUES IN (%s)", i, table.concat(pt_array[i], ",")) -- if i ~= partition_num then -- sub_sql = sub_sql .. "," -- end end return sub_sql end function distributed_list_date(partition_num, partition_values_num, partition_func) local sub_sql = "" local pt_array = array_list_value_date(partition_num, partition_values_num, partition_func) for i = 1, partition_num do if string.len(sub_sql) == 0 then sub_sql = string.format("s%d VALUES IN (%s)", i, table.concat(pt_array[i], ",")) else sub_sql = string.format("%s, s%d VALUES IN (%s)", sub_sql, i, table.concat(pt_array[i], ",")) end end return sub_sql end function distributed_list_date_multipartition(partition_num, partition_values_num, group_num) local sub_sql = "" local pt_array = array_list_value_date(group_num, partition_values_num) local array_alis = group_partition_alias(partition_num, group_num) for i = 1, group_num do if string.len(sub_sql) == 0 then sub_sql = string.format("WHEN g%d VALUES IN (%s) THEN tdsql_subdistributed by hash(id) (%s)", i, table.concat(pt_array[i], ","), table.concat(array_alis[i], ",")) else sub_sql = string.format("%s, WHEN g%d VALUES IN (%s) THEN tdsql_subdistributed by hash(id) (%s)", sub_sql, i, table.concat(pt_array[i], ","), table.concat(array_alis[i], ",")) end end return sub_sql end function getNewDate(srcDateTime, interval, dateUnit) --从日期字符串中截取出年月日时分秒 local Y = string.sub(srcDateTime,1,4) local M = string.sub(srcDateTime,5,6) local D = string.sub(srcDateTime,7,8) local H = string.sub(srcDateTime,9,10) local MM = string.sub(srcDateTime,11,12) local SS = string.sub(srcDateTime,13,14) --把日期时间字符串转换成对应的日期时间 local dt1 = os.time{year=Y, month=M, day=D, hour=H,min=MM,sec=SS} --根据时间单位和偏移量得到具体的偏移数据 local ofset=0 if dateUnit =='DAY' then ofset = 60 *60 * 24 * interval elseif dateUnit == 'HOUR' then ofset = 60 *60 * interval elseif dateUnit == 'MINUTE' then ofset = 60 * interval elseif dateUnit == 'SECOND' then ofset = interval end --指定的时间+时间偏移量 local newTime = os.date("%Y%m%d", dt1 + tonumber(ofset)) return newTime end |
[…]