Levon's Blog

微信: L6241425

1. golang 实现HTTPS Web Server

  • 生成私钥和证书
1
2
openssl genrsa -out server.key 2048 //生成私钥
openssl req -new -x509 -key server.key -out server.pem -days 3650 //生成证书
阅读全文 »

1. 服务器相关

变量名备注示例
nginx_version当前运行的 Nginx 版本号1.11.2
server_port服务器端口8080
server_addr服务器端地址127.0.0.1
server_name服务器名称127.0.0.1
server_protocol服务器的HTTP版本HTTP/1.0
statusHTTP 响应代码200
time_iso8601服务器时间的 ISO 8610 格式2018-09-02T15:14:27+08:00
time_local服务器时间(LOG Format 格式)02/Sep/2018:15:14:27 +0800
document_root当前请求的文档根目录或别名/home/xiaowu/github/echo.xuexb.com
request_filename当前连接请求的文件路径,由 rootalias指令与 URI 请求生成/home/xiaowu/github/echo.xuexb.com/api/dump/path
request_completion如果请求成功,值为”OK”,如果请求未完成或者请求不是一个范围请求的最后一部分,则为空
pid工作进程的PID1234
msec当前的Unix时间戳1535872750.954
limit_rate用于设置响应的速度限制0
pipe如果请求来自管道通信,值为“p”,否则为“.”.
connection_requestsTCP连接当前的请求数量1
connectionTCP 连接的序列号363861
realpath_root当前请求的文档根目录或别名的真实路径,会将所有符号连接转换为真实路径/home/xiaowu/github/echo.xuexb.com
阅读全文 »

map的读写删除都不是原子操作,因此需要控制并发访问,而Go的原生map不支持并发读写;Go在1.9的版本中新增了sync.Map的数据结构,两个map实现分离。

  1. 不会引发扩容的操作(查,改)使用read map,可能引发扩容操作(新增)使用 dirty map。

  2. 读写 read 并不需要加锁,而读或写 dirty 则需要加锁。

  3. 适合读多 append 少的场景,其实是读写和追加分离。

阅读全文 »

hashMap一般有两个实现方案:开放寻址法(往后错位)和拉链法(槽内是链表)。

image-20240709220852218
  1. go map 其实是用的拉链法,首先有一个hmap的结构,存放了 2^B 个桶。
  2. map 的数据被置入一个由桶组成的有序数组中,每个桶最多可以存放 8 个 key/value,超了则会链接到额外的溢出桶。
  3. 基本数据结构是 (桶数组 + 桶内的key-value数组 + 溢出的桶链表)。
image-20240709221340103
阅读全文 »

1. channel

1.1 关闭有缓冲数据的 channel, 还能读取吗(可以)

只有当channel无数据,且channel被close了,才会返回ok=false。 只要有堆积数据,即使 close() 也不会返回关闭状态。

关闭后有数据也能从里面得到数据,除非消耗空了。

阅读全文 »

1. 目录

1.1 [/usr]/lib/systemd/system/

(软件包安装的单元)

The expectation is that /lib/systemd/system is a directory that should only contain systemd unit files which were put there by the package manager (YUM/DNF/RPM/APT/etc).

1.2 /etc/systemd/system/

(系统管理员安装的单元, 优先级更高)

Files in /etc/systemd/system are manually placed here by the operator of the system for ad-hoc software installations that are not in the form of a package. This would include tarball type software installations or home grown scripts.

阅读全文 »
0%