2016-11-30 238 views
0

我正在自動執行集羣的安裝和供應,其中包括安裝Ambari並通過API使用Blueprint。這一切都工作正常,但我有一件事,我遇到了麻煩,這是在整個供應過程中(我指的是我的過程,而不是Ambari集羣創建過程)更改Ambari密碼。我不想要的是將新安裝的Ambari安裝與默認的「admin/admin」憑據放在一起,而且我也不能讓每個人都進行更改。如何以編程方式更改Ambari管理員密碼

我試過了REST API,但即使調用看起來執行正確(例如,沒有錯誤返回),新密碼也不會生效。

我想過通過ssh使用ambari-admin-password-reset命令,但是我的Ambari安裝(使用2.1.0)似乎沒有該命令。我再次檢查代理正在運行,並且我已經以root用戶的身份嘗試過它,並且在任何情況下都會產生「未找到命令」錯誤。我也想過使用JDBC,直接連接到Postgres,並直接使用密碼,但我不確定Ambari使用哪種哈希算法,和/或它存儲鹽的位置(如果使用的話)。

如果任何人都可以提供有關如何使任何或所有這些方法工作的任何建議,將不勝感激。現在我要把我的最後一根頭髮撕成這樣。

編輯:FWIW,這是我在調用REST API時所做的,這似乎是在默默地失敗。

public static void main(String[] args) 
{ 


    // make REST call to Ambari to change password 
    try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) 
    { 
     HttpHost target = new HttpHost("admin.test-cluster-6.example.com", 8080, "http"); 

     String authorizationEncoded = Base64.encodeBase64String("admin:admin".getBytes()); 

     // specify the put request 
     HttpPut putRequest = new HttpPut("/api/v1/users/admin"); 

     StringEntity jsonEntity = new StringEntity("{\"Users/password\":\"newpassword\"}"); 

     putRequest.setEntity(jsonEntity); 
     putRequest.setHeader("X-Requested-By:", "ambari"); 
     putRequest.setHeader("Authorization", "Basic " + authorizationEncoded); 

     System.out.println("executing request to " + target); 

     HttpResponse httpResponse = httpClient.execute(target, putRequest); 
     HttpEntity entity = httpResponse.getEntity(); 
     System.out.println("status: " + httpResponse.getStatusLine()); 
     InputStream is = entity.getContent(); 
     String responseBody = streamToString(is); 

     System.out.println("response: " + responseBody); 

    } 
    catch (IOException e) 
    { 
     e.printStackTrace(); 

    } 

    System.out.println("done"); 
} 

這樣做產生的輸出

status: HTTP/1.1 200 OK 

這將導致人們認爲操作成功。但沒有骰子。

此外,這是Ambari 2.1.0,無論您嘗試更改哪個用戶的密碼,都會發生相同的行爲。

回答

1

你有正確的網址,但你發送的JSON不正確。它應該是這樣的形式:

{ 
    "Users": { 
    "user_name": "myusername", 
    "old_password": "myoldpassword", 
    "password": "mynewpassword" 
    } 

}

這是對這個page在ambari維基詳細說明。