2016-11-30 129 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维基详细说明。

相关问题