利用iperf测试服务器之间的网络带宽

1:下载安装(以ubuntu为例)

sudo wget -O /usr/lib/libiperf.so.0 https://iperf.fr/download/ubuntu/libiperf.so.0_3.1.3
sudo wget -O /usr/bin/iperf3 https://iperf.fr/download/ubuntu/iperf3_3.1.3
sudo chmod +x /usr/bin/iperf3

2:测试
A服务器执行(内网IP为172.26.22.201)
iperf3 -s
B服务器上执行
iperf3 -s 172.26.22.201
结果为:

Connecting to host 172.26.22.201, port 5201
[  4] local 172.26.29.32 port 53560 connected to 172.26.22.201 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec   117 MBytes   984 Mbits/sec   42    454 KBytes       
[  4]   1.00-2.00   sec   112 MBytes   939 Mbits/sec   34    315 KBytes       
[  4]   2.00-3.00   sec   115 MBytes   965 Mbits/sec   38    437 KBytes       
[  4]   3.00-4.00   sec   111 MBytes   931 Mbits/sec   28    341 KBytes       
[  4]   4.00-5.00   sec   115 MBytes   965 Mbits/sec   36    332 KBytes       
[  4]   5.00-6.00   sec   114 MBytes   960 Mbits/sec   29    428 KBytes       
[  4]   6.00-7.00   sec   115 MBytes   963 Mbits/sec   38    385 KBytes       
[  4]   7.00-8.00   sec   115 MBytes   963 Mbits/sec   39    358 KBytes       
[  4]   8.00-9.00   sec   113 MBytes   950 Mbits/sec   38    306 KBytes       
[  4]   9.00-10.00  sec   115 MBytes   966 Mbits/sec   37    393 KBytes       
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec  1.12 GBytes   959 Mbits/sec  359             sender
[  4]   0.00-10.00  sec  1.11 GBytes   957 Mbits/sec                  receiver

另外,如果用外网IP,速率会慢很多

参考:
https://iperf.fr/iperf-download.php

springboot常见问题

1:springboot定时任务不执行
原因可能为:
1)没添加@EnableScheduling或者定时任务类没添加@Component
2)定时任务类所在的package不对,不在启动类的的子包下

ELK常见问题

1:kibana无法外网访问
设置server.host = "0.0.0.0"
2:kibana7.x首次无法启动
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'unsafe-eval' 'nonce-SK5LdJc4MkeDocgq'". Either the 'unsafe-inline' keyword, a hash ('sha256-SHHSeLc0bp6xt4BoVVyUy+3IbVqp3ujLaR+s+kSP5UI='), or a nonce ('nonce-...') is required to enable inline execution.
设置logging.verbose: true
重启后文件解决
2:elasticsearch7.x启动报错
修改了network.host为0.0.0.0怎么都启动不起来,到/var/log/elasticsearch/查看错误日志如下

the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

解决步骤如下:(以ubuntu16.04为例)

vi /etc/security/limits.conf
添加:
* soft nofile 65534
* hard nofile 65534
root soft nofile 65534
root hard nofile 65534
重启电脑
vi  /etc/sysctl.conf
vm.max_map_count=262144
保存退出,sysctl  -p  
修改elasticsearch.yml
cluster.initial_master_nodes: ["node-1"]
 curl -H "Content-Type: application/json" -XPUT localhost:9200/_settings -d '{ "index" : { "refresh_interval" : -1, "number_of_replicas" : 0 } }'

3:删除filebeat对文件的记录
/var/lib/filebeat/registry
删除这个里面的东西重启即可

相关讨论:https://discuss.elastic.co/t/problems-with-access-to-elasticsearch-form-outside-machine/172450

4:logstash进程杀不掉
initctl stop logstash

jackson报错 Unrecognized field xxx

有个哥们写的比较清楚了,就直接转过来了,原文为:https://www.jianshu.com/p/785d7a043e4c
问题描述
使用Jackson的ObjectMapper将json字符串转换为对象时报错:

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "sex" (class dev.wj.jacksonunrecognizedfielddemo.entity.User), not marked as ignorable (2 known properties: "name", "age"])
 at [Source: {"age":18, "name":"wj", "sex":1}; line: 1, column: 32] (through reference chain: dev.wj.jacksonunrecognizedfielddemo.entity.User["sex"])

问题分析
错误信息提示,未识别字段“sex”。
引起该问题的原因是在使用ObjectMapper将json字符串转换为对象时,被映射的对象中没有和json串中的字段对应。
举例
首先先建立User类,包含age和name两个字段。

public class User {

    private Integer age;

    private String name;

}

假设程序调用了别人的接口,返回一个描述user信息的json字符串:

  {
    "age": 18,
    "name": "wj",
    "sex": "男"
  }

该json串中包含了age、name、和sex三个字段。
此时如果将该字符串映射为User对象即会报出Unrecognized field xxx错误。

@RunWith(SpringRunner.class)
@SpringBootTest
public class JacksonTest {

    @Test
    public void jacksonTest() {

        String json = "{\"age\": 18, \"name\": \"wj\", \"sex\": \"男\"}";

        ObjectMapper objectMapper = new ObjectMapper();

        User user = null;
        try {
            user = objectMapper.readValue(json, User.class);
        } catch (IOException e) {
            e.printStackTrace();
        }

        System.out.println(user.toString());
    }
}

原因就是json串中的sex字段在User类中没有对应的字段映射。
解决方案
如果json中包含的字段都是有用的,那么映射类应包含所有json串中包含的字段。如在User类中添加private String sex字段即可。
如果json串中的字段不完全需要映射到实体类中,则可在实体类上加上@JsonIgnoreProperties(ignoreUnknown = true)注解,时jackson在转换时忽略不能映射的字段。

eclipse安装PMD,checkstyle,findbugs

PMD地址为:
https://dl.bintray.com/pmd/pmd-eclipse-plugin/updates/

checkstyle:
https://sourceforge.net/projects/eclipse-cs/
如果无法在线安装,可以下载zip包安装

findbugs:
http://findbugs.cs.umd.edu/eclipse/