Multiple changes to save on disk and memory usage

This commit is contained in:
Mark Korondi 2017-04-28 14:13:08 +02:00
parent 73228ec51a
commit 1c0c006904
14 changed files with 153 additions and 75 deletions

24
CHANGELOG.md Normal file
View File

@ -0,0 +1,24 @@
# Change Log
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
## [Unreleased]
### Changed
- Image is now based on Ubuntu Xenial 16.04 LTS
- Image download is much smaller, around 1.1G (was ~2G)
- VM runs on less memory (minimum 4G, recommended 6G)
- Default user is now ubuntu, password is openstack
- HexChat instead of XChat
- Project renamed to Upstream Institute ;-)
### Added
- `cleanup.sh` script that helps shrinking the image
### Fixed
- There's no need to fiddle with network settings anymore
[Unreleased]: https://github.com/kmarc/openstack-training-virtual-environment/compare/v2016.02...HEAD

View File

@ -17,7 +17,7 @@ right place.
### What do I need?
* 6GB of **free** RAM (so at least 8GB in your laptop)
* 5GB of **free** RAM (so at least 8GB in your laptop)
* Recent CPU with at least 4 cores
* 10GB disk space
* [VirtualBox](https://www.virtualbox.org/)
@ -73,6 +73,19 @@ then can be distributed and easily import into VirtualBox
`./create-training-box.sh` is a handy tool that sets up everything with Vagrant
and then creates the distributable box file.
#### Requirements
* `sudo apt install libguestfs-tools`
* [libssl098:i386] is required for vmware vdiskmanager (shrink disks)
```bash
wget http://security.ubuntu.com/ubuntu/ubuntu/pool/universe/o/openssl098/libssl0.9.8_0.9.8o-7ubuntu4_i386.deb
sudo dpkg -i libssl0.9.8_0.9.8o-7ubuntu4_i386.deb
```
[vmvare-vdiskmanager]: https://kb.vmware.com/selfservice/viewAttachment.do?attachID=1023856-vdiskmanager-linux.7.0.1.zip&documentID=1023856
[libssl098:i386]: http://security.ubuntu.com/ubuntu/ubuntu/pool/universe/o/openssl098/
### Learn how to easily set up devstack
* [install-base.sh](install-base.sh) and
@ -86,8 +99,11 @@ After booting up the virtual machine, start setting up devstack. It takes around
10 minutes to finish, until then you can get familiar with the environment the
VM provides you with.
Open up a terminal and run `/opt/devstack/stack.sh`. To reduce memory usage in
your VM, also run `optimize-memory`.
To set up an OpenStack installation with devstack, open a terminal and run:
```bash
/opt/devstack/stack.sh && optimize-memory
```
The four main software you will be using from the desktop during the training
are
@ -116,7 +132,7 @@ default security groups are not modified, so if you want to ping or SSH into
your VM, you need to add the correct security rules (ICMP In/Egress from all,
SSH ingress from all). Also beware that sometimes Horizon logs you in into the
wrong project. To use the private networking by default, you need to log in as
the default `demo` user (password: `admin`) and select `demo` as project.
the default `demo` user (password: `openstack`) and select `demo` as project.
Screenshots
-----------

5
Vagrantfile vendored
View File

@ -2,7 +2,7 @@ Vagrant.configure(2) do |config|
config.vm.hostname = "upstream-training"
config.vm.box = "ubuntu/xenial64"
config.vm.provider "virtualbox" do |vb|
vb.memory = "4608"
vb.memory = "4096"
vb.cpus = 2
vb.name = "upstream-training"
vb.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
@ -10,6 +10,8 @@ Vagrant.configure(2) do |config|
vb.customize ["modifyvm", :id, "--accelerate3d", "on"]
vb.customize ["modifyvm", :id, "--vram", "32"]
vb.customize ["modifyvm", :id, "--natnet1", "192.168.10/24"]
# Xenial COM1 port logging
vb.customize ["modifyvm", :id, "--uartmode1", "disconnected"]
end
config.vm.provision :shell, inline: "/vagrant/install-base.sh",
privileged: false, keep_color: true
@ -22,6 +24,7 @@ Vagrant.configure(2) do |config|
config.vm.provision :shell, inline: "/vagrant/cleanup.sh",
privileged: false, keep_color: true
config.vm.box_check_update = true
config.vm.graceful_halt_timeout = 180
config.ssh.forward_x11 = true
config.ssh.forward_agent = true
end

View File

@ -1,13 +1,31 @@
#!/usr/bin/env bash
# Remove older kernels
OLDS=$(dpkg -l | awk '/linux-image-[0-9]/{ print $2 }' \
| sort -r \
| sed 's/linux-image-\(.*\)-generic/\1/g' \
| tail -n +2)
for old in $OLDS; do
sudo apt autoremove --purge -y ".*$old.*"
done
# Empty user caches
rm -rf ~/.cache
sudo rm -rf /root/.cache
# Remove compiled pyc files
sudo updatedb
for pyc in $(locate -- *.pyc); do
sudo rm -rf "$pyc"
done
sudo updatedb
# Remove unused packages
sudo apt autoremove --purge -y humanity-icon-theme snapd
# Empty packages cache
sudo apt clean
# Remove compiled pyc files
sudo updatedb
for pyc in $(locate *.pyc); do
sudo rm -rf $pyc
done
# Empty user caches
rm -rf ~/.cache/*
# Zero out unused space
dd if=/dev/zero of=~/ZERO bs=1M status=progress
rm -rf ~/ZERO

View File

@ -1,8 +1,23 @@
#!/usr/bin/env bash
VDISKMANAGER_DOWNLOAD='https://kb.vmware.com/selfservice/viewAttachment.do?attachID=1023856-vdiskmanager-linux.7.0.1.zip&documentID=1023856'
vagrant up
vagrant halt
if [[ ! -e dist/vmware-vdiskmanager ]]; then
wget "$VDISKMANAGER_DOWNLOAD" -O /tmp/vmware-vdiskmanager.zip
unzip /tmp/vmware-vdiskmanager.zip -d dist/
mv dist/*vmware-vdiskmanager* dist/vmware-vdiskmanager
fi
VMDK=$(vboxmanage showvminfo upstream-training --machinereadable \
| grep SCSI-0-0 \
| cut -d'"' -f4)
echo "Schrinking image..."
./dist/vmware-vdiskmanager -k "$VMDK"
echo "Creating Virtual Appliance..."
vboxmanage sharedfolder remove upstream-training --name vagrant
vboxmanage export upstream-training \

View File

@ -0,0 +1,2 @@
APT::Install-Suggests "0";
APT::Install-Recommends "0";

View File

@ -11,7 +11,7 @@
#
# By default this script does nothing.
dd if=/dev/zero of=/swap.img bs=1M count=2048 >> /tmp/rc.local.log 2>&1
mkswap /swap.img >> /tmp/rc.local.log 2>&1
swapon /swap.img >> /tmp/rc.local.log 2>&1
dd if=/dev/zero of=/swap.img bs=1M count=2048
mkswap /swap.img
swapon /swap.img
exit 0

View File

@ -1,4 +0,0 @@
#!/bin/sh
swapoff -a
rm -rf /home/vagrant/swap.img

View File

@ -2,8 +2,8 @@
<channel name="xsettings" version="1.0">
<property name="Net" type="empty">
<property name="ThemeName" type="string" value="Xfce"/>
<property name="IconThemeName" type="string" value="Tango"/>
<property name="ThemeName" type="string" value="Adwaita"/>
<property name="IconThemeName" type="string" value="Adwaita"/>
<property name="DoubleClickTime" type="empty"/>
<property name="DoubleClickDistance" type="empty"/>
<property name="DndDragThreshold" type="empty"/>

View File

@ -4,7 +4,16 @@
# packages
#OFFLINE=True
ADMIN_PASSWORD=admin
ADMIN_PASSWORD=openstack
DATABASE_PASSWORD=$ADMIN_PASSWORD
RABBIT_PASSWORD=$ADMIN_PASSWORD
SERVICE_PASSWORD=$ADMIN_PASSWORD
# Git fine tuning. HTTPS is usually enabled on firewalls.
# Depth should be only one for upstream training purposes
GIT_DEPTH=1
GIT_BASE=https://git.openstack.org
# Let's save some memory
API_WORKERS=1

View File

@ -1,39 +1,5 @@
#!/usr/bin/env bash
# Tune mysql
sudo tee -a /etc/mysql/my.cnf << EOF
# Courtesy of Morgan Tocker
# http://www.tocker.ca/2014/03/10/configuring-mysql-to-use-minimal-memory.html
[mysqld]
innodb_buffer_pool_size=5M
innodb_log_buffer_size=256K
query_cache_size=0
key_buffer_size=8
thread_cache_size=0
host_cache_size=0
innodb_ft_cache_size=1600000
innodb_ft_total_cache_size=32000000
# per thread or per operation settings
thread_stack=131072
sort_buffer_size=32K
read_buffer_size=8200
read_rnd_buffer_size=8200
max_heap_table_size=16K
tmp_table_size=1K
bulk_insert_buffer_size=0
join_buffer_size=128
net_buffer_length=1K
innodb_sort_buffer_size=64K
#settings that relate to the binary log (if enabled)
binlog_cache_size=4K
binlog_stmt_cache_size=4K
EOF
sudo service mysql restart
# Set Apache WSGI modules' process and thread count
sudo sed -i '/WSGIDaemonProcess/s/processes=[0-9]*/processes=1/g' /etc/apache2/sites-available/horizon.conf
sudo sed -i '/WSGIDaemonProcess/s/threads=[0-9]*/threads=5/g' /etc/apache2/sites-available/horizon.conf

View File

@ -6,30 +6,24 @@ export DEBIAN_FRONTEND=noninteractive
REPO=$(dirname "$(readlink -f "$0")")/
# Copy configs
sudo cp -ar "$REPO/files/etc" /
sudo cp -ar "$REPO/files/home" /
sudo chown -R "$USER:$GROUP" /home/
# Copy scripts
sudo cp -ar "$REPO/files/usr" /
sudo sed -i "s@http://archive.ubuntu.com@$APT_MIRROR@g" /etc/apt/sources.list
sudo apt update
sudo apt dist-upgrade -y
# Fixing headless dictionaries-common install
sudo apt install -y dictionaries-common
sudo /usr/share/debconf/fix_db.pl
sudo dpkg-reconfigure dictionaries-common
sudo apt dist-upgrade -y
# Install git workflow related software
sudo apt install -y git gitk git-gui git-review tig
# Install basic TUI applications
sudo apt install -y htop mc tmux
# Copy configs
sudo cp -ar "$REPO/files/etc" /
sudo cp -ar "$REPO/files/home" /
sudo chown -R "$USER:$GROUP" /home/
# Set password
echo "$USER:openstack" | sudo chpasswd
# Copy scripts
sudo cp -ar "$REPO/files/usr" /

View File

@ -14,3 +14,36 @@ cp -ar "$REPO/files/opt" /
# Enable OFFLINE mode for next invoking stack.sh to be faster
sed -i 's/#OFFLINE=/OFFLINE=/' /opt/devstack/local.conf
# Configure mysql to operate with less memory
sudo tee -a /etc/mysql/my.cnf << EOF
# Courtesy of Morgan Tocker
# http://www.tocker.ca/2014/03/10/configuring-mysql-to-use-minimal-memory.html
[mysqld]
innodb_buffer_pool_size=5M
innodb_log_buffer_size=256K
query_cache_size=0
key_buffer_size=8
thread_cache_size=0
host_cache_size=0
innodb_ft_cache_size=1600000
innodb_ft_total_cache_size=32000000
# per thread or per operation settings
thread_stack=131072
sort_buffer_size=32K
read_buffer_size=8200
read_rnd_buffer_size=8200
max_heap_table_size=16K
tmp_table_size=1K
bulk_insert_buffer_size=0
join_buffer_size=128
net_buffer_length=1K
innodb_sort_buffer_size=64K
#settings that relate to the binary log (if enabled)
binlog_cache_size=4K
binlog_stmt_cache_size=4K
EOF
sudo service mysql restart

View File

@ -4,12 +4,14 @@ export DEBIAN_FRONTEND=noninteractive
# Set up a desktop environment
sudo apt install -y linux-image-extra-virtual
sudo apt install -y xfce4
sudo apt install -y lightdm lightdm-gtk-greeter \
--no-install-recommends --no-install-suggests
sudo apt install -y xserver-xorg-input-evdev
sudo apt install -y adwaita-icon-theme-full gnome-themes-standard \
gtk2-engines-pixbuf thunar xfce4-panel xfce4-session \
xfdesktop4 xfwm4
sudo apt install -y lightdm lightdm-gtk-greeter
# Install basic GUI applications
sudo apt install -y firefox xfce4-terminal xfce4-whiskermenu-plugin \
vim-gtk geany hexchat
vim-gtk geany hexchat
# Configure virtualbox GUI
sudo apt install -y virtualbox-guest-dkms virtualbox-guest-x11