自动化脚本腾讯云配置集群(三)批量修改host
生活随笔
收集整理的這篇文章主要介紹了
自动化脚本腾讯云配置集群(三)批量修改host
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在搭建hadoop或者spark集群之前,可能需要對集群中節點的別名重新命名,方便集群的管理。例如hosts文件中,將節點的IP對應成master和slave1等。如下
# hosts 127.0.0.1 localhost localhost.localdomain 10.135.72.89 master 10.135.82.197 slave1 10.104.73.51 slave2類似于上述對hosts文件的修改。首先我們在master節點上創建一個新的hosts文件,用來記錄更新的hosts文件,方便之后自動化替換各節點的系統hosts文件。
步驟介紹:
1. master節點上,根據集群IP信息,創建hosts文件。
2. 將該hosts文件分發到從節點。
3. 在各個從節點上,替換系統hosts文件為更新后的hosts文件
host文件
以下是筆者根據自己的集群創建的hosts文件
expect_host.sh腳本
主要功能:通過命令登錄到從節點機器,并切換至從節點的root用戶,在使用root權限替換hosts文件。該腳本將作為功能模塊在root_hosts.sh文件中執行。
#!/usr/bin/expect # expect expect_hosts.sh 10.135.82.197 ubuntu ubuntu123456 #執行命令與參數樣例set timeout 1 #set host "10.186.2.84" #set username "ubuntu" #set password "ubuntu123456" set host [lindex $argv 0] set username [lindex $argv 1] set password [lindex $argv 2]spawn ssh $username@$host expect {"Are you sure you want to continue connecting (yes/no)?" {send "yes\r"; exp_continue}"*password*" {send "$password\r"} }expect "*$" send "sudo passwd root\r" expect "*password*" {send "123456\r"} expect "*password*" {send "123456\r"}expect "*$" send "su - root\r" expect "Password:" {send "123456\r"}expect "*#" send "cat /home/ubuntu/myscript/hosts > /etc/hosts\r"expect interactexpect EOFroot_hosts.sh腳本
主要功能:在master上直接運行該腳本,并能完成登錄到各個從節點,并替換從節點系統的hosts文件。
#!/bin/bash nodes=($(awk "{print \$1}" slavenodes)) for node in ${nodes[*]} dossh ubuntu@$node "mkdir -p /home/ubuntu/myscript/"rsync -r --progress ~/myscript/hosts ubuntu@$node:/home/ubuntu/myscript/hostsexpect expect_hosts.sh $node ubuntu ubuntu123456 done總結
以上是生活随笔為你收集整理的自动化脚本腾讯云配置集群(三)批量修改host的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 动漫APP软件研发
- 下一篇: 征信的用途以及提升途径