0%

仓库地址

1
https://registry.hub.docker.com/r/certbot/certbot

官方参考

1
https://certbot.eff.org/docs/install.html#running-with-docker

pull 镜像

1
docker pull certbot/certbot

基于内置webserver部署

这个方案的坏处是需要启动内置的nginx服务器占用80和443端口.

创建两个目录

1
2
/etc/letsencrypt
/var/lib/letsencrypt

运行镜像

1
2
3
4
5
docker run -it --rm --name certbot \
-v "/etc/letsencrypt:/etc/letsencrypt" \
-v "/var/lib/letsencrypt:/var/lib/letsencrypt" \
-p 80:80 -p 443:443 \
certbot/certbot certonly

提问用webserver部署或者用webroot

1
2
3
4
5
6
7
How would you like to authenticate with the ACME CA?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Spin up a temporary webserver (standalone)
2: Place files in webroot directory (webroot)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 1

我们用临时服务器方便点所以选择1, 如果用2的话需要自己设置验证文件.

提示你输入邮箱

1
2
3
Plugins selected: Authenticator standalone, Installer None
Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel):

不用看了,就是我已阅读并同意….

1
2
3
4
5
6
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: a

想不想接受他给你发邮件

1
2
3
4
5
6
7
8
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y

输入你的域名, 例如: yourself.hostname.xxx, 这里不要输错了, 输错无法后退, 只能重来.

1
2
Please enter in your domain name(s) (comma and/or space separated)  (Enter 'c'
to cancel): yourself.hostname.xxx

看到

1
2
3
4
5
6
7
8
9
10
11
12
13
14
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/yourself.hostname.xxx/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/yourself.hostname.xxx/privkey.pem
Your cert will expire on 2020-12-13. To obtain a new or tweaked
version of this certificate in the future, simply run certbot
again. To non-interactively renew *all* of your certificates, run
"certbot renew"
- If you like Certbot, please consider supporting our work by:

Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le

完成

证书保存在

1
/etc/letsencrypt/live/yourself.hostname.xxx/

使用阿里源进行安装

CentOS7用阿里源安装Docker

1
2
3
4
5
6
7
8
9
# step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3: 更新并安装Docker-CE
sudo yum makecache fast
sudo yum -y install docker-ce
# Step 4: 开启Docker服务
sudo service docker start

根据CentOS7的安装方式安装遇到如下问题。
错误描述

1
2
3
4
5
6
7
8
9
10
11
12
13
上次元数据过期检查:0:00:11 前,执行于 20200610日 星期三 020521秒。
错误:
问题: package docker-ce-3:19.03.11-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
- cannot install the best candidate for the job
- package containerd.io-1.2.10-3.2.el7.x86_64 is excluded
- package containerd.io-1.2.13-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.13-3.2.el7.x86_64 is excluded
- package containerd.io-1.2.2-3.3.el7.x86_64 is excluded
- package containerd.io-1.2.2-3.el7.x86_64 is excluded
- package containerd.io-1.2.4-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.5-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.6-3.3.el7.x86_64 is excluded
(尝试添加 '--skip-broken' 来跳过无法安装的软件包 或 '--nobest' 来不只使用最佳选择的软件包)

使用阿里源安装containerd.io安装不低于1.2.2-3的版本

1
yum install -y https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/edge/Packages/containerd.io-1.2.13-3.2.el7.x86_64.rpm

然后继续根据CentOS7的安装方法安装即可。

参考链接:https://blog.csdn.net/RtxTitanV/article/details/106550640

12306验证码识别

这是一个基于Flask,Tensorflow,Keras实现的12306验证码识别接口。

搭建好的接口:https://mark12306captcha.wudinaonao.com

拉取镜像

1
docker pull wudinaonao/flask-mark-12306-captcha

启动镜像

docker

1
docker run -dit -p 8848:8848 wudinaonao/flask-mark-12306-captcha

docker compose

1
2
3
4
5
6
7
8
version: "3.1"
services:
flask-mark-12306-captcha:
image: wudinaonao/flask-mark-12306-captcha
container_name: flask-mark-12306-captcha
ports:
- 8848:8848
restart: always

一个用于验证的前端

访问:http://yourhostname:8848

20200609204007

API

获取验证码

从12306获取一张测试的验证码

  • Request

    • Method: GET
    • Headers
      • Content-Type: application/json
    • URL: /Mark12306Captcha/api/v1.0/get/captcha
  • Response

    • Headers
      • Content-Type: application/json
    • Body
      1
      2
      3
      4
      5
      {
      "status": "success",
      "message": "mark successfully",
      "result": "captcha base64 string"
      }

识别

Full

  • Request

    • Method: POST
    • Headers
      • Content-Type: application/json
    • URL: /Mark12306Captcha/api/v1.0/mark
    • Body
      • {"originCaptcha":"captcha base64 string"}
  • Response

    • Headers
      • Content-Type: application/json
    • Body
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      {
      "status": "success",
      "message": "mark successfully",
      "result": {
      "originCaptcha": "origin captcha base64 string",
      "ids": [
      5,
      7
      ],
      "results": [
      [
      190,
      165
      ],
      [
      260,
      141
      ]
      ],
      "markedCaptcha": "marked captcha base64 string"
      }
      }
  • Result 解释说明

    • ids 图片的编号
      • 0 2 4 6
        1 3 5 7
    • results 一个列表,每个元素是标记的坐标
    • markedCaptcha 绘制好标记结果的验证码Base64字符串

Lite

  • Request

    • Method: POST
    • Headers
      • Content-Type: application/json
    • URL: /Mark12306Captcha/api/v1.0/mark/lite
    • Body
      • {"originCaptcha":"captcha base64 string"}
  • Response

    • Headers
      • Content-Type: application/json
    • Body
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      {
      "status": "success",
      "message": "mark successfully",
      "result": [
      [
      168,
      144
      ],
      [
      274,
      125
      ]
      ]
      }
    • Result 解释说明参见上面

License

Apache License

denied: requested access to the resource is denied

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
The push refers to repository [docker.io/library/flask-mark-12306-captcha]
0566a0ade762: Preparing
a82f13d5c08d: Preparing
6680b518709b: Preparing
42d3338c1387: Preparing
380d9d1be624: Preparing
5bf497fc7ae4: Waiting
079e0a70bca0: Waiting
569e5571a3eb: Waiting
697765a85531: Waiting
8c39f7b1a31a: Waiting
88cfc2fcd059: Waiting
760e8d95cf58: Waiting
7cc1c2d7e744: Waiting
8c02234b8605: Waiting
denied: requested access to the resource is denied

解决

push 的时候加上用户名

1
docker push <username>/<image name>:<tag name>

An image does not exist locally with the tag

1
2
3
(base) root@ubuntu:/home/ubuntu/docker/python/FlaskMark12306Captcha# docker push wudinaonao/flask-mark-12306-captcha:v1
The push refers to repository [docker.io/wudinaonao/flask-mark-12306-captcha]
An image does not exist locally with the tag: wudinaonao/flask-mark-12306-captcha

解决

本地不存在指定的镜像,可能构建镜像的时候没有指定tag

1
docker tag <old image name> <username>/<new image name>:<tag name>

例如

1
docker tag flask-mark-12306-captcha wudinaonao/flask-mark-12306-captcha:v1

完成

20200609193818

1
2
3
ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service
cd /etc/systemd/system/
nano rc-local.service

rc-local.service 内容

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
#  SPDX-License-Identifier: LGPL-2.1+
#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

[Install]
WantedBy=multi-user.target
Alias=rc-local.service

创建 rc.local 文件

1
touch /etc/rc.local

赋予可执行权限

1
chmod 755 /etc/rc.local

编辑 rc.local

1
nano /etc/rc.local

文件内容

1
2
3
4
5
6
#!/bin/bash

# 这里开机执行的脚本
# 要卸载 exit 0 之前

exit 0

完成。

参考链接 https://blog.csdn.net/zhengchaooo/article/details/80202599

方法一

返回值为字符串类型

1
2
import os
os.getenv("KEY")

方法二

返回值为bytes类型

1
2
import os
os.getenvb("KEY")

错误描述

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Traceback (most recent call last):
File "Scheduler.py", line 96, in <module>
scheduler.start()
File "Scheduler.py", line 78, in start
CronTrigger.from_crontab(Config.SPIDER_INTERVAL)
File "/root/anaconda3/envs/caoliu/lib/python3.6/site-packages/apscheduler/triggers/cron/__init__.py", line 103, in from_crontab
day_of_week=values[4], timezone=timezone)
File "/root/anaconda3/envs/caoliu/lib/python3.6/site-packages/apscheduler/triggers/cron/__init__.py", line 58, in __init__
self.timezone = get_localzone()
File "/root/anaconda3/envs/caoliu/lib/python3.6/site-packages/tzlocal/unix.py", line 165, in get_localzone
_cache_tz = _get_localzone()
File "/root/anaconda3/envs/caoliu/lib/python3.6/site-packages/tzlocal/unix.py", line 90, in _get_localzone
utils.assert_tz_offset(tz)
File "/root/anaconda3/envs/caoliu/lib/python3.6/site-packages/tzlocal/utils.py", line 46, in assert_tz_offset
raise ValueError(msg)
ValueError: Timezone offset does not match system offset: 0 != 28800. Please, check your config files.

开发机上一切正常,部署到服务器上出现这个问题。

服务器的时区和apscheduler不一样。

解决方案

在 apscheuler 里指定时区

查看服务器上的时区

1
cat /etc/timezone

在 apscheuler 里指定时区

20200606173447

Ubuntu 版本 20.04 LTS

1
sudo tzselect

根据提示选择你需要的时区

20200606171802

例如我选择的是Asia-China-Beijing Time

创建一个软连接

1
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

查看结果

1
date -R

挂载远程目录//192.168.1.3/download/porn到本地/download/porn

1
mount -t cifs //192.168.1.3/download/porn /download/porn -o username=test,password=test,domain=DOMAIN,vers=1.0