Advertisement
Guest User

Untitled

a guest
Apr 15th, 2014
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.55 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3.  
  4. function init_vars() {
  5. date=`date +%Y%m%d%H%M%S`
  6.  
  7. KVM_NODE_IP=192.168.1.213
  8. KVM_NODE_MASK=255.255.255.0
  9. KVM_NODE_NET=192.168.1.0
  10. KVM_NODE_GW=192.168.1.1
  11. KVM_NODE_BC=192.168.1.255
  12. KVM_NODE_NAME=kvm01
  13. KVM_FQDN_NODE_NAME=kvm01.nicopolis.local
  14.  
  15. DNS_PRIMARY=192.168.1.202
  16. DNS_SECONDARY= 192.168.1.203
  17. DNS_SEARCH=nicopolis.local
  18.  
  19. echo "=> Deploying KVM + Cloudstack to $KVM_NODE_IP ($KVM_FQDN_NODE_NAME)"
  20. echo "=> Cloudstack will need to be completely uninstalled beforehand."
  21. read -p "=> Continue? [ynq]" yn
  22. case $yn in
  23. [Yy]* ) return; echo " ";;
  24. [NnQq]* ) exit;;
  25. * ) echo "Please answer y or n.";;
  26. esac
  27. }
  28.  
  29.  
  30. function enable_root() {
  31. echo "=> Enabling root, please specify password."
  32. sudo passwd root
  33. echo " "
  34. }
  35.  
  36. function teardown() {
  37. echo "=> Tearing down the previous installation.."
  38. service libvirt-bin stop
  39. service cloudstack-agent stop
  40. apt-get -y purge jsvc cloudstack-agent cloudstack-common libvirt-bin
  41. rm -rf /var/log/cloudstack
  42. rm -rf /etc/cloudstack
  43. }
  44.  
  45. function configure_networking() {
  46. echo "=> Backing up network configuration..."
  47. cp /etc/network/interfaces /etc/network/interfaces-$date.backup
  48. echo "=> Backing up hosts file..."
  49. cp /etc/hosts /etc/hosts-$date.backup
  50. echo "=> Backing up hostname..."
  51. cp /etc/hostname /etc/hostname-$date.backup
  52. echo "=> Configuring hostname..."
  53. cat > /etc/hostname << _EOF_
  54. $KVM_NODE_NAME
  55. _EOF_
  56. hostname -b -F /etc/hostname
  57. echo "=> Configuring networking"
  58. cat > /etc/network/interfaces << _EOF_
  59. auto lo
  60. iface lo inet loopback
  61.  
  62. auto eth0
  63. iface eth0 inet manual
  64.  
  65. # Management
  66. auto cloudbr0
  67. iface cloudbr0 inet static
  68. address $KVM_NODE_IP
  69. netmask $KVM_NODE_MASK
  70. network $KVM_NODE_NET
  71. broadcast $KVM_NODE_BC
  72. gateway $KVM_NODE_GW
  73. dns-nameservers $DNS_PRIMARY $DNS_SECONDARY
  74. dns-search $DNS_SEARCH
  75. bridge_ports eth0
  76. bridge_fd 5
  77. bridge_stp off
  78. bridge_maxwait 1
  79.  
  80. # Other
  81.  
  82. _EOF_
  83. echo "=> Done configuring networking."
  84. }
  85.  
  86. function set_firewall ()
  87. {
  88. echo "=> Setting up Ubuntu's simple firewall..."
  89. ufw allow proto tcp from any to any port 22
  90. ufw allow proto tcp from any to any port 1798
  91. ufw allow proto tcp from any to any port 16509
  92. ufw allow proto tcp from any to any port 5900:6100
  93. ufw allow proto tcp from any to any port 49152:49216
  94. ufw disable
  95. }
  96.  
  97. function ubuntu_update ()
  98. {
  99. echo "=> Prepare the Cloudstack repository."
  100. cat > /etc/apt/sources.list.d/cloudstack.list << _EOF_
  101. deb http://packages.ntghost.com/deb/cloudstack saucy main
  102. _EOF_
  103. echo "=> Updating and upgrading"
  104. apt-get -y update
  105. apt-get -y upgrade
  106. }
  107. function install_packages () {
  108. echo "=> Installing needed packages"
  109. apt-get -y --force-yes install vlan ifenslave nfs-common cloudstack-agent htop screen vim-
  110.  
  111. nox git curl zsh
  112. tasksel install virt-host
  113. }
  114.  
  115. function configure_utilities () {
  116. echo "=> Configuring utilities"
  117. curl -L https://raw.github.com/Arkaniad/oh-my-zsh/master/tools/install.sh | sh
  118. cat > /root/.vimrc << _EOF_
  119. syntax on
  120. set number
  121. set expandtab
  122. set tabstop=2
  123. _EOF_
  124. }
  125.  
  126. function configure_libvirt () {
  127. echo "=> Backing up libvirt files"
  128. cp /etc/libvirt/qemu.conf /etc/libvirt/qemu.conf-$date.backup
  129. cp /etc/libvirt/libvirtd.conf /etc/libvirt/libvirtd.conf-$date.backup
  130. echo "=> Configuring libvirtd"
  131. sed -i 's/-d/-d -l/g' /etc/default/libvirt-bin
  132. sed -i 's/#vnc_listen \= \"0.0.0.0\"/vnc_listen \= \"0.0.0.0\"/g' /etc/libvirt/qemu.conf
  133. sed -i 's/#listen_tls \= 0/listen_tls \= 0/g' /etc/libvirt/libvirtd.conf
  134. sed -i 's/#listen_tcp \= 0/listen_tcp \= 0/g' /etc/libvirt/libvirtd.conf
  135. sed -i 's/#auth_tcp \= \"sasl\"/auth_tcp \= \"none\"/g' /etc/libvirt/libvirtd.conf
  136. echo "=> Restarting libvirt"
  137. service libvirt-bin restart
  138. }
  139.  
  140. function prepare_apparmor () {
  141. dpkg --list 'apparmor'
  142. echo "=> Loosening AppArmor restrictions.."
  143. ln -s /etc/apparmor.d/usr.sbin.libvirtd /etc/apparmor.d/disable/
  144. ln -s /etc/apparmor.d/usr.lib.libvirt.virt-aa-helper /etc/apparmor.d/disable/
  145. apparmor_parser -R /etc/apparmor.d/usr.sbin.libvirtd
  146. apparmor_parser -R /etc/apparmor.d/usr.lib.libvirt.virt-aa-helper
  147. }
  148.  
  149. function rollup() {
  150. echo "=> Housekeeping tasks..."
  151. service dbus start
  152. service libvirt-bin restart
  153. service cloudstack-agent restart
  154. }
  155.  
  156. init_vars
  157. enable_root
  158. teardown
  159. configure_bonding
  160. configure_networking
  161. set_firewall
  162. ubuntu_update
  163. install_packages
  164. configure_utilities
  165. configure_libvirt
  166. prepare_apparmor
  167. rollup
  168. echo " "
  169. echo "All done. Reboot and plug into trunk ports."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement