系列目录html
因为服务端设置了https访问,所以若是经过浏览器访问时会提示证书不被信任,可是仍然能够经过处理继续访问.可是在自动化环境中,都是经过命令来请求的,这样不受信任的https就会报错误,这样咱们就要像docker服务器同样添加对自签证书的信任.前两部分咱们分别在docker推送镜像和拉取镜像时添加了信任证书操做.可是都是基于linux的,在自动化环境中,可能有的节点是windows节点,咱们这一节来看下如何在windows环境下添加自签证书信任.java
咱们先来看一下若是没有添加证书信任的状况下经过命令请求的结果是什么样子的linux
C:\Users\tyler>curl https://192.168.124.43:8443/ curl: (77) schannel: next InitializeSecurityContext failed: SEC_E_UNTRUSTED_ROOT (0x80090325) - The certificate chain was issued by an authority that is not trusted. C:\Users\tyler>
能够看到,请求失败,提示的错误信息是证书不被信任.web
因为个人windows测试机上安装了curl所以会出现curl命令,若是你没有安装则会出现curl不是一个命令的错误.若是不想装curl能够经过powershell来请求,具体操做以下docker
PS C:\Users\tyler> Invoke-WebRequest https://192.168.124.43:8443/ Invoke-WebRequest : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. At line:1 char:1 + Invoke-WebRequest https://192.168.124.43:8443/ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc eption + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand PS C:\Users\tyler>
能够看到,没有添加信任经过命令请求就会返回错误.下面咱们讲下如何在windows环境下添加自签证书信任shell
首先,打开cmd,cd到一个自已便于记的目录,而后执行命令keytool -printcert -sslserver 192.168.124.43:8443 -rfc >nexus.crt
windows
前面已经说过要执行keytool命令须要正确配置java,若是仍然没法执行,能够从java安装目录里找到
keytool.exe
,以上命令的keytool换成keytoolexe
的完整路径.浏览器
若是你看到页面里面的内容没有上面的多,也不用担忧,由于这个状态并不是初始状态.服务器
在以上操做过程当中会出现一个选择,默认选择当前用户便可.curl
以上操做完之后点击肯定.而后展开左侧的证书,并执行如下操做
点击导入就会出现一个选择对话框,这时候找到咱们刚才保存的nexus.crt文件导入.最后会出现一个警示,这时候选择肯定.而不是取消.
这时候,若是关闭主界面的时候会提示是否保存设置,这里取消便可.证书信任已经保存.
这个时候咱们再执行curl
或者powershell invoke-webrequest
,便可以年到以下信息
>curl https://192.168.124.43:8443/ <!DOCTYPE html> <html lang="en"> <head> <title>Nexus Repository Manager</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <meta name="description" content="Nexus Repository Manager"/> <meta http-equiv="X-UA-Compatible" content="IE=edge"/> ...
因为内容太长,这里就再也不输完整的了.
原文出处:https://www.cnblogs.com/tylerzhou/p/11102605.html