Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- function init_vars() {
- date=`date +%Y%m%d%H%M%S`
- KVM_NODE_IP=192.168.1.213
- KVM_NODE_MASK=255.255.255.0
- KVM_NODE_NET=192.168.1.0
- KVM_NODE_GW=192.168.1.1
- KVM_NODE_BC=192.168.1.255
- KVM_NODE_NAME=kvm01
- KVM_FQDN_NODE_NAME=kvm01.nicopolis.local
- DNS_PRIMARY=192.168.1.202
- DNS_SECONDARY= 192.168.1.203
- DNS_SEARCH=nicopolis.local
- echo "=> Deploying KVM + Cloudstack to $KVM_NODE_IP ($KVM_FQDN_NODE_NAME)"
- echo "=> Cloudstack will need to be completely uninstalled beforehand."
- read -p "=> Continue? [ynq]" yn
- case $yn in
- [Yy]* ) return; echo " ";;
- [NnQq]* ) exit;;
- * ) echo "Please answer y or n.";;
- esac
- }
- function enable_root() {
- echo "=> Enabling root, please specify password."
- sudo passwd root
- echo " "
- }
- function teardown() {
- echo "=> Tearing down the previous installation.."
- service libvirt-bin stop
- service cloudstack-agent stop
- apt-get -y purge jsvc cloudstack-agent cloudstack-common libvirt-bin
- rm -rf /var/log/cloudstack
- rm -rf /etc/cloudstack
- }
- function configure_networking() {
- echo "=> Backing up network configuration..."
- cp /etc/network/interfaces /etc/network/interfaces-$date.backup
- echo "=> Backing up hosts file..."
- cp /etc/hosts /etc/hosts-$date.backup
- echo "=> Backing up hostname..."
- cp /etc/hostname /etc/hostname-$date.backup
- echo "=> Configuring hostname..."
- cat > /etc/hostname << _EOF_
- $KVM_NODE_NAME
- _EOF_
- hostname -b -F /etc/hostname
- echo "=> Configuring networking"
- cat > /etc/network/interfaces << _EOF_
- auto lo
- iface lo inet loopback
- auto eth0
- iface eth0 inet manual
- # Management
- auto cloudbr0
- iface cloudbr0 inet static
- address $KVM_NODE_IP
- netmask $KVM_NODE_MASK
- network $KVM_NODE_NET
- broadcast $KVM_NODE_BC
- gateway $KVM_NODE_GW
- dns-nameservers $DNS_PRIMARY $DNS_SECONDARY
- dns-search $DNS_SEARCH
- bridge_ports eth0
- bridge_fd 5
- bridge_stp off
- bridge_maxwait 1
- # Other
- _EOF_
- echo "=> Done configuring networking."
- }
- function set_firewall ()
- {
- echo "=> Setting up Ubuntu's simple firewall..."
- ufw allow proto tcp from any to any port 22
- ufw allow proto tcp from any to any port 1798
- ufw allow proto tcp from any to any port 16509
- ufw allow proto tcp from any to any port 5900:6100
- ufw allow proto tcp from any to any port 49152:49216
- ufw disable
- }
- function ubuntu_update ()
- {
- echo "=> Prepare the Cloudstack repository."
- cat > /etc/apt/sources.list.d/cloudstack.list << _EOF_
- deb http://packages.ntghost.com/deb/cloudstack saucy main
- _EOF_
- echo "=> Updating and upgrading"
- apt-get -y update
- apt-get -y upgrade
- }
- function install_packages () {
- echo "=> Installing needed packages"
- apt-get -y --force-yes install vlan ifenslave nfs-common cloudstack-agent htop screen vim-
- nox git curl zsh
- tasksel install virt-host
- }
- function configure_utilities () {
- echo "=> Configuring utilities"
- curl -L https://raw.github.com/Arkaniad/oh-my-zsh/master/tools/install.sh | sh
- cat > /root/.vimrc << _EOF_
- syntax on
- set number
- set expandtab
- set tabstop=2
- _EOF_
- }
- function configure_libvirt () {
- echo "=> Backing up libvirt files"
- cp /etc/libvirt/qemu.conf /etc/libvirt/qemu.conf-$date.backup
- cp /etc/libvirt/libvirtd.conf /etc/libvirt/libvirtd.conf-$date.backup
- echo "=> Configuring libvirtd"
- sed -i 's/-d/-d -l/g' /etc/default/libvirt-bin
- sed -i 's/#vnc_listen \= \"0.0.0.0\"/vnc_listen \= \"0.0.0.0\"/g' /etc/libvirt/qemu.conf
- sed -i 's/#listen_tls \= 0/listen_tls \= 0/g' /etc/libvirt/libvirtd.conf
- sed -i 's/#listen_tcp \= 0/listen_tcp \= 0/g' /etc/libvirt/libvirtd.conf
- sed -i 's/#auth_tcp \= \"sasl\"/auth_tcp \= \"none\"/g' /etc/libvirt/libvirtd.conf
- echo "=> Restarting libvirt"
- service libvirt-bin restart
- }
- function prepare_apparmor () {
- dpkg --list 'apparmor'
- echo "=> Loosening AppArmor restrictions.."
- ln -s /etc/apparmor.d/usr.sbin.libvirtd /etc/apparmor.d/disable/
- ln -s /etc/apparmor.d/usr.lib.libvirt.virt-aa-helper /etc/apparmor.d/disable/
- apparmor_parser -R /etc/apparmor.d/usr.sbin.libvirtd
- apparmor_parser -R /etc/apparmor.d/usr.lib.libvirt.virt-aa-helper
- }
- function rollup() {
- echo "=> Housekeeping tasks..."
- service dbus start
- service libvirt-bin restart
- service cloudstack-agent restart
- }
- init_vars
- enable_root
- teardown
- configure_bonding
- configure_networking
- set_firewall
- ubuntu_update
- install_packages
- configure_utilities
- configure_libvirt
- prepare_apparmor
- rollup
- echo " "
- echo "All done. Reboot and plug into trunk ports."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement