- ติดตั้งจาก Scrip ไม่ได้ ต้อง Download มาติดตั้งเอง Manual ดู Code ที่ไฟล์ sv.sh ดั้งนี้
- #! /bin/bash
- if [ $(whoami) = "root" ]; then
- cd /tmp
- SELECT=1
- LOOP=0
- else
- whiptail --title "UOE-Server VM Solution (v.1.0)" --msgbox "Please try running this script again as root" 10 70
- exit
- fi
- while [ "$SELECT" = "1" ]
- do
- if [ "$LOOP" = "0" ]; then
- OPTION=$(whiptail --title "UOE-Server VM Solution (v.1.0)" --menu "Please Select Module for Ubuntu Server 14.04" 15 60 7 1. "Install All Module for Server" 2. "Mini GUI Server" 3. "Webmin Control Panel" 4. "Monitorix (Host Monitering)" 5. "VirtualBox (VM Server)" 6. "PHPVirtualBox (VM Web Control)" 7. "VboxHA (High Availability)" 3>&2 2>&1 1>&3)
- rm -rf *.deb
- clear
- else
- if [ "$OPTION" = "1." ]; then
- OPTION="2."
- elif [ "$OPTION" = "2." ]; then
- OPTION="3."
- elif [ "$OPTION" = "3." ]; then
- OPTION="4."
- elif [ "$OPTION" = "4." ]; then
- OPTION="5."
- elif [ "$OPTION" = "5." ]; then
- OPTION="6."
- elif [ "$OPTION" = "6." ]; then
- OPTION="7."
- LOOP=0
- fi
- fi
- case "$OPTION" in
- "1.") echo "---------- Install All Module for Server ----------"
- LOOP=1
- ;;
- "2.") echo "---------- Mini GUI Server ----------"
- aptitude -y install openssh-server
- aptitude -y install lubuntu-core chromium-browser lxterminal leafpad lxrandr xarchiver pmount policykit-1 synaptic htop iotop nmon --without-recommends
- aptitude -y install pepperflashplugin-nonfree && update-pepperflashplugin-nonfree --install
- ;;
- "3.") echo "---------- Webmin Control Panel ----------"
- wget -c "http://downloads.sourceforge.net/project/webadmin/webmin/1.700/webmin_1.700_all.deb"
- dpkg -i webmin*.deb
- apt-get install -y -f
- ;;
- "4.") echo "---------- Monitorix (Host Monitering) ----------"
- wget -c "http://www.monitorix.org/monitorix_3.7.0-izzy1_all.deb"
- dpkg -i monitorix*.deb
- apt-get install -y -f
- ;;
- "5.") echo "---------- VirtualBox (VM Server) ----------"
- wget -c "http://download.virtualbox.org/virtualbox/4.3.16/virtualbox-4.3_4.3.16-95972~Ubuntu~raring_amd64.deb"
- aptitude -y install make gcc
- dpkg -i virtualbox*.deb
- apt-get install -y -f
- wget -c "http://download.virtualbox.org/virtualbox/4.3.16/Oracle_VM_VirtualBox_Extension_Pack-4.3.16.vbox-extpack"
- VBoxManage extpack install *.vbox-extpack
- if [ `grep -c VBOXSTATUS /etc/rc.local` = 0 ]; then
- sed -i 's/exit 0//g' /etc/rc.local
- echo 'VBOXSTATUS=$(/etc/init.d/vboxdrv status)' >> /etc/rc.local
- echo 'if [ "$VBOXSTATUS" = "VirtualBox kernel module is not loaded." ]; then' >> /etc/rc.local
- echo '/etc/init.d/vboxdrv setup' >> /etc/rc.local
- echo 'reboot' >> /etc/rc.local
- echo 'fi' >> /etc/rc.local
- echo 'exit 0' >> /etc/rc.local
- fi
- ;;
- "6.") echo "---------- PHPVirtualBox (VM Web Control) ----------"
- aptitude -y install php5
- service apache2 restart
- wget "http://downloads.sourceforge.net/project/phpvirtualbox/phpvirtualbox-4.3-1.zip" -O phpvirtualbox.zip
- unzip phpvirtualbox.zip -d /var/www/html
- mv /var/www/html/phpvirtualbox-4.3-1 /var/www/html/vbox
- UNAME=$(whiptail --title "PHPVirtualBox (step 1/3)" --inputbox "User Name" 8 70 `grep 1000:1000 /etc/passwd | awk -F : '{print $1}'` 3>&1 1>&2 2>&3)
- PASS1=$(whiptail --title "PHPVirtualBox (step 2/3)" --passwordbox "Password" 8 70 3>&1 1>&2 2>&3)
- PASS2=$(whiptail --title "PHPVirtualBox (step 3/3)" --passwordbox "Re-enter Password" 8 70 3>&1 1>&2 2>&3)
- while [ "$PASS1" != "$PASS2" ]
- do
- MSGBOX=$(whiptail --title "PHPVirtualBox (error)" --msgbox "(ERROR) Password does not match!" 8 70 `grep 1000:1000 /etc/passwd | awk -F : '{print $1}'` 3>&1 1>&2 2>&3)
- PASS1=$(whiptail --title "PHPVirtualBox (step 2/3)" --passwordbox "Password" 8 70 3>&1 1>&2 2>&3)
- PASS2=$(whiptail --title "PHPVirtualBox (step 3/3)" --passwordbox "Re-enter Password" 8 70 3>&1 1>&2 2>&3)
- done
- CONF1=$(grep -n \'vbox' "/var/www/html/vbox/config.php-example" | awk -F : '{print $1 - 1}')
- CONF2=$(grep -n 'vbox' "/var/www/html/vbox/config.php-example" | awk -F : '{print $1 + 2}')
- head -n $CONF1 "/var/www/html/vbox/config.php-example" > "/var/www/html/vbox/config.php"
- echo "var \$username='$UNAME';" >> "/var/www/html/vbox/config.php"
- echo "var \$password='$PASS1';" >> "/var/www/html/vbox/config.php"
- tail -n +$CONF2 "/var/www/html/vbox/config.php-example" >> "/var/www/html/vbox/config.php"
- echo "VBOXWEB_USER=$UNAME" > "/etc/default/virtualbox"
- /etc/init.d/vboxweb-service start
- ;;
- "7.") echo "---------- VboxHA (High Availability) ----------"
- aptitude -y install drbd8-utils pv
- CONFIRM=0
- UNAME=$(grep 1000:1000 /etc/passwd | awk -F : '{print $1}')
- while [ "$CONFIRM" = "0" ]
- do
- MYINDEX=$(whiptail --title "VboxHA (step 1/7)" --inputbox "Index for this server (1 or 2)" 8 70 3>&1 1>&2 2>&3)
- MYHOST=$(whiptail --title "VboxHA (step 2/7)" --inputbox "Hostname for this server" 8 70 `uname -n` 3>&1 1>&2 2>&3)
- MYIP=$(whiptail --title "VboxHA (step 3/7)" --inputbox "IP Address for this server" 8 70 `ifconfig | grep "inet addr" | head -n 1 | awk -F : '{print $2}' | awk '{print $1}'` 3>&1 1>&2 2>&3)
- MYDISK=$(whiptail --title "VboxHA (step 4/7)" --inputbox "Partition for run guest-os on this server" 8 70 3>&1 1>&2 2>&3)
- BKHOST=$(whiptail --title "VboxHA (step 5/7))" --inputbox "Hostname for backup server" 8 70 3>&1 1>&2 2>&3)
- BKIP=$(whiptail --title "VboxHA (step 6/7)" --inputbox "IP Address for backup server" 8 70 3>&1 1>&2 2>&3)
- BKDISK=$(whiptail --title "VboxHA (step 7/7)" --inputbox "Partition for backup guest-os on this server" 8 70 3>&1 1>&2 2>&3)
- if (whiptail --title "VboxHA (High Availability)" --yesno "Confirm your settings." --yes-button "Yes" --no-button "Back" 8 70) then
- CONFIRM=1
- else
- CONFIRM=0
- fi
- done
- if [ "$MYINDEX" = "1" ]; then
- echo "#Index $MYINDEX" > /etc/drbd.conf
- echo "global { usage-count no; }" >> /etc/drbd.conf
- echo "common { syncer { rate 100M; } }" >> /etc/drbd.conf
- echo "resource r1 { protocol C; startup { wfc-timeout 30; degr-wfc-timeout 120; }" >> /etc/drbd.conf
- echo "net { cram-hmac-alg sha1; shared-secret "vboxha"; }" >> /etc/drbd.conf
- echo "on $MYHOST { device /dev/drbd1; disk $MYDISK; address $MYIP:7781; meta-disk internal; }" >> /etc/drbd.conf
- echo "on $BKHOST { device /dev/drbd1; disk $MYDISK; address $BKIP:7781; meta-disk internal; } }" >> /etc/drbd.conf
- echo "resource r2 { protocol C; startup { wfc-timeout 30; degr-wfc-timeout 120; }" >> /etc/drbd.conf
- echo "net { cram-hmac-alg sha1; shared-secret "vboxha"; }" >> /etc/drbd.conf
- echo "on $MYHOST { device /dev/drbd2; disk $BKDISK; address $MYIP:7782; meta-disk internal; }" >> /etc/drbd.conf
- echo "on $BKHOST { device /dev/drbd2; disk $BKDISK; address $BKIP:7782; meta-disk internal; } }" >> /etc/drbd.conf
- elif [ "$MYINDEX" = "2" ]; then
- echo "#Index $MYINDEX" > /etc/drbd.conf
- echo "global { usage-count no; }" >> /etc/drbd.conf
- echo "common { syncer { rate 100M; } }" >> /etc/drbd.conf
- echo "resource r1 { protocol C; startup { wfc-timeout 30; degr-wfc-timeout 120; }" >> /etc/drbd.conf
- echo "net { cram-hmac-alg sha1; shared-secret "vboxha"; }" >> /etc/drbd.conf
- echo "on $MYHOST { device /dev/drbd1; disk $BKDISK; address $MYIP:7781; meta-disk internal; }" >> /etc/drbd.conf
- echo "on $BKHOST { device /dev/drbd1; disk $BKDISK; address $BKIP:7781; meta-disk internal; } }" >> /etc/drbd.conf
- echo "resource r2 { protocol C; startup { wfc-timeout 30; degr-wfc-timeout 120; }" >> /etc/drbd.conf
- echo "net { cram-hmac-alg sha1; shared-secret "vboxha"; }" >> /etc/drbd.conf
- echo "on $MYHOST { device /dev/drbd2; disk $MYDISK; address $MYIP:7782; meta-disk internal; }" >> /etc/drbd.conf
- echo "on $BKHOST { device /dev/drbd2; disk $MYDISK; address $BKIP:7782; meta-disk internal; } }" >> /etc/drbd.conf
- fi
- if [ `grep -c $BKHOST /etc/hosts` = 0 ]; then
- head -n 2 /etc/hosts > /tmp/hosts
- echo "$BKIP $BKHOST" >> /tmp/hosts
- tail -n +3 /etc/hosts >> /tmp/hosts
- cat /tmp/hosts > /etc/hosts
- fi
- update-rc.d -f vboxweb-service remove
- service drbd stop
- pv -tpreb /dev/zero | dd of=$MYDISK bs=1M count=128
- pv -tpreb /dev/zero | dd of=$BKDISK bs=1M count=128
- drbdadm create-md r1
- drbdadm create-md r2
- service drbd start
- drbdadm -- --overwrite-data-of-peer primary r$MYINDEX
- mkdir -p /home/$UNAME/virtualbox/1
- mkdir -p /home/$UNAME/virtualbox/2
- mkfs.ext4 /dev/drbd$MYINDEX
- mount /dev/drbd$MYINDEX /home/$UNAME/virtualbox/$MYINDEX && mkdir -p /home/$UNAME/virtualbox/$MYINDEX/guest
- chmod 777 /home/$UNAME/virtualbox/$MYINDEX/guest
- wget http://goo.gl/BW2ZAq -O /usr/bin/vboxha.sh
- chmod 755 /usr/bin/vboxha.sh
- if [ `grep -c vboxha.sh /etc/rc.local` = 0 ]; then
- sed -i 's/exit 0//g' /etc/rc.local
- echo '/usr/bin/vboxha.sh &' >> /etc/rc.local
- echo 'exit 0' >> /etc/rc.local
- fi
- ;;
- *) echo "---------- Exit ----------"
- SELECT=0
- ;;
- esac
- if [ "$SELECT" = "1" ] && [ "$LOOP" = "0" ]; then
- if (whiptail --title "UOE-Server VM Solution (v.1.0)" --yesno "Install Succeeded" --yes-button "Main menu." --no-button "Finish" 8 70) then
- SELECT=1
- else
- SELECT=0
- fi
- fi
- done
- clear
- exit
1. download ไฟล์จาก https://sourceforge.net/projects/phpvirtualbox/files/ เลือกติดตั้งให้ตรงกับ Virtual Box ที่เราลง เช่นลง 4.3 ก็โหลด 4.3 หรือ 5 ก็โหลด 5
2. ติดตั้ง php5
- apt-get install php5
restart apache
- service apache2 restart
3. copy file phpvirtualbox.zip ที่โหลดมาได้จาก ข้อ 1. ไปไว้ที่ /var/www/html
4. แตกไฟล์ unzip ด้วยการติดตั้งโปรแกรม unzip ก่อน
- sudo apt-get install unp
5. แตกไฟล์ด้วยคำสั่ง
- unp phpvirtualbox-4.3-3.zip
6. เปลี่ยนชื่อ Folder เป็น vbox
7. เปลี่ยนชื่อไฟล์ config.php-example ให้เป็น config.php
8. แก้ไฟล์ config.php ดังนี้
/* Username / Password for system user that runs VirtualBox */
var $username = 'sa'; // user ที่ติดตั้ง guest
var $password = '123'; // password ที่ติดตั้ง guest
// Host / ip to use for console connections
#var $consoleHost = '192.168.1.22'; // IP Host
8. ทดลอง login ผ่าน http://192.168.2.22/vbox/
user name : password default คือ admin : admin
ไม่มีความคิดเห็น:
แสดงความคิดเห็น