Write the Code. Change the World.

4月 28

https://certbot.eff.org/instructions?ws=nginx&os=snap&tab=standard

安装

安装 snapd

https://snapcraft.io/docs/installing-snap-on-centos

https://snapcraft.io/docs/installing-snapd

yum install snapd

systemctl enable --now snapd.socket

ln -s /var/lib/snapd/snap /snap

看看 snapd 状态。 snap changes

安装 certbot

snap install --classic certbot

建立软链

ln -s /snap/bin/certbot /usr/bin/certbot

生成证书

必须服务器先安装好 nginx。

生成单个域名证书

  • 执行 nginx -t 先查找 nginx 的配置文件位置。比如:/tianwanggaidhu/service/nginx/conf/nginx.conf
  • 执行生成命令。比如生成证书的域名是 vini123.com。
    certbot --nginx --nginx-server-root=/tianwanggaidhu/service/nginx/conf -d vini123.com -d www.vini123.com

    需要注意的是,--nginx-server-root 对应的是 nginx.conf 的配置目录,而不是具体的文件。

生第一个域名证书的时候,会让你输入 email,然后同意协议(y 回车即可)。生成一次后,后边的域名就直接生成了。

可以在任意位置执行该命令。

生成成功的同时,nginx 也一起重启了。也就是生成后,证书就 ok了。

证书续期

生成的证书有效期是 3 个月的。3个月后,需要新的证书。这里用续期处理。

certbot renew --dry-run

可以通过定时任务来续订。

生泛域名证书

参考

https://www.cnblogs.com/michaelshen/p/18538178

4月 27

coturn

https://github.com/coturn/coturn/

安装

安装依赖

yum install -y make gcc cc gcc-c++ wget openssl-devel libevent libevent-devel

下载和编译

cd /usr/local/src

wget https://codeload.github.com/coturn/coturn/tar.gz/refs/tags/4.6.2

tar -xzvf coturn-4.6.2.tar.gz

cd coturn-4.6.2

./configure

make

make install

安装结束时的最后几行日志。

install -p examples/etc/turnserver.conf /usr/local/etc/turnserver.conf.default
cp -rpf examples/etc /usr/local/share/examples/turnserver
cp -rpf examples/scripts /usr/local/share/examples/turnserver
rm -rf /usr/local/share/examples/turnserver/scripts/rfc5769.sh
cp -rpf include/turn/client /usr/local/include/turn
install -p include/turn/ns_turn_defs.h /usr/local/include/turn
cat /usr/local/share/doc/turnserver/postinstall.txt

检查安装

which turnserver

输出:/usr/local/bin/turnserver

配置 turn

cd /usr/local/etc
cp turnserver.conf.default turnserver.conf

配置以下信息。

listening-port=3478  # 监听的端口
listening-ip=0.0.0.0 # 监听的内网IP
external-ip=x.x.x.x  # 监听的外网IP
user=user:123456     # 设置账号密码
realm=xxx.com        # realm 名称,通常是一个域名
no-tls
no-dtls
verbose
log-file=/var/log/turn.log # 配置日志位置

配置自启动

添加

vim /usr/lib/systemd/system/turnserver.service

# 配置以下内容
[Unit]
Description=turnserver for p2p
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/bin/turnserver -o -c /usr/local/etc/turnserver.conf
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

# :wq 保存

启用

  • systemctl daemon-reload 重置服务列表
  • systemctl enable turnserver.service 开启开机自启
  • systemctl start turnserver.service 启动服务
  • systemctl restart turnserver.service 重启服务
  • systemctl status turnserver.service 查看状态
  • systemctl disable turnserver.service 关闭开机自启。()不关闭,就不执行这个)

查看进程

ps -ef|grep turnserver

# 只显示主进程
pgrep -a turnserver

查看监听端口。

netstat -tulnp | grep turnserver

查看 3478 端口。

lsof -i :3478

测试检查

turnutils_uclient -v -t -y -u user -w password ip

替换对应的 user, password, ip 为配置的值。

或网页测试
https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/

参考

https://sanyers.github.io/blog/web/webrtc/turn%E6%9C%8D%E5%8A%A1%E5%99%A8%E9%83%A8%E7%BD%B2.html#_6%E3%80%81%E5%90%AF%E5%8A%A8%E6%9C%8D%E5%8A%A1

https://coturn.net/turnserver/

https://github.com/coturn/coturn/wiki/Downloads

4月 22

go-stress-testing

https://github.com/link1st/go-stress-testing
如果没有环境可以去下作者编译好的: https://github.com/link1st/go-stress-testing/releases

go clone https://github.com/link1st/go-stress-testing.git

cd go-stress-testing

go build

执行测试:

.\go-stress-testing.exe -c 10 -n 10 -u https://www.baidu.com

返回结果:

参考

https://cloud.tencent.com/developer/article/1509809

go-wrk

https://github.com/adjust/go-wrk

操作

自身系统有 go 环境。

git clone https://github.com/adjust/go-wrk.git
cd go-wrk
go mod init go-wrk
go build

执行测试。

./go-wrk [flags] url

例子:

./go-wrk -c=400 -t=8 -n=100000 http://localhost:8080/index.html

flags

 -H="User-Agent: go-wrk 0.1 bechmark\nContent-Type: text/html;": the http headers sent separated by '\n'
    -c=100: the max numbers of connections used
    -k=true: if keep-alives are disabled
    -i=false: if TLS security checks are disabled
    -m="GET": the http request method
    -n=1000: the total number of calls processed
    -t=1: the numbers of threads used
    -b="" the http request body
    -s="" if specified, it counts how often the searched string s is contained in the responses