Fakultas Ilmu Komputer UI

Commit 1d7138b3 authored by Ardhi Putra Pratama's avatar Ardhi Putra Pratama
Browse files

Add extra stuff on cluster management

parent fa513508
require 'fileutils'
Vagrant.require_version ">= 1.6.0"
# Defaults for config options defined in CONFIG
$num_instances = 3
$instance_name_prefix = "cl-ardhi"
$enable_serial_logging = false
$share_home = true
$vm_gui = false
$vm_memory = 3072
$vm_cpus = 2
$forwarded_ports = {}
# Attempt to apply the deprecated environment variable NUM_INSTANCES to
# $num_instances while allowing config.rb to override it
if ENV["NUM_INSTANCES"].to_i > 0 && ENV["NUM_INSTANCES"]
$num_instances = ENV["NUM_INSTANCES"].to_i
end
def vm_gui
$vb_gui.nil? ? $vm_gui : $vb_gui
end
def vm_memory
$vb_memory.nil? ? $vm_memory : $vb_memory
end
def vm_cpus
$vb_cpus.nil? ? $vm_cpus : $vb_cpus
end
Vagrant.configure("2") do |config|
# always use Vagrants insecure key
config.ssh.insert_key = false
config.vm.box = "ubuntu/xenial64"
# enable hostmanager
config.hostmanager.enabled = true
# configure the host's /etc/hosts
config.hostmanager.manage_host = true
(1..$num_instances).each do |i|
config.vm.define vm_name = "%s-%02d" % [$instance_name_prefix, i] do |config|
config.vm.hostname = vm_name
if $enable_serial_logging
logdir = File.join(File.dirname(__FILE__), "log")
FileUtils.mkdir_p(logdir)
serialFile = File.join(logdir, "%s-serial.txt" % vm_name)
FileUtils.touch(serialFile)
config.vm.provider :virtualbox do |vb, override|
vb.customize ["modifyvm", :id, "--uart1", "0x3F8", "4"]
vb.customize ["modifyvm", :id, "--uartmode1", serialFile]
end
end
$forwarded_ports.each do |guest, host|
config.vm.network "forwarded_port", guest: guest, host: host, auto_correct: true
end
config.vm.provider :virtualbox do |vb|
vb.gui = vm_gui
vb.memory = vm_memory
vb.cpus = vm_cpus
end
ip = "172.17.10.#{i+100}"
config.vm.network :private_network, ip: ip
end
end
end
#!/bin/bash
username=$1
password=$2
p_headnode="PASSWORD HEAD"
u_headnode="USERNAME HEAD"
hosts=(cluster01 cluster03 cluster04 cluster05 cluster06)
# end of configuration
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
mkdir /var/mirror/user/$username
for hostname in ${hosts[@]}
do
ssh -t $u_headnode@$hostname "echo $p_headnode | sudo -S useradd -m -p $pass -s /bin/bash $username;"
sshpass -p "$password" ssh -o StrictHostKeyChecking=no -t $username@$hostname "ssh-keygen -f /home/$username/.ssh/id_rsa -t rsa -N '';"
done
for mehost in ${hosts[@]}
do
for hostname in ${hosts[@]}
do
sshpass -p "$password" ssh -t -o "StrictHostKeyChecking no" $username@$mehost "sshpass -p $password ssh-copy-id -o 'StrictHostKeyChecking no' $username@$hostname"
done
done
echo $p_headnode | sudo -S chown -R $username:$username /var/mirror/user/$username
exit 0
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment