コード例 #1
0
 public void configHostName() throws IOException {
   expect.sendLine("echo '' > /etc/hosts");
   ready(ROOT_USER);
   for (HostInfo info : BuildEnv.ALL_HOST) {
     expect.sendLine("echo '" + info.getIp() + " " + info.getHostName() + "' >> /etc/hosts");
     ready(ROOT_USER);
   }
 }
コード例 #2
0
 public void copyConfig(boolean isFirst) throws IOException, TemplateException {
   genServerConfFile();
   expect.sendLine(
       "\\cp -f /vagrant/src/main/resources/template/server.cnf."
           + hostInfo.getHostName()
           + " /etc/my.cnf.d/server.cnf");
   ready(ROOT_USER);
   if (isFirst) {
     configMariaDBFirst();
   }
 }
コード例 #3
0
  public void genServerConfFile() throws IOException, TemplateException {
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
    cfg.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);
    cfg.setClassForTemplateLoading(this.getClass(), "/");
    Template template = cfg.getTemplate("template/galera_server.ftl");

    // Build the data-model
    Map<String, Object> data = new HashMap<>();
    data.put("ownHostInfo", hostInfo);
    data.put("otherHostInfos", otherHostInfo);
    // Console output
    String path = getClass().getClassLoader().getResource("").getFile();
    FileWriter out = new FileWriter(path + "/template/server.cnf." + hostInfo.getHostName());
    template.process(data, out);
    out.flush();
    out.close();
  }
コード例 #4
0
 public void configSSH(String user) throws IOException {
   System.out.println("~~~~~~~~~~~~~configSSH  start~~~~~~~~~~~~~~");
   this.expect.sendLine("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa");
   ready(user);
   this.expect.sendLine("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys");
   ready(user);
   this.expect.sendLine("\\cp -f /vagrant/src/main/resources/ssh/config ~/.ssh");
   ready(user);
   for (HostInfo hi : otherHostInfo) {
     String copyId = "ssh-copy-id -i ~/.ssh/id_rsa.pub " + user + "@" + hi.getHostName();
     this.expect.sendLine(copyId);
     ready(user);
   }
   this.expect.sendLine("chmod 700 -R ~/.ssh");
   ready(user);
   System.out.println("~~~~~~~~~~~~~configSSH  成功~~~~~~~~~~~~~~");
 }
コード例 #5
0
 private void ready(String user) throws IOException {
   expect.expect(contains(user + "@" + hostInfo.getHostName()));
   System.out.flush();
 }