MySQL-8.0.24主从环境搭建

docker搭建创建MySQL容器

master主库
1
docker run -d -p 3316:3306 -e MYSQL_ROOT_PASSWORD=password -e TZ=Asia/Shanghai --name mysql-8.0.24-master mysql:8.0.24 --lower-case-table-names=1 --default-authentication-plugin=mysql_native_password
阅读更多

Flink CDC入门

查看Mysql是否开启bin-log

1
SHOW VARIABLES LIKE '%log_bin%';

如下表格才是开启bin-log的,如果未开启请自行百度开启

Variable_nameValue
log_binNO

Elasticsearch插件集成

简繁通检

- 安装的插件一版本大多数要和es版本保持一致

简繁体转化
1
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-stconvert/releases/download/v7.6.2/elasticsearch-analysis-stconvert-7.6.2.zip
阅读更多

Docker搭建MQTT服务器

1
docker run -p 18083:18083 -p 8883:8883 -p 1883:1883 -p 8083:8083 -p 8084:8084 --name=mqtt --restart=always -d emqx:5.0.20
1
docker run -it --name=mosquitto --privileged  -p 1883:1883 -p 9001:9001 -d  eclipse-mosquitto:openssl

CentOS7中文乱码

系统中文乱码

1
2
3
4
5
6
7
8
9
10
11
12
[root@iZqryz7xfamf9rZ categories]# locale -a |grep "zh_CN"
zh_CN
zh_CN.gb18030
zh_CN.gb2312
zh_CN.gbk
zh_CN.utf8
[root@iZqryz7xfamf9rZ categories]# vim /etc/locale.conf
[root@iZqryz7xfamf9rZ categories]# cat /etc/locale.conf
LANG=zh_CN
[root@iZqryz7xfamf9rZ categories]# localectl set-locale LANG=zh_CN
[root@iZqryz7xfamf9rZ categories]# yum install convmv
[root@iZqryz7xfamf9rZ categories]# convmv -f gbk -t utf-8 -r --notest /

PageHelper分页

经过试验,存在问题!!!

PageHelper单表查询分页

1
2
3
4
5
public PageInfo findByPage(PageVO page) {
PageHelper.startPage(page.getPageNum(), page.getPageSize());
List<Project> all = projectMapper.findByPage();//分页SQL方法
return new PageInfo<>(all);//返回
}

多表关联查询分页

多表关联查询分页可能会存在分页数量不正确的情况,通过如下方式解决
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public PageInfo findAll(PageVO page) {
PageHelper.startPage(page.getPageNum(), page.getPageSize()).doCount(
() -> projectMapper.doCount() //自定义查询总数量方法,这里的返回值要求是long
);
List<Project> all = projectMapper.findAll();
return new PageInfo<>(all);
}

public PageInfo findByPage(PageVO page) {
PageHelper.startPage(page.getPageNum(), page.getPageSize()).doCount(new ISelect() {
@Override
public void doSelect() {
logn count = projectMapper.doCount();//自定义查询总数量方法,这里的返回值要求是long
}
});
List<Project> all = projectMapper.findByPage();
return new PageInfo<>(all);
}
projectMapper
1
2
@Select("SELECT COUNT(id) FROM `project`")
long doCount();

SpringBoot整合Docker自动化部署

配置pom.xml

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
<!--使用docker-maven-plugin插件-->
<build>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.0.0</version>

<configuration>
<!--指定远程 docker api地址-->
<dockerHost>http://47.99.143.64:2375</dockerHost>

<!--指定生成的镜像名-->
<imageName>${project.artifactId}</imageName>

<!-- 指定 Dockerfile 路径 ${project.basedir}:项目根路径下-->
<dockerDirectory>${project.basedir}</dockerDirectory>

<!-- 这里是复制 jar 包到 docker 容器指定目录配置 -->
<resources>
<resource>
<targetPath>/</targetPath>
<!--jar 包所在的路径 此处配置的 即对应 target 目录-->
<directory>${project.build.directory}</directory>
<!-- 需要包含的 jar包 ,这里对应的是 Dockerfile中添加的文件名 -->
<include>${project.build.finalName}.jar</include>
</resource>
</resources>

<!-- 以下两行是为了docker push到DockerHub使用的。 -->
<!-- <serverId>docker-hub</serverId>-->
<!-- <registryUrl>https://index.docker.io/v1</registryUrl>-->
</configuration>
</plugin>
</plugins>
</build>

Java小工具

统计系统磁盘, 不需要其他依赖

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
public static void main(String[] args) throws IOException {
DecimalFormat df = new DecimalFormat("#0.00");
long diskSize = 0;
long diskUsed = 0;
File[] disks = File.listRoots();
for (File file : disks) {
// 获取盘符
System.out.print(file.getCanonicalPath() + " ");
// 获取总容量
long totalSpace = file.getTotalSpace();
diskSize += totalSpace;
// 获取剩余容量
long usableSpace = file.getUsableSpace();
// 获取已经使用的容量
long freeSpace = totalSpace - usableSpace;
diskUsed += freeSpace;
// 获取使用率
float useRate = (float)((freeSpace * 1.0 / totalSpace) * 100);
System.out.print("总容量: " + totalSpace / 1024 / 1024 / 1024 + "GB ");
System.out.print("已经使用: " + freeSpace / 1024 / 1024 / 1024 + "GB ");
System.out.print("剩余容量: " + usableSpace / 1024 / 1024 / 1024 + "GB ");
System.out.println("使用率: " + Double.parseDouble(df.format(useRate)) + "% ");
}
float useRate = (float)((diskUsed * 1.0 / diskSize) * 100);
System.out.println("所有磁盘总容量:"+diskSize / 1024 / 1024 / 1024 + "GB ");
System.out.println("所有磁盘已经使用:"+diskUsed / 1024 / 1024 / 1024 + "GB ");
System.out.println("所有磁盘使用率:"+ Double.parseDouble(df.format(useRate))+"%");
System.out.println(new SystemDataController().findAll());
}

统计CPU和内存, 需要用到fastjson2

1
2
3
4
5
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.13</version>
</dependency>
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
public static void main(String[] args) {
long GB = 1024 * 1024 * 1024;
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
String osJson = JSON.toJSONString(operatingSystemMXBean);
System.out.println("osJson is " + osJson);
JSONObject jsonObject = JSON.parseObject(osJson);
double processCpuLoad = jsonObject.getDouble("processCpuLoad") * 100;
double systemCpuLoad = jsonObject.getDouble("systemCpuLoad") * 100;
Long totalPhysicalMemorySize = jsonObject.getLong("totalPhysicalMemorySize");
Long freePhysicalMemorySize = jsonObject.getLong("freePhysicalMemorySize");
double totalMemory = 1.0 * totalPhysicalMemorySize / GB;
double freeMemory = 1.0 * freePhysicalMemorySize / GB;
double memoryUseRatio = 1.0 * (totalPhysicalMemorySize - freePhysicalMemorySize) / totalPhysicalMemorySize * 100;

StringBuilder result = new StringBuilder();
result.append("系统CPU占用率: ")
.append(twoDecimal(systemCpuLoad))
.append("%,内存占用率:")
.append(twoDecimal(memoryUseRatio))
.append("%,系统总内存:")
.append(twoDecimal(totalMemory))
.append("GB,系统剩余内存:")
.append(twoDecimal(freeMemory))
.append("GB,该进程占用CPU:")
.append(twoDecimal(processCpuLoad))
.append("%");
System.out.println(result.toString());
}
public static double twoDecimal(double doubleValue) {
BigDecimal bigDecimal = new BigDecimal(doubleValue).setScale(2, RoundingMode.HALF_UP);
return bigDecimal.doubleValue();
}

java递归树并分页

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
/**
* 分页
* @param idList 要查询的条件
* @param pageNum
* @param pageSize
* @return
*/
private PageInfo result(List<Object> idList, int pageNum, int pageSize){
List<BaseMenuVO> result = selectTree("0", menuMapper.findByIds(idList));
List<BaseMenuVO> baseMenuVOS = result
.stream().skip((pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
PageInfo pageInfo = new PageInfo(result);
pageInfo.setTotal(result.size());
pageInfo.setList(baseMenuVOS);
pageInfo.setPageNum(pageNum);
pageInfo.setPageSize(pageSize);
return pageInfo;
}

/**
* 生成树
* @param parentId 父级id
* @param treeEntityList 数据源
* @return
*/
private List<BaseMenuVO> selectTree(String parentId, List<BaseMenuVO> treeEntityList) {
List<BaseMenuVO> collect = treeEntityList.stream()
.filter(treeEntity -> treeEntity.getParentId().equals(parentId))
.peek(treeEntity -> treeEntity.setChildren(selectTree(treeEntity.getId(), treeEntityList)))
.collect(Collectors.toList());
return collect;
}

求两个数组的差集、补集

1
2
3
4
5
List<String> deleteList =
list1.stream().filter(e -> !list2.contains(e)).collect(Collectors.toList());

List<String> addList =
list2.stream().filter(e -> !list1.contains(e)).collect(Collectors.toList());