如何在webhdfs-hdfs-hadoop-origin中启用cors origin allowhttp://localhost:4200不被访问控制允许原点所允许

x33g5p2x  于 2021-06-01  发布在  Hadoop
关注(0)|答案(4)|浏览(645)

当我尝试从angular 6应用程序访问webhdfs时,出现如下错误。在我看来,我几乎什么都试过了,包括改变电脑的设置 core-site.xml 以及 hdfs-site.xml 不幸的是没有积极的结果。显然,很可能需要正确配置hadoop。有人知道我怎么解决这个问题吗?

[Error] Origin http://localhost:4200 is not allowed by Access-Control-Allow-Origin.
[Error] XMLHttpRequest cannot load http://192.168.0.16:9870/webhdfs/v1/user/myuser/myfile.csv?op=CREATE&user.name=myuser&createflag=&createparent=true&overwrite=false due to access control checks.
[Error] Failed to load resource: Origin http://localhost:4200 is not allowed by Access-Control-Allow-Origin. (myfile.csv, line 0)
pieyvz9o

pieyvz9o1#

在core-site.xml中,如果没有,请添加此项。。。

<property>
  <name>hadoop.http.filter.initializers</name>
  <value>org.apache.hadoop.http.lib.StaticUserWebFilter,org.apache.hadoop.security.HttpCrossOriginFilterInitializer</value>
  <description>A comma separated list of class names. Each class in the list
  must extend org.apache.hadoop.http.FilterInitializer. The corresponding
  Filter will be initialized. Then, the Filter will be applied to all user
  facing jsp and servlet web pages.  The ordering of the list defines the
  ordering of the filters.</description>
</property>
<property>
<name>hadoop.http.cross-origin.enabled</name>
<value>true</value>
<description>Enables cross origin support for all web-services</description>
</property>
<property>
<name>hadoop.http.cross-origin.allowed-origins</name>
<value>*</value>
<description>Comma separated list of origins that are allowed, wildcards (*) and patterns allowed</description>
</property>
<property>
<name>hadoop.http.cross-origin.allowed-methods</name>
<value>GET,POST,HEAD,PUT,OPTIONS,DELETE</value>
<description>Comma separated list of methods that are allowed</description>
</property>
<property>
<name>hadoop.http.cross-origin.allowed-headers</name>
<value>X-Requested-With,Content-Type,Accept,Origin,WWW-Authenticate,Accept-Encoding,Transfer-Encoding</value>
<description>Comma separated list of headers that are allowed</description>
</property>
<property>
<name>hadoop.http.cross-origin.max-age</name>
<value>1800</value>
<description>Number of seconds a pre-flighted request can be cached</description>
</property>
sgtfey8w

sgtfey8w2#

您应该配置hdfs-site.xml,并添加配置

<property>
    <name>dfs.permissions</name>
    <value>false</value>
    <description>If "true", enable permission checking in HDFS. If "false", permission checking is turned off, but all other behavior is unchanged. Switching from one parameter value to the other does not change the mode, owner or group of files or directories.</description>
</property>
pgx2nnw8

pgx2nnw83#

从文档中:
要启用跨源支持(cors),请设置以下配置参数:
将org.apache.hadoop.security.httpcrossoriginfilterinitializer添加到core-site.xml中的hadoop.http.filter.initializers。您还需要在core-site.xml中设置以下属性-
hadoop.http.cross-origin.enabled=真
hadoop.http.cross-origin.allowed-origins=*
hadoop.http.cross-origin.allowed-methods=get、post、head、delete和options
hadoop.http.cross-origin.allowed-headers=x-requested-with,内容类型,接受,来源
hadoop.http.cross-origin.max-age=1800

webghufk

webghufk4#

必须将这些属性附加到此文件中 etc/hadoop/core-site.xml ```


hadoop.http.cross-origin.enabled
false


hadoop.http.cross-origin.allowed-origins
*


hadoop.http.cross-origin.allowed-methods
GET,POST,HEAD


hadoop.http.cross-origin.allowed-headers
X-Requested-With,Content-Type,Accept,Origin


hadoop.http.cross-origin.max-age
1800

相关问题