tcp、http的一些知识整理

前言

tcp、http的一些知识整理

1、含义

1.1 序列号seq

占4个字节,用来标记数据段的顺序,TCP把连接中发送的所有数据字节都编上一个序号,第一个字节的编号由本地随机产生;给字节编上序号后,就给每一个报文段指派一个序号;序列号seq就是这个报文段中的第一个字节的数据编号。

1.2 确认号ack

占4个字节,期待收到对方下一个报文段的第一个数据字节的序号;序列号表示报文段携带数据的第一个字节的编号;而确认号指的是期望接收到下一个字节的编号;因此当前报文段最后一个字节的编号+1即为确认号。

……

阅读全文

python工具-移除照片或视频背景

前言

BackgroundRemover是一个命令行工具,用于从视频 和图像中删除背景

1、依赖

Requirements
python <= 3.6
python3.6-dev #or what ever version of python you using
torch and torchvision stable version https://pytorch.org
ffmpeg 4.4+

1
2
3
pip install python3.6-dev
pip install ffmpeg
pip install torch

2、安装

1
pip install backgroundremover

3、下载模型并设置

如果不提前下载模型的话,在首次执行的时候会自动下载,但是需要从 google 网盘下载,因此需要有翻墙能力。
如果手工下载可以参考下面地址:
1、https://github.com/xuebinqin/U-2-Net#usage-for-salient-object-detection,参考章节"Download the u2net_portrait.pth"
2、https://pan.baidu.com/s/1FbUIBJsEua7G1vYo06lSmg 提取码: o0uu
3、https://drive.google.com/u/0/uc?id=1rbSTGKAE-MTxBYHd-51l2hMOQPT_7EPy&export=download

……

阅读全文

springboot的devTools热部署

前言

springboot利用devtools实现热部署

1、application.yml

1
2
3
4
5
6
7
8
9
spring:
    devtools:
        restart:
            #热部署生效
          enabled: true
            #设置重启的目录
            #additional-paths: src/main/java
            #classpath目录下的WEB-INF文件夹内容修改不重启
          exclude: WEB-INF/**

设置WEB-INF下的jsp修改不需要重启。

2、pom.xml

1
2
3
4
5
6
7
8
<!--devtools热部署-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
    <!-- optional=true,依赖不会传递,该项目依赖devtools;之后依赖该项目的项目如果想要使用devtools,需要重新引入 -->
    <scope>true</scope>
</dependency>
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
      <fork>true</fork>
    </configuration>
    <dependencies>
      <!-- spring热部署-->
      <!-- https://mvnrepository.com/artifact/org.springframework/springloaded -->
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>springloaded</artifactId>
        <version>1.2.6.RELEASE</version>
      </dependency>
    </dependencies>
</plugin>

3、idea设置

1、File-Settings-Compiler-Build Project automatically
2、ctrl + shift + alt + /,选择Registry,勾上 Compiler autoMake allow when app running

……

阅读全文

nginx参数介绍

前言

nginx的反向代理和当做前端容器使用比较广泛,有一些参数详情搜集整理下

1、Nginx运行工作进程数量

Nginx运行工作进程个数一般设置CPU的核心或者核心数x2。
如果不了解cpu的核数,可以top命令之后按1看出来,也可以查看/proc/cpuinfo文件

1
grep ^processor /proc/cpuinfo | wc -l 
1
2
3
4
5
6
7
8
9
[root@lx~]# vi /usr/local/nginx1.10/conf/nginx.conf
worker_processes 4;
[root@lx~]# /usr/local/nginx1.10/sbin/nginx-s reload
[root@lx~]# ps -aux | grep nginx |grep -v grep
root 9834 0.0 0.0 47556 1948 ?     Ss 22:36 0:00 nginx: master processnginx
www 10135 0.0 0.0 50088 2004 ?       S   22:58 0:00 nginx: worker process
www 10136 0.0 0.0 50088 2004 ?       S   22:58 0:00 nginx: worker process
www 10137 0.0 0.0 50088 2004 ?       S   22:58 0:00 nginx: worker process
www 10138 0.0 0.0 50088 2004 ?       S   22:58 0:00 nginx: worker process

2、Nginx运行CPU亲和力

比如4核配置:

……

阅读全文

linux的一些细节点-不定期补充

前言

linux的一些小细节记录

1、tmp目录、var目录自动清理

tmp下的文件或目录长时间没有更新或者改动的话会被系统定期时间,配置参考如下:

1
vi /usr/lib/tmpfiles.d/tmp.conf
1
2
3
4
5
6
7
8
9
# Clear tmp directories separately, to make them easier to override  
v /tmp 1777 root root 90d  
v /var/tmp 1777 root root 90d  

# Exclude namespace mountpoints created with PrivateTmp=yes  
x /tmp/systemd-private-%b-*  
X /tmp/systemd-private-%b-*/tmp  
x /var/tmp/systemd-private-%b-*  
X /var/tmp/systemd-private-%b-*/tmp

2、tcp连接数统计

1
2
3
4
5
6
7
netstat -ant|awk '/^tcp/ {++S[$NF]} END {for(a in S) print (a,S[a])}'

TIME_WAIT 1
FIN_WAIT2 1
ESTABLISHED 34
LAST_ACK 1
LISTEN 23

3、wget下载提示ssl错

1
wget --no-check-certificate -O brutexss.zip "http://files.cnblogs.com/files/Pitcoft/Brutexss(%E6%B1%89%E5%8C%96%E6%94%B9%E8%BF%9B).zip"

4、wget抓取网站

1
2
3
wget -m -e robots=off https://www.baidu.com
-m 是克隆整个网站
-e robots=off 是让wget忽视robots.txt

5、shell批量注释

<<'COMMENT'
...

COMMENT  

举例如下:

……

阅读全文

被同事误删表找回丢失的数据

有些不靠谱的同事真的很误事,运维了几年的系统从来没出过误删表数据的事件,3月14日下午突然被同事误删了订单表全量数据,查询表返回0 rows,突然大脑一片空白,心想完了完了,最重要的表数据全部被清理了,虽然有每日凌晨5点的全量备份,但是截止下午的数据怎么找回?从来没碰到过误删事件,也从来没处理过数据恢复。。。

一、先挽救每日备份的数据

找到每日全量备份的数据,把订单表还原到测试库,然后单独把订单表重新备份,针对误删的表进行全量恢复 采用的工具是mydumper,非mysql官方的mydump 心想:好在有每日凌晨5点的全量备份,虽然在自己手里,从开发了每日全量备份脚本并配置定时任务每天执行,从来没派上用场,也希望不会派上用场,但是良好的备份意识还是挽救了90%的数据。 半小时左右,90%的数据恢复,然后把问题上报。

……

阅读全文

JDK1.8.0.161版本bug定位

前言

好好运行的系统,突然故障,无意间根据错误信息查找,竟然是jdk的bug,描述下曲折的定位过程。

1、错误日志

有个老系统有使用到soap接口,采用CXF结合接口文件wsdl自动生成的接口开发的,突然在3月2日(后续日志定位才发现真正故障的时间)无法正常工作,但是实际发现时间已经到了3月6日了,直接查看日志文件,报错“组装saop报文头异常:Entity References are not allowed in SOAP documents”

……

阅读全文

容灾概念介绍

前言

容灾的一些名词、概念介绍

1、介绍

容灾恢复能力的关键指标

RPO(Recovery Point Obejective,恢复点目标)

是指业务系统所允许的在灾难过程中的最大数据丢失量,用来衡量容灾系统的数据冗余备份能力。

RTO(Recovery Time Objective,恢复时间目标)

是指信息系统从灾难状态恢复到可运行状态所需的时间,用来衡量容灾系统的业务恢复能力。 我国的国家标准《GB20988-2007-T 信息安全技术信息系统灾难恢复规范》对灾备数据中心根据RPO与RTO两项指标分成了6个相应的等级,如下所示:

……

阅读全文

手机端调测H5页面神器-vConsole

前言

手机端调测H5页面是比较麻烦的,需要借助腾讯的vConsole神器
下载地址: https://github.com/Tencent/vConsole.git

1、导入引用

1
2
3
4
5
6
<script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script>
<script>
  // 初始化
  var vConsole = new VConsole();
  console.log('VConsole is cool');
</script>

如下图:

2、属性

vConsole.version

当前 vConsole 的版本号。

  • 只读
  • 类型:string

例子:

1
vConsole.version // => "3.11.0"

vConsole.option

配置项。

  • 可写
  • 类型:object
键名 类型 可选 默认值 描述
defaultPlugins Array true [‘system’, ’network’, ’element’, ‘storage’] 需要自动初始化并加载的内置插件。
onReady Function true 回调方法,当 vConsole 完成初始化并加载完内置插件后触发。
onClearLog Function true 回调方法,点击 Log 或 System 面板的 “Clear” 按钮后出发。
maxLogNumber Number true 1000 超出数量上限的日志会被自动清除。
maxNetworkNumber Number true 1000 超出数量上限的请求记录会被自动清除。
disableLogScrolling Boolean true 若为 false,有新日志时面板将不会自动滚动到底部。
theme String true ’light’ 主题颜色,可选值为 ’light'
target String, HTMLElement true document.documentElement 挂载到的节点,可为 HTMLElement 或 CSS selector。

例子:

……

阅读全文

mongodb安装后的初始化操作

前言

mongodb安装成功后的初始化操作,安装步骤比较简单略过不讲

1、启动

1
./mongobd -f /etc/mongodb.conf

2、进入命令行

1
./mongo 

3、创建超级管理账号

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
use admin

db.createUser({user:"adminuser",pwd:"12345678",roles:["userAdminAnyDatabase"]})

## 4、用超级管理账号创建业务账号
db.auth('adminuser', '12345678')

use testdb

db.createUser({user:"testuser",pwd:"12345678",roles: [{role:"readWrite", db:"testdb"}]})

5、conf文件demo,yaml格式,注意空格

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
systemLog:
    destination: file
    logAppend: true
    path: /usr/local/mongodb/logs/mongodb.log

storage:
    dbPath: /usr/local/mongodb/data/db
    journal:
        enabled: true

processManagement:
    fork:        
    pidFilePath: /var/run/mongodb/mongod.pid
    timeZoneInfo: /usr/share/zoneinfo

net:
    port: 27017
    bindIp: 0.0.0.0

security:
    authorization: enabled

6、参数解读:

 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
systemLog:
  destination: file//指定是一个文件
  path: /data/logs/mongod.log//日志存放位置
  logAppend: true//产生日志内容追加到文件
#  quiet: true//在quite模式下会限制输出信息
#  timeStampFormat: iso8601-utc //默认是iso8601-local,日志信息中还有其他时间戳格式:ctime,iso8601-utc,iso8601-local

processManagement:
  fork: true//以守护进程的方式运行MongoDB,创建服务器进程
  pidFilePath: "/data/mongo-data/mongod.pid"//pid文件路径
net:
# bindIp: 192.168.33.131//绑定ip地址访问mongodb,多个ip逗号分隔
  port: 27017//端口
  maxIncomingConnections:10000//默认65535,mongodb实例接受的最多连接数,如果高于操作系统接受的最大线程数,设置无效。
#  http:
#    enabled: true//http端口最好关闭
#RESTInterfaceEnabled: false//即使http接口选项关闭,如果这个选项打开后会有更多的不安全因素

storage:
  dbPath: "/data/mongo-data"//数据文件存放路径
  engine: wiredTiger//数据引擎
  wiredTiger:
    engineConfig://wt引擎配置
      cacheSizeGB: 1//看服务器情况来进行设置
      directoryForIndexes: true//索引是否按数据库名进行单独存储
    collectionConfig:
      blockCompressor: zlib//压缩配置
    indexConfig:
      prefixCompression: true//索引配置
  journal:
    enabled: true//记录操作日志,防止数据丢失。
  directoryPerDB: true//指定存储每个数据库文件到单独的数据目录。如果在一个已存在的系统使用该选项,需要事先把存在的数据文件移动到目录。
operationProfiling:
  slowOpThresholdMs: 100 //指定慢查询时间,单位毫秒,如果打开功能,则向system.profile集合写入数据
  mode: "slowOp"//off、slowOp、all,分别对应关闭,仅打开慢查询,记录所有操作。
security:
  keyFile: "/data/mongodb-keyfile"//指定分片集或副本集成员之间身份验证的key文件存储位置
  clusterAuthMode: "keyFile"//集群认证模式,默认是keyFile
  authorization: "disabled"//访问数据库和进行操作的用户角色认证

7、常见操作

命令 含义
show dbs 显示数据库列表
show collections 显示当前数据库中的集合(类似关系数据库中的表)
show users 显示用户
use dbname 切换当前数据库,这和MS-SQL里面的意思一样
db.help() 显示数据库操作命令,里面有很多的命令

8、聚集集合操作

8.1、查询所有记录

1
2
db.userInfo.find();
相当于:select* from userInfo;

8.2、查询去掉后的当前聚集集合中的某列的重复数据

1
2
3
db.userInfo.distinct("name");
会过滤掉name中的相同数据
相当于:select distinct name from userInfo;

8.3、查询age = 22的记录

1
2
db.userInfo.find({"age": 22});
相当于: select * from userInfo where age = 22;

8.4、查询age > 22的记录

1
2
db.userInfo.find({age: {$gt: 22}});
相当于:select * from userInfo where age >22;

8.5、查询age < 22的记录

1
2
db.userInfo.find({age: {$lt: 22}});
相当于:select * from userInfo where age <22;

8.6、查询age >= 25的记录

1
2
db.userInfo.find({age: {$gte: 25}});
相当于:select * from userInfo where age >= 25;

8.7、查询age <= 25的记录

1
db.userInfo.find({age: {$lte: 25}});

8.8、查询age >= 23 并且 age <= 26

1
db.userInfo.find({age: {$gte: 23, $lte: 26}});

8.9、查询name中包含 mongo的数据

1
2
3
db.userInfo.find({name: /mongo/});
//相当于%%
select * from userInfo where name like ‘%mongo%';

8.10、查询name中以mongo开头的

1
2
db.userInfo.find({name: /^mongo/});
select * from userInfo where name like ‘mongo%';

8.11、查询指定列name、age数据

1
2
db.userInfo.find({}, {name: 1, age: 1});
相当于:select name, age from userInfo;

当然name也可以用true或false,当用true的情况下河name:1效果一样,如果用false就是排除name,显示name以外的列信息。

……

阅读全文

最近文章

分类

标签

其它