Hadoop集群配置完成,web監控界面的50070和50030端口不需用戶驗證即可訪問,對生產環境是不容許的,需要加上安全機制。
實驗環境:OS:Centos 6.5 x64 & Soft:Hadoop 1.2.1
1、修改core-site.xml,增加如下內容,配置完成后拷貝到其他節點上。
<property> <name>hadoop.http.filter.initializers</name> <value>org.apache.hadoop.security.AuthenticationFilterInitializer</value> </property> <property> <name>hadoop.http.authentication.type</name> <value>simple</value> </property> <property> <name>hadoop.http.authentication.token.validity</name> <value>3600</value> </property> <property> <name>hadoop.http.authentication.signature.secret.file</name> <value>/home/huser/hadoop/hadoop-http-auth-signature-secret</value> </property> <property> <name>hadoop.http.authentication.cookie.domain</name> <value></value> </property> <property> <name>hadoop.http.authentication.simple.anonymous.allowed</name> <value>false</value> </property>
2、在上述配置的目錄/home/huser/hadoop/下生成文件hadoop-http-auth-signature-secret,拷貝到其他節點上。
$ echo "hadoop" > hadoop-http-auth-signature-secret
3、重啟集群環境,訪問web頁面會報錯。
HTTP ERROR 401
Problem accessing /dfshealth.jsp. Reason:
org.apache.hadoop.security.authentication.client.AuthenticationException: Anonymous requests are disallowed
在訪問地址欄后面加上?user.name=xxx,其中“xxx“為hadoop-http-auth-signature-secret文件寫入的內容,頁面可以正常訪問,由此可以做到安全機制。