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());

Python入门

修改pip默认下载地址

  • 1.打开cmd,找到Python安装路径下的/lib/site.py
    执行此命令第一行就是site.py文件的位置
    1
    python -m site -help 
  • 2.修改配置,找到被注释代码进行修改,注释的为原配置,新配置未注释,新文件夹需要独立创建,否则修改不会生效
    1
    2
    3
    4
    # USER_SITE = None
    # USER_BASE = None
    USER_SITE = "E:/Repository/pip/lib/site-packages"
    USER_BASE = "E:/Repository/pip/Scripts"
  • 3.检测是否修改成功
    1
    pip install numpy

Nginx输入用户名密码访问

前期操作

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
#查看运行容器的ID
docker ps

#进入nginx容器
docker exec -it 容器ID /bin/bash

#容器内部操作
#更新软件源
apt-get update

#安装apache2-utils
apt-get install apache2-utils

#创建用户名
htpasswd -c /etc/nginx/passwd.db 用户名

#输入密码(自动弹出)
New password:
Re-type new password:

#查看用户和密码
cat /etc/nginx/passwd.db

#退出容器
exit
阅读更多

Kibana入门

安装Elasticsearch请看Docker入门或者Elasticsearch安装

安装Kibana请看Docker入门

IK分词器安装请看Docker入门

阅读更多

Kibana入门

FIND_IN_SET()函数无法识别

方案一(有效果,但不多,mybatis中会出问题)

解决方案
1
2
3
4
5
6
7
CREATE OR REPLACE  FUNCTION find_in_set(str text, strlist text) RETURNS int
AS
DECLARE b1 VARCHAR;
begin
b1:=array_position(string_to_array($2, ','),$1);
RETURN b1;
end;
测试
1
SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, ancestors) 

方案二,有效

1
2
SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, ancestors)
SELECT t.dept_id FROM sys_dept t WHERE position(#{deptId} in ancestors)