Mudanças entre as edições de "OpenStack IFSC:Criação de máquina virtual Debian GNU/Linux testing 64-bit"
Linha 56: | Linha 56: | ||
<syntaxhighlight lang=bash> | <syntaxhighlight lang=bash> | ||
aptitude install cloud-init cloud-initramfs-growroot cloud-utils | aptitude install cloud-init cloud-initramfs-growroot cloud-utils | ||
− | + | </syntaxhighlight> | |
− | |||
+ | * Configuração do <tt>cloud-init</tt>. Segue abaixo os trechos do arquivo modificado: | ||
+ | <code> | ||
+ | --- /etc/cloud/cloud-original.cfg 2014-09-08 09:36:52.000000000 -0300 | ||
+ | +++ /etc/cloud/cloud.cfg 2014-09-08 09:37:08.000000000 -0300 | ||
+ | @@ -24,8 +24,10 @@ | ||
+ | # The modules that run in the 'init' stage | ||
+ | cloud_init_modules: | ||
+ | - migrator | ||
+ | + - seed_random | ||
+ | - bootcmd | ||
+ | - write-files | ||
+ | + - growpart | ||
+ | - resizefs | ||
+ | - set_hostname | ||
+ | - update_hostname | ||
+ | @@ -40,6 +42,7 @@ | ||
+ | # Emit the cloud config ready event | ||
+ | # this can be used by upstart jobs for 'start on cloud-config'. | ||
+ | - emit_upstart | ||
+ | + - disk_setup | ||
+ | - mounts | ||
+ | - ssh-import-id | ||
+ | - locale | ||
+ | @@ -61,6 +64,7 @@ | ||
+ | # The modules that run in the 'final' stage | ||
+ | cloud_final_modules: | ||
+ | - rightscale_userdata | ||
+ | + - scripts-vendor | ||
+ | - scripts-per-once | ||
+ | - scripts-per-boot | ||
+ | - scripts-per-instance | ||
+ | @@ -75,19 +79,32 @@ | ||
+ | # (not accessible to handlers/transforms) | ||
+ | system_info: | ||
+ | # This will affect which distro class gets used | ||
+ | # Default user name + that default users groups (if added/used) | ||
+ | default_user: | ||
+ | lock_passwd: True | ||
+ | + sudo: ["ALL=(ALL) NOPASSWD:ALL"] | ||
+ | + shell: /bin/bash | ||
+ | # Other config here will be given to the distro class and/or path classes | ||
+ | paths: | ||
+ | cloud_dir: /var/lib/cloud/ | ||
+ | templates_dir: /etc/cloud/templates/ | ||
+ | upstart_dir: /etc/init/ | ||
+ | package_mirrors: | ||
+ | - - arches: [default] | ||
+ | + - arches: [i386, amd64] | ||
+ | failsafe: | ||
+ | - primary: http://ftp.debian.org/debian | ||
+ | + primary: http://debian.pop-sc.rnp.br/debian | ||
+ | + security: http://security.debian.com/ | ||
+ | + mount_default_fields: [~, ~, 'auto', 'defaults,nofail', '0', '2'] | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | * Bloqueio de acesso de root via SSH: | ||
+ | <syntaxhighlight lang=bash> | ||
sed -i "s/PermitRootLogin yes/PermitRootLogin without-password/" /etc/ssh/sshd_config | sed -i "s/PermitRootLogin yes/PermitRootLogin without-password/" /etc/ssh/sshd_config | ||
+ | </syntaxhighlight> | ||
+ | * Remoção do módulo do alto-falante local: | ||
+ | <syntaxhighlight lang=bash> | ||
cat > /etc/modprobe.d/blacklist.conf << EOF | cat > /etc/modprobe.d/blacklist.conf << EOF | ||
blacklist pcspkr | blacklist pcspkr | ||
EOF | EOF | ||
+ | </syntaxhighlight> | ||
+ | * Remoção da proteção de tela e desligamento por ociosidade: | ||
+ | <syntaxhighlight lang=bash> | ||
sed -i s/^BLANK_TIME=.*/BLANK_TIME=0/ /etc/kbd/config | sed -i s/^BLANK_TIME=.*/BLANK_TIME=0/ /etc/kbd/config | ||
sed -i s/^POWERDOWN_TIME=.*/POWERDOWN_TIME=0/ /etc/kbd/config | sed -i s/^POWERDOWN_TIME=.*/POWERDOWN_TIME=0/ /etc/kbd/config | ||
sed -i 's/^[ \t#]KEYBOARD_DELAY=.*/KEYBOARD_DELAY=1000/' /etc/kbd/config | sed -i 's/^[ \t#]KEYBOARD_DELAY=.*/KEYBOARD_DELAY=1000/' /etc/kbd/config | ||
+ | </syntaxhighlight> | ||
+ | * Desativação da automatização de nomeação de interfaces de rede: | ||
+ | <syntaxhighlight lang=bash> | ||
rm -f /etc/udev/rules.d/70-persistent-net.rules | rm -f /etc/udev/rules.d/70-persistent-net.rules | ||
rm -f /lib/udev/write_net_rules | rm -f /lib/udev/write_net_rules | ||
+ | </syntaxhighlight> | ||
+ | * Adição da interface serial <tt>ttyS0</tt> ao console para visualização na interface Web (Dashboard): | ||
+ | <syntaxhighlight lang=bash> | ||
sed -i -e ’s/^GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0"/' /etc/default/grub | sed -i -e ’s/^GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0"/' /etc/default/grub | ||
update-grub | update-grub | ||
+ | </syntaxhighlight> | ||
+ | * Adição dos módulos de dispositivos virtuais comuns do KVM<ref>http://www.linux-kvm.org/page/Virtio</ref> com libvirt<ref>http://wiki.libvirt.org/page/Virtio</ref>: | ||
+ | <syntaxhighlight lang=bash> | ||
cat > /etc/initramfstools/modules << EOF | cat > /etc/initramfstools/modules << EOF | ||
virtio | virtio | ||
Linha 83: | Linha 154: | ||
EOF | EOF | ||
update-initramfs -u | update-initramfs -u | ||
+ | </syntaxhighlight> | ||
− | + | * Remoção de cache local de pacotes: | |
+ | <syntaxhighlight lang=bash> | ||
rm /var/cache/apt/archives/*.deb | rm /var/cache/apt/archives/*.deb | ||
apt-get autoremove | apt-get autoremove | ||
apt-get autoclean | apt-get autoclean | ||
apt-get clean | apt-get clean | ||
+ | </syntaxhighlight> | ||
+ | * Limpeza das chaves originais do SSH, embora o <tt>cloud-init</tt> gerará novas ao iniciar a máquina virtual: | ||
+ | <syntaxhighlight lang=bash> | ||
rm -f /etc/ssh/ssh_host* | rm -f /etc/ssh/ssh_host* | ||
dpkg-reconfigure openssh-server | dpkg-reconfigure openssh-server | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | * O pacote <tt>cloud-init</tt> do Debian GNU/Linux, por algum motivo, cria o diretório <tt>/var/lib/cloud/instance</tt>, o que gerará problemas futuramente (quando o próprio script tenta criar um ''link'' com mesmo nome): | ||
+ | <syntaxhighlight lang=bash> | ||
+ | rm -rf /var/lib/cloud/instance | ||
+ | </syntaxhighlight> | ||
+ | * Remoção do histórico da própria instalação: | ||
+ | <syntaxhighlight lang=bash> | ||
rm -rf /tmp/* | rm -rf /tmp/* | ||
rm -f /var/log/wtmp /var/log/btmp | rm -f /var/log/wtmp /var/log/btmp | ||
shutdown -h 1 | shutdown -h 1 | ||
history -c | history -c | ||
− | |||
− | |||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
=Referências= | =Referências= | ||
<references/> | <references/> |
Edição das 00h12min de 9 de setembro de 2014
Bases
O modelo de máquina virtual Debian GNU/Linux testing 64-bit foi baseado em:
- Guia oficial do OpenStack[1].
- Manual disponível no blog ThorneLabs[2].
- Script build-openstack-debian-image[3].
Instalação
Inicialmente, foi criado um disco vazio e executada uma máquina virtual com esse disco e o instalador[4]:
qemu-img create -f qcow2 debian.qcow2 1G
kvm -m 1024 -cdrom debian-jessie-DI-b1-amd64-netinst.iso -drive file=debian.qcow2 -net nic -net user -nographic -vnc :10 -usbdevice tablet
Em seguida, foi conectado um cliente VNC ao mesmo e iniciado o processo regular de instalação do sistema.
Configuração
Após reiniciado o sistema, ainda no VNC, foram executados os comandos de configuração:
- Configuração de rede:
cat > /etc/network/interfaces << EOF
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
EOF
- Configuração do APT:
cat > /etc/apt/sources.list << EOF
deb http://debian.pop-sc.rnp.br/debian testing main contrib non-free
deb http://security.debian.org testing/updates main contrib non-free
EOF
- Atualização do sistema, incluindo o suporte a plataforma i386:
dpkg --add-architeture i386
aptitude update
aptitude safe-upgrade
aptitude full-upgrade
- Instalação dos pacotes básicos de usuário:
aptitude install bash-completion less vim bzip2 patch
- Instalação dos pacotes necessários à autoconfiguração feita pelo pacote cloud-init:
aptitude install sudo locales ssh linux-image-amd64 euca2ools file curl wget rsync dbus
- Instalação do cloud-init:
aptitude install cloud-init cloud-initramfs-growroot cloud-utils
- Configuração do cloud-init. Segue abaixo os trechos do arquivo modificado:
--- /etc/cloud/cloud-original.cfg 2014-09-08 09:36:52.000000000 -0300
+++ /etc/cloud/cloud.cfg 2014-09-08 09:37:08.000000000 -0300
@@ -24,8 +24,10 @@
# The modules that run in the 'init' stage
cloud_init_modules:
- migrator
+ - seed_random
- bootcmd
- write-files
+ - growpart
- resizefs
- set_hostname
- update_hostname
@@ -40,6 +42,7 @@
# Emit the cloud config ready event
# this can be used by upstart jobs for 'start on cloud-config'.
- emit_upstart
+ - disk_setup
- mounts
- ssh-import-id
- locale
@@ -61,6 +64,7 @@
# The modules that run in the 'final' stage
cloud_final_modules:
- rightscale_userdata
+ - scripts-vendor
- scripts-per-once
- scripts-per-boot
- scripts-per-instance
@@ -75,19 +79,32 @@
# (not accessible to handlers/transforms)
system_info:
# This will affect which distro class gets used
# Default user name + that default users groups (if added/used)
default_user:
lock_passwd: True
+ sudo: ["ALL=(ALL) NOPASSWD:ALL"]
+ shell: /bin/bash
# Other config here will be given to the distro class and/or path classes
paths:
cloud_dir: /var/lib/cloud/
templates_dir: /etc/cloud/templates/
upstart_dir: /etc/init/
package_mirrors:
- - arches: [default]
+ - arches: [i386, amd64]
failsafe:
- primary: http://ftp.debian.org/debian
+ primary: http://debian.pop-sc.rnp.br/debian
+ security: http://security.debian.com/
+ mount_default_fields: [~, ~, 'auto', 'defaults,nofail', '0', '2']
</syntaxhighlight>
- Bloqueio de acesso de root via SSH:
sed -i "s/PermitRootLogin yes/PermitRootLogin without-password/" /etc/ssh/sshd_config
- Remoção do módulo do alto-falante local:
cat > /etc/modprobe.d/blacklist.conf << EOF
blacklist pcspkr
EOF
- Remoção da proteção de tela e desligamento por ociosidade:
sed -i s/^BLANK_TIME=.*/BLANK_TIME=0/ /etc/kbd/config
sed -i s/^POWERDOWN_TIME=.*/POWERDOWN_TIME=0/ /etc/kbd/config
sed -i 's/^[ \t#]KEYBOARD_DELAY=.*/KEYBOARD_DELAY=1000/' /etc/kbd/config
- Desativação da automatização de nomeação de interfaces de rede:
rm -f /etc/udev/rules.d/70-persistent-net.rules
rm -f /lib/udev/write_net_rules
- Adição da interface serial ttyS0 ao console para visualização na interface Web (Dashboard):
sed -i -e ’s/^GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0"/' /etc/default/grub
update-grub
cat > /etc/initramfstools/modules << EOF
virtio
virtio_pci
virtio_scsi
virtio_blk
virtio_net
EOF
update-initramfs -u
- Remoção de cache local de pacotes:
rm /var/cache/apt/archives/*.deb
apt-get autoremove
apt-get autoclean
apt-get clean
- Limpeza das chaves originais do SSH, embora o cloud-init gerará novas ao iniciar a máquina virtual:
rm -f /etc/ssh/ssh_host*
dpkg-reconfigure openssh-server
- O pacote cloud-init do Debian GNU/Linux, por algum motivo, cria o diretório /var/lib/cloud/instance, o que gerará problemas futuramente (quando o próprio script tenta criar um link com mesmo nome):
rm -rf /var/lib/cloud/instance
- Remoção do histórico da própria instalação:
rm -rf /tmp/*
rm -f /var/log/wtmp /var/log/btmp
shutdown -h 1
history -c
Referências
- ↑ http://docs.openstack.org/image-guide/content/ch_openstack_images.html
- ↑ http://thornelabs.net/2014/04/07/create-a-kvm-based-debian-7-openstack-cloud-image.html
- ↑ http://manpages.ubuntu.com/manpages/trusty/man1/build-openstack-debian-image.1.html
- ↑ https://www.debian.org/devel/debian-installer
- ↑ http://www.linux-kvm.org/page/Virtio
- ↑ http://wiki.libvirt.org/page/Virtio