分类目录归档:未分类

Certbot为阿里云/cloudflare域名生成证书

# 对于主机上存在合适的python版本的环境,可以使用以下方法:
apt install certbot
python3 -m venv venv  # 这个会提示你应该用什么命令,就是下面的,根据自己的python版本而不同
apt install python3.11-venv
mkdir -p /mnt/certbot
cd /mnt/certbot
python3 -m venv venv
source venv/bin/activate
pip install certbot certbot-nginx certbot-dns-aliyun
vi /mnt/certbot/credentials.ini
dns_aliyun_access_key = xxxxxxx
dns_aliyun_access_key_secret = yyyyyyyyy
# 设置配置文件权限,否则会有安全警示
chmod 0400 /mnt/certbot/credentials.ini
certbot certonly --dns-aliyun-credentials credentials.ini -d example.cn -d *.example.cn

certbot需要python3较新版本,比如 3.11. 如果主机安装python有困难(比如centos 7,已经不维护了),可以使用docker方式。

# 本地证书地址可以映射到 /etc/nginx/conf.d/cert,方便查看
docker run --restart=always -d -v 本地证书路径:/etc/letsencrypt --name certbot python:3.11-slim tail -f /dev/null
# 这个时候已经启动了一个python环境,由于python docker内可能没有vim等工具,可在宿主机上编辑配置文件credentials.ini
docker exec -it certbot /bin/bash
# 进入docker容器以后再执行生成证书的操作
证书创建以后,需要定时续期,需要在/etc/letsencrypt/cert-renew.sh
certbot renew
加上执行权限 chmod +x cert-renew.sh
在宿主机上,执行下面的命令就可以自动续期
docker exec -it certbot /bin/bash /etc/letsencrypt/cert-renew.sh
放到crontab中每天检查一遍即可
# 对于cloudflare,需要的配置文件和命令如下
在python环境内需要安装的包
pip install certbot certbot-nginx certbot-dns-cloudflare
# 配置文件内容如下, cloudflare里的配置文件使用受限API,只能访问指定的资源,更加安全
dns_cloudflare_api_token = xxxxxxxxxxxxx
# 另一种方式是使用全局权限(非常不推荐):
dns_cloudflare_email = cloudflare@example.com
dns_cloudflare_api_key = xxxxxxxxx
# 命令如下
certbot certonly --dns-cloudflare --dns-cloudflare-credentials /etc/letsencrypt/credentials.ini --dns-cloudflare-propagation-seconds 60 --key-type ecdsa -d mydomain.me -d *.mydomain.me

# 续期命令仍然是
certbot renew

failed to find cpu cgroup (v2)

阿里云的服务器,启动k3s服务时,报错误:failed to find cpu cgroup (v2)

找了好久,找到了一个可用的解决方法:

系统启动时,systemd默认使用Cgroups v1, 并将可以使用的controller mount到/sys/fs/cgroup。如果想在启动时把Cgroups v1关掉,可以在/etc/default/grub文件下修改kernel参数,增加GRUB_CMDLINE_LINUX_DEFAULT=”cgroup_no_v1=all”. 其中的all表示关闭所有的v1 controller,如果只想关闭指定的controller,则将all替换成需要的controller名称,并用逗号分隔即可。这样就可以在cgroups v2中使用你想要的controller了。