| | |
| | | // @Failure 500 {string} json "{"code":500, msg:"", success:false}" |
| | | // @Router /data/api-v/es/updateEsHosts [POST] |
| | | func (em *EsManagementController) UpdateEsHosts(c *gin.Context) { |
| | | flag := "修改成功" |
| | | var hosts Hosts |
| | | c.BindJSON(&hosts) |
| | | nodeInfos, err := getEsClusterInfors(hosts.OldIp) |
| | | var nodeType string |
| | | if err != nil { |
| | | logger.Fatal(err) |
| | | util.ResponseFormat(c, code.QueryClusterInfoErr, err) |
| | | } |
| | | newMasterHosts := make([]string, 0) |
| | | allHosts := make([]string, 0) |
| | |
| | | |
| | | if nodeType == "master" { |
| | | str1 := "sed -ie 's/network.host: " + hosts.OldIp + "/network.host: " + hosts.NewIp + "/g' /opt/elasticsearch/config/elasticsearch.yml" |
| | | runScript(str1) |
| | | msg1 := runScript(str1) |
| | | if msg1 == "运行失败" { |
| | | flag = "修改配置文件失败" |
| | | } |
| | | for i, host := range newMasterHosts { |
| | | if host == hosts.OldIp { |
| | | newMasterHosts[i] = hosts.NewIp |
| | |
| | | outs := strings.Replace(ots, "\"", "\\\"", -1) |
| | | oldUnicastHost := "\\" + strings.Replace(outs, "]", "\\]", -1) |
| | | str2 := "sed -ie 's/discovery.zen.ping.unicast.hosts: " + oldUnicastHost + "/discovery.zen.ping.unicast.hosts: " + newUnicastHost + "/g' /opt/elasticsearch/config/elasticsearch.yml" |
| | | runScript(str2) |
| | | msg2 := runScript(str2) |
| | | if msg2 == "运行失败" { |
| | | flag = "修改配置文件失败" |
| | | } |
| | | for _, host := range allHosts { |
| | | str3 := "sshpass -p \"123\" ssh basic@" + host + " \"cd /opt/elasticsearch/config ; " + str2 + " ; cat elasticsearch.yml\"" |
| | | runScript(str3) |
| | | msg := runScript(str3) |
| | | if msg == "运行失败" { |
| | | flag = "修改配置文件失败" |
| | | } |
| | | } |
| | | } else { |
| | | str1 := "sed -ie 's/network.host: " + hosts.OldIp + "/network.host: " + hosts.NewIp + "/g' /opt/elasticsearch/config/elasticsearch.yml" |
| | | runScript(str1) |
| | | msg1 := runScript(str1) |
| | | if msg1 == "运行失败" { |
| | | flag = "修改配置文件失败" |
| | | } |
| | | } |
| | | if flag == "修改配置文件失败" { |
| | | util.ResponseFormat(c, code.UpdateFail, flag) |
| | | } |
| | | util.ResponseFormat(c, code.Success, flag) |
| | | |
| | | } |
| | | |
| | | type Hosts struct { |