獲取安全證書有兩個辦法:互聯網認證的CA處獲取。自建CA本身給本身簽名。css
一、準備一臺服務器(有公網IP),已作好域名解析。這裏以Ubuntu 14.04 TLS爲例。
二、確保該服務器80,443端口能夠從互聯網訪問到且不被佔用(關掉佔用端口的服務器)。node
由於LetsEncrypt申請證書是須要聯網簽名的,而且要用到80端口。nginx
在成功獲取證書後,服務器IP和端口就可另做他用。所以,能夠在某臺有公網IP的主機服務器上獲取證書,再將證書轉移到其它服務器進行使用。若採用 這樣的方式,Docker客戶端須要將私網IP和dockie.mydomain.com對應寫入hosts文件或將該解析寫到私網DNS服務器裏。但證 書到期renew的時候還須要一樣的公網域名(公網IP能夠不一樣)。git
三、在服務器上獲取簽名證書github
SH$ git clone https://github.com/letsencrypt/letsencrypt.git $ cd letsencrypt $ sudo ./certbot-auto certonly --standalone --email admin@example.com -d example.com -d www.example.com -d other.example.net
這裏直接根據官方提供的方法從GITHUB獲取安裝包和目錄安裝,上面是一個標準的格式,根據咱們的郵箱、以及須要添加的域名設置,若是多域名直接 在後面添加-d就能夠,好比繼續添加其餘域名 -d www.laojiang.me -d laojiang.me以此類推。docker
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/laojiang.me/fullchain.pem. Your cert will expire on 2016-07-13. To obtain a new version of the certificate in the future, simply run Let's Encrypt again. - If you like Let's Encrypt, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le
看到這樣的文字和提示就表明獲取Let’s Encrypt證書成功,時間是90天,咱們須要在到期前手手動續約就能夠繼續90天。而後咱們在」/etc/letsencrypt/live/域名 /「目錄中看到4個文件(cert.pem chain.pem fullchain.pem privkey.pem)。瀏覽器
四、更新證書
使用下面這條命令,更新證書,它將更新到期時間不到30天的證書,並且它會根據你當初生成證書的設置更新你的證書。安全
$ ./certbot-auto renew --dry-run
五、經過鉤子更新證書bash
$ ./certbot-auto renew --standalone --pre-hook "service nginx stop" --post-hook "service nginx start"
這裏使用了一個鉤子,--pre-hook
>更新前執行命令命令,--post-hook
更新以後執行命令。服務器
執行如下命令,它會在文件夾下生成domain.key和domain.crt
SHmkdir -p certs && openssl req \ -newkey rsa:4096 \ -nodes -sha256 \ -keyout certs/domain.key \ -x509 -days 365 \ -out certs/domain.crt
相關參數說明:
SHCountry Name (2 letter code) [AU]:CN #國家代碼,中國CN State or Province Name (full name) [Some-State]:Sichuan #省份全拼 Locality Name (eg, city) []:Chengdu #城市 Organization Name (eg, company) [Internet Widgits Pty Ltd]:Person #組織名,公司名 Organizational Unit Name (eg, section) []:Chen #部門名稱 Common Name (e.g. server FQDN or YOUR name) []:registry.domain.com #這裏必須填寫Docker Registry使用的域名 Email Address []:ccc@domain.com #電子郵件
自簽名證書,使用Docker Registry的Docker機須要將domain.crt拷貝到 /etc/docker/certs.d/[docker_registry_domain]/ca.crt,而後重啓docker,將domain.crt內容放入系統的CA bundle文件當中,使操做系統信任咱們的自簽名證書。
CentOS 6 / 7中bundle文件的位置在/etc/pki/tls/certs/ca-bundle.crt:
cat domain.crt >> /etc/pki/tls/certs/ca-bundle.crt
Ubuntu/Debian Bundle文件地址/etc/ssl/certs/ca-certificates.crt
cat domain.crt >> /etc/ssl/certs/ca-certificates.crt
Mac
一、點擊鑰匙串訪問
二、點擊系統
三、點擊證書
四、將domain.crt拖到目錄下 五、輸入密碼,添加成功 六、雙擊該證書,點擊信任,選擇 七、退出