# Let's Encrypt免費ssl證書(基于haproxy負載)
- [1. 條件](#1__4)
- [2. 實施](#2__10)
- [2.1 準備工具](#21__12)
- [2.1.1 下載](#211__14)
- [2.1.2 安裝](#212__17)
- [2.2 獲取證書](#22__41)
- [2.3 配置haproxy](#23_haproxy_87)
- [2.3.1 條件](#231__89)
- [2.3.2 合并證書](#232__94)
- [2.3.4 配置haproxy](#234_haproxy_101)
- [2.3.5 pem轉成KeyStore](#235_pemKeyStore_118)
- [3. 申請延期](#3__130)
- [3.1 查看證書過期時間](#31__132)
- [3.2 申請延期](#32__143)
## 1. 條件
1. 可用的域名
2. 在域名綁定的服務器上
3. 域名綁定服務器在申請免費證書時,80和443端口是沒有被占用的(最主要的是80)
## 2. 實施
### 2.1 準備工具
#### 2.1.1 下載
<https://codeload.github.com/certbot/certbot/zip/master>
#### 2.1.2 安裝
```
unzip certbot-master.zip
cd certbot-master
```
1. letsencrypt-auto申請證書主要用的工具
使用說明:
```
run:獲取并安裝證書到當前的Web服務器
certonly:獲取或續期證書,但是不安裝
renew:在證書快過期時,續期之前獲取的所有證書
-d DOMAINS:一個證書支持多個域名,用逗號分隔
--apache:使用 Apache 插件來認證和安裝證書
--standalone:運行獨立的 web server 來驗證
--nginx:使用 Nginx 插件來認證和安裝證書
--webroot:如果目標服務器已經有 web server 運行且不能關閉,可以通過往服務器的網站根目錄放置文件的方式來驗證
--manual:通過交互式方式,或 Shell 腳本手動獲取證書
```
### 2.2 獲取證書
此命令代表僅僅獲取證書而已
```
./letsencrypt-auto certonly --standalone --email lovetocar@aexit.net -d 域名(多個用逗號隔開)
```
期間輸入:
```
-------------------------------------------------------------------------------
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-v01.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
(A)gree/(C)ancel: A
-------------------------------------------------------------------------------
Would you be willing 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 EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for lovetocar.cn
Waiting for verification...
Cleaning up challenges
```
見到如下,代表證書生成成功了
```
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/lovetocar.cn/fullchain.pem
Your key file has been saved at:
```
在/etc/letsencrypt/live/lovetocar.cn/ 目錄下生成四個文件
```
cert.pem: Your domain's certificate(公鑰)
chain.pem: The Let's Encrypt chain certificate
fullchain.pem: cert.pem and chain.pem combined(包含公鑰和 Let's Encrypt的證書文件)
privkey.pem: Your certificate's private key (私鑰)
```
### 2.3 配置haproxy
#### 2.3.1 條件
1. haproxy支持ssl(不支持就去編譯安裝)
2. 需要合并上一步生成的證書
#### 2.3.2 合并證書
haproxy負載下的web,需要為haproxy指定一個包含公鑰和私鑰的pem,此時合并fullchain.pem和privkey.pem
```
cat privkey.pem fullchain.pem | tee timing-prod.pem
```
#### 2.3.4 配置haproxy
```
frontend timing
bind 0.0.0.0:80
redirect scheme https if !{ ssl_fc } # http請求轉成https
bind 0.0.0.0:443 ssl crt /home/timing/https/ssl/fullchain.pem # 指定證書
acl is_timing hdr(host) -i lovetocar.cn lovetocar.cn:443
use_backend timing if is_timing
backend timing
balance source
server timing1 10.30.46.31:31001 weight 1 maxconn 10000 check inter 10s
server timing2 10.30.48.211:31001 weight 1 maxconn 10000 check inter 10s
```
#### 2.3.5 pem轉成KeyStore
如果有需要的話,pem可以轉成KeyStore
```
openssl pkcs12 -export -in cert.pem -inkey timing-prod.pem -out timing-prod.pk12 -name timing
keytool -importkeystore -deststorepass '4rfv$RFV' -destkeypass '4rfv$RFV' -destkeystore timing-prod.keystore -srckeystore timing-prod.pk12 -srcstoretype PKCS12 -srcstorepass '4rfv$RFV' -alias timing
```
## 3. 申請延期
### 3.1 查看證書過期時間
包含公鑰的pem
```
openssl x509 -in ./fullchain2.pem -noout -dates
notBefore=Feb 28 01:54:56 2018 GMT
notAfter=May 29 01:54:56 2018 GMT
```
證書有效期是 2018-2-28到2018-5-29
### 3.2 申請延期
```
certbot renew
```
- 計算機網絡
- 基礎_01
- tcp/ip
- http轉https
- Let's Encrypt免費ssl證書(基于haproxy負載)
- what's the http?
- 網關
- 網絡IO
- http
- 工具
- Git
- 初始本地倉庫并上傳
- git保存密碼
- Gitflow
- maven
- 1.生命周期命令
- 聚合與繼承
- 插件管理
- assembly
- 資源管理插件
- 依賴范圍
- 分環境打包
- dependencyManagement
- 版本分類
- 找不到主類
- 無法加載主類
- 私服
- svn
- gradle
- 手動引入第三方jar包
- 打包exe文件
- Windows
- java
- 設計模式
- 七大原則
- 1.開閉原則
- 2. 里式替換原則
- 3. 依賴倒置原則
- 4. 單一職責原則
- 單例模式
- 工廠模式
- 簡單工廠
- 工廠方法模式
- 抽象工廠模式
- 觀察者模式
- 適配器模式
- 建造者模式
- 代理模式
- 適配器模式
- 命令模式
- json
- jackson
- poi
- excel
- easy-poi
- 規則
- 模板
- 合并單元格
- word
- 讀取
- java基礎
- 類路徑與jar
- 訪問控制權限
- 類加載
- 注解
- 異常處理
- String不可變
- 跨域
- transient關鍵字
- 二進制編碼
- 泛型1
- 與或非
- final詳解
- Java -jar
- 正則
- 讀取jar
- map
- map計算
- hashcode計算原理
- 枚舉
- 序列化
- URLClassLoader
- 環境變量和系統變量
- java高級
- java8
- 1.Lambda表達式和函數式接口
- 2.接口的默認方法和靜態方法
- 3.方法引用
- 4.重復注解
- 5.類型推斷
- 6.拓寬注解的應用場景
- java7-自動關閉資源機制
- 泛型
- stream
- 時區的正確理解
- StringJoiner字符串拼接
- 注解
- @RequestParam和@RequestBody的區別
- 多線程
- 概念
- 線程實現方法
- 守護線程
- 線程阻塞
- 筆試題
- 類加載
- FutureTask和Future
- 線程池
- 同步與異步
- 高效簡潔的代碼
- IO
- ThreadLocal
- IO
- NIO
- 圖片操作
- KeyTool生成證書
- 壓縮圖片
- restful
- 分布式session
- app保持session
- ClassLoader.getResources 能搜索到的資源路徑
- java開發規范
- jvm
- 高并發
- netty
- 多線程與多路復用
- 異步與事件驅動
- 五種IO模型
- copy on write
- code style
- 布隆過濾器
- 筆試
- 數據庫
- mybatis
- mybatis與springboot整合配置
- pagehelper
- 分頁數據重復問題
- Java與數據庫之間映射
- 攔截器
- 攔截器應用
- jvm
- 堆內存測試
- 線程棧
- 直接內存
- 內存結構
- 內存模型
- 垃圾回收
- 調優
- 符號引用
- 運行參數
- 方法區
- 分帶回收理論
- 快捷開發
- idea插件
- 注釋模板
- git
- pull沖突
- push沖突
- Excel處理
- 圖片處理
- 合并單元格
- easypoi
- 模板處理
- 響應式編程
- reactor
- reactor基礎
- jingyan
- 規范
- 數據庫