[SSL: CERTIFICATE_VERIFY_FAILED] Certificate Verify Failed (_ssl.C:579)

在安装HDP过程中,遇到了连接失败的问题。原因是Python 2.7.5版本中的一个缺陷导致证书验证失败。解决方法是禁用Python中的证书验证。

安装HDP过程中,一直遇到问题。(一开始两个都是Failed)。网上搜索,有说是OpenSSL版本太旧要更新,更新后问题解决,但是自己的centos7尝试更新,但显示已经是最新的版本了。最终查到问题所在,是python2.7.5版本问题。网上答案详见错误代码后。


  1. ==========================
  2. Creating target directory...
  3. ==========================
  4. Command start time 2018-02-27 09:30:03
  5. Connection to node2.jky.com closed.
  6. SSH command execution finished
  7. host=node2.jky.com, exitcode=0
  8. Command end time 2018-02-27 09:30:03
  9. ==========================
  10. Copying ambari sudo script...
  11. ==========================
  12. Command start time 2018-02-27 09:30:03
  13. scp /var/lib/ambari-server/ambari-sudo.sh
  14. host=node2.jky.com, exitcode=0
  15. Command end time 2018-02-27 09:30:03
  16. ==========================
  17. Copying common functions script...
  18. ==========================
  19. Command start time 2018-02-27 09:30:03
  20. scp /usr/lib/python2.6/site-packages/ambari_commons
  21. host=node2.jky.com, exitcode=0
  22. Command end time 2018-02-27 09:30:04
  23. ==========================
  24. Copying OS type check script...
  25. ==========================
  26. Command start time 2018-02-27 09:30:04
  27. scp /usr/lib/python2.6/site-packages/ambari_server/os_check_type.py
  28. host=node2.jky.com, exitcode=0
  29. Command end time 2018-02-27 09:30:04
  30. ==========================
  31. Running OS type check...
  32. ==========================
  33. Command start time 2018-02-27 09:30:04
  34. Cluster primary/cluster OS family is redhat7 and local/current OS family is redhat7
  35. Connection to node2.jky.com closed.
  36. SSH command execution finished
  37. host=node2.jky.com, exitcode=0
  38. Command end time 2018-02-27 09:30:04
  39. ==========================
  40. Checking 'sudo' package on remote host...
  41. ==========================
  42. Command start time 2018-02-27 09:30:04
  43. Connection to node2.jky.com closed.
  44. SSH command execution finished
  45. host=node2.jky.com, exitcode=0
  46. Command end time 2018-02-27 09:30:05
  47. ==========================
  48. Copying repo file to 'tmp' folder...
  49. ==========================
  50. Command start time 2018-02-27 09:30:05
  51. scp /etc/yum.repos.d/ambari.repo
  52. host=node2.jky.com, exitcode=0
  53. Command end time 2018-02-27 09:30:05
  54. ==========================
  55. Moving file to repo dir...
  56. ==========================
  57. Command start time 2018-02-27 09:30:05
  58. Connection to node2.jky.com closed.
  59. SSH command execution finished
  60. host=node2.jky.com, exitcode=0
  61. Command end time 2018-02-27 09:30:05
  62. ==========================
  63. Changing permissions for ambari.repo...
  64. ==========================
  65. Command start time 2018-02-27 09:30:05
  66. Connection to node2.jky.com closed.
  67. SSH command execution finished
  68. host=node2.jky.com, exitcode=0
  69. Command end time 2018-02-27 09:30:06
  70. ==========================
  71. Copying setup script file...
  72. ==========================
  73. Command start time 2018-02-27 09:30:06
  74. scp /usr/lib/python2.6/site-packages/ambari_server/setupAgent.py
  75. host=node2.jky.com, exitcode=0
  76. Command end time 2018-02-27 09:30:06
  77. ==========================
  78. Running setup agent script...
  79. ==========================
  80. Command start time 2018-02-27 09:30:06
  81. ('WARNING 2018-02-27 09:30:14,621 NetUtil.py:116 - Server at https://master.jky.com:8440 is not reachable, sleeping for 10 seconds...
  82. INFO 2018-02-27 09:30:14,621 HeartbeatHandlers.py:115 - Stop event received
  83. INFO 2018-02-27 09:30:14,621 NetUtil.py:122 - Stop event received
  84. INFO 2018-02-27 09:30:14,621 ExitHelper.py:53 - Performing cleanup before exiting...
  85. INFO 2018-02-27 09:30:14,621 ExitHelper.py:67 - Cleanup finished, exiting with code:0
  86. INFO 2018-02-27 09:30:16,903 main.py:223 - Agent died gracefully, exiting.
  87. INFO 2018-02-27 09:30:16,904 ExitHelper.py:53 - Performing cleanup before exiting...
  88. INFO 2018-02-27 09:30:17,196 main.py:90 - loglevel=logging.INFO
  89. INFO 2018-02-27 09:30:17,197 main.py:90 - loglevel=logging.INFO
  90. INFO 2018-02-27 09:30:17,197 main.py:90 - loglevel=logging.INFO
  91. INFO 2018-02-27 09:30:17,198 DataCleaner.py:39 - Data cleanup thread started
  92. INFO 2018-02-27 09:30:17,199 DataCleaner.py:120 - Data cleanup started
  93. INFO 2018-02-27 09:30:17,199 DataCleaner.py:122 - Data cleanup finished
  94. INFO 2018-02-27 09:30:17,252 PingPortListener.py:50 - Ping port listener started on port: 8670
  95. INFO 2018-02-27 09:30:17,254 main.py:349 - Connecting to Ambari server at https://master.jky.com:8440 (192.168.201.13)
  96. INFO 2018-02-27 09:30:17,254 NetUtil.py:62 - Connecting to https://master.jky.com:8440/ca
  97. ERROR 2018-02-27 09:30:17,314 NetUtil.py:88 - [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579)
  98. ERROR 2018-02-27 09:30:17,314 NetUtil.py:89 - SSLError: Failed to connect. Please check openssl library versions.
  99. Refer to: https://bugzilla.redhat.com/show_bug.cgi?id=1022468 for more details.
  100. WARNING 2018-02-27 09:30:17,315 NetUtil.py:116 - Server at https://master.jky.com:8440 is not reachable, sleeping for 10 seconds...
  101. ', None)
  102. ('WARNING 2018-02-27 09:30:14,621 NetUtil.py:116 - Server at https://master.jky.com:8440 is not reachable, sleeping for 10 seconds...
  103. INFO 2018-02-27 09:30:14,621 HeartbeatHandlers.py:115 - Stop event received
  104. INFO 2018-02-27 09:30:14,621 NetUtil.py:122 - Stop event received
  105. INFO 2018-02-27 09:30:14,621 ExitHelper.py:53 - Performing cleanup before exiting...
  106. INFO 2018-02-27 09:30:14,621 ExitHelper.py:67 - Cleanup finished, exiting with code:0
  107. INFO 2018-02-27 09:30:16,903 main.py:223 - Agent died gracefully, exiting.
  108. INFO 2018-02-27 09:30:16,904 ExitHelper.py:53 - Performing cleanup before exiting...
  109. INFO 2018-02-27 09:30:17,196 main.py:90 - loglevel=logging.INFO
  110. INFO 2018-02-27 09:30:17,197 main.py:90 - loglevel=logging.INFO
  111. INFO 2018-02-27 09:30:17,197 main.py:90 - loglevel=logging.INFO
  112. INFO 2018-02-27 09:30:17,198 DataCleaner.py:39 - Data cleanup thread started
  113. INFO 2018-02-27 09:30:17,199 DataCleaner.py:120 - Data cleanup started
  114. INFO 2018-02-27 09:30:17,199 DataCleaner.py:122 - Data cleanup finished
  115. INFO 2018-02-27 09:30:17,252 PingPortListener.py:50 - Ping port listener started on port: 8670
  116. INFO 2018-02-27 09:30:17,254 main.py:349 - Connecting to Ambari server at https://master.jky.com:8440 (192.168.201.13)
  117. INFO 2018-02-27 09:30:17,254 NetUtil.py:62 - Connecting to https://master.jky.com:8440/ca
  118. ERROR 2018-02-27 09:30:17,314 NetUtil.py:88 - [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579)
  119. ERROR 2018-02-27 09:30:17,314 NetUtil.py:89 - SSLError: Failed to connect. Please check openssl library versions.
  120. Refer to: https://bugzilla.redhat.com/show_bug.cgi?id=1022468 for more details.
  121. WARNING 2018-02-27 09:30:17,315 NetUtil.py:116 - Server at https://master.jky.com:8440 is not reachable, sleeping for 10 seconds...
  122. ', None)
  123. Connection to node2.jky.com closed.
  124. SSH command execution finished
  125. host=node2.jky.com, exitcode=0
  126. Command end time 2018-02-27 09:30:19
  127. Registering with the server...
  128. Registration with the server failed.

Cause:

This is due to a defect in newer releases of Python 2.7.5 which causes certificate validation to fail regardless of certificate status. 

这是由于Python 2.7.5的新版本中存在缺陷,导致无论证书状态如何,证书验证都失败。

Resolution Steps:

NOTE: As a workaround, we strongly recommend that Python not be updated to a version newer than python-2.7.5-48.el*.x86_64 (or downgraded to that version, if newer).

You can verify your release through python -V or python -c 'import sys; print(sys.version)' or yum list installed |grep python. You'll want to confirm that the major version is 2.7.5, the build is from Feb 2017 or older, and the full release is 2.7.5-48 or older.

Alternatively, you can disable certificate verification in Python if you wish to remain on a newer version:

sed -i 's/verify=platform_default/verify=disable/' /etc/python/cert-verification.cfg

**我用这条命令解决了问题。只需要两个节点都输入这条命令即可。本文截图只在第一个节点执行了,所以第二个节点还是failed

(注意:作为一种解决方法,我们强烈建议 不要 Python  更新为比python-2.7.5-48.el * .x86_64更新的版本(或者降级到该版本,如果更新的话)。

你可以通过  python -V 或者  python -c'import sys; 打印(sys.version)'或  安装的yum列表| grep python。 您需要确认主要版本为2.7.5,版本为2017年2月或更早版本,完整版本为2.7.5-48或更早版本。

或者,如果您希望保留在新版本中,则可以在Python中禁用证书验证:

*我通过python -V 只能查看到自己的python版本为2.7.5,但是不知道是否为2.7.5-48,因此没法按照他人的解决办法,把版本降至2.7.5-48,智能禁用证书验证。希望,可以有通过改变python版本的办法解决问题


解决问题参考资料:

1.https://interset.zendesk.com/hc/en-us/articles/115011874548--SSL-CERTIFICATE-VERIFY-FAILED-certificate-verify-failed-ssl-c-579-

2.https://community.hortonworks.com/questions/120861/ambari-agent-ssl-certificate-verify-failed-certifi.html

在 Python 中,出现 `urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed` 错误,通常是因为 Python 2.7.9 之后,使用 `urllib.urlopen` 打开一个 `https` 链接时,会验证一次 SSL 证书,而当目标网站使用的是自签名的证书时就会抛出该错误 [^1]。以下是几种常见的解决方案: ### 忽略 SSL 证书验证 在使用 `urllib` 库时,可以通过创建一个忽略 SSL 验证的上下文来解决此问题。示例代码如下: ```python import urllib.request import ssl # 创建一个不验证 SSL 证书的上下文 context = ssl._create_unverified_context() try: # 使用创建的上下文打开 URL response = urllib.request.urlopen('https://example.com', context=context) html = response.read() print(html) except urllib.error.URLError as e: print(f"Error: {e}") ``` ### 设置系统环境变量 可以通过设置 `SSL_CERT_FILE` 环境变量,指向有效的 CA 证书文件,例如: ```bash set SSL_CERT_FILE=C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\certifi\cacert.pem ``` 在 Python 脚本中,也可以通过 `os.environ` 来设置: ```python import os import urllib.request os.environ['SSL_CERT_FILE'] = 'C:/Users/Admin/AppData/Local/Programs/Python/Python311/Lib/site-packages/certifi/cacert.pem' try: response = urllib.request.urlopen('https://example.com') html = response.read() print(html) except urllib.error.URLError as e: print(f"Error: {e}") ``` ### 更新 CA 证书 确保系统中的 CA 证书是最新的,可以使用 `certifi` 库来获取最新的 CA 证书。首先安装 `certifi`: ```bash pip install certifi ``` 然后在代码中使用: ```python import urllib.request import certifi try: response = urllib.request.urlopen('https://example.com', cafile=certifi.where()) html = response.read() print(html) except urllib.error.URLError as e: print(f"Error: {e}") ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值