Eli's Blog

1. TCP

a

TCP 是面向连接、可靠的、基于字节流传输层通信协议。

  • 面向连接:一对一的连接。不像 UDP 可以同时向多个主机发送消息。
  • 可靠的:网络链路中出现变化,TCP 可以保证一个报文一定能够到达指定端。

1. HTTP

1.1 特性

  • 构建在TCP上的应用层协议
  • 无连接无状态

1.2 状态码

  • 200 OK
  • 301 Moved Permanently 永久重定向,后续请求直接发往新地址
  • 302 Moved Temporarily 临时重定向
  • 304 Not Modified 文件未修改,直接使用缓存文件
  • 400 Bad Request 客户端请求有语法错误
  • 401 Unauthorized 请求未经授权
  • 403 Forbidden 认证通过,但无权限访问资源
  • 404 Not Found 请求的资源不存在
  • 405 Method Not Allowed
  • 500 Internal Server Error
  • 502 Bad Gateway 与upstream建立了连接,但响应超时。可能原因:后端代码执行超时、数据库响应慢等 (received an invalid response from the upstream server)
  • 503 Service Unavailable 服务器当前不能够处理客户端的请求,在一段时间之后,服务器可能会恢复正常。(The server cannot handle the request, because it is overloaded or down for maintenance, generally this is temporary state.)
  • 504 Gateway Time-out 完全无法与upstream建立连接,一般是nginx配置错误 (did not receive a timely response from the upstream server)

1. 负载均衡

1.1 SLB

SLB: Server Load Balance

  • 通过设置虚拟服务地址(IP),将位于同一区域(Region)的多台云服务器(Elastic Compute Service,ECS)的资源虚拟成一个高性能、高可用的应用服务池;再根据应用指定的方式,将来自客户端的网络请求分发到云服务器池中

  • SLB服务会检查云服务器池中ECS的健康状态,自动隔离异常状态的ECS,从而解决了单台ECS的单点问题,同时提高了应用的整体服务能力

负载均衡算法:

  • 轮询 (Round Robin)

  • 最小连接 (Leaster Connections): 优先选择连接数最小的服务器

  • Source: 根据请求源IP的hash值来选择要转发的服务器,保证特定用户连接到相同服务器

1. buffer和cache

buffer强调写,cache强调读,读写都带的时候,几乎无差别。buffer另外也有排队等待被处理的意思,cache基本没有。

2. bash配置文件

2.1 全局配置

1
2
3
/etc/profile
/etc/profile.d/*.sh
/etc/bashrc

2.2 用户配置

1
2
~/.bash_profile, ~/.bash_login, ~/.profile(同时存在时,依次读取)
~/.bashrc

1. Ubuntu

1.1 修改IP

Ubuntu 16, 18:

1
2
3
4
5
6
7
8
9
10
sudo vi /etc/network/interfaces
auto ens33
iface ens33 inet static
address 192.168.80.20
netmask 255.255.255.0
gateway 192.168.80.2
dns-nameservers 8.8.8.8

sudo ip addr flush ens33
sudo systemctl restart networking

1. select

select最早于1983年出现在4.2BSD中,它通过一个select()系统调用来监视多个文件描述符的数组,当select()返回后,该数组中就绪的文件描述符便会被内核修改标志位,使得进程可以获得这些文件描述符从而进行后续的读写操作。

1
2
3
4
5
6
7
while true {
select(streams[])
for i in streams[] {
if i has data
read until unavailable
}
}