Wiki do Tiozão do Linux

Instalar Ubuntu Nuvem Oracle Always Free

Ambiente Nuvem - Oracle Cloud

Porque escolher Oracle Cloud

Porque escolher Ubuntu 22.04

Criando um servidor na Nuvem Oracle

Provisionando um novo servidor

Criando uma Instância, você poderá acessá-la através de uma conexão Secure Shell (SSH) no endereço IP público disponibilizado.

  1. Acesse https://cloud.oracle.com e entre com sua identificação/senha.
  2. Clique no botão Create Instance conforme tela abaixo
    create_instance.png
  3. Coloque um nome sugestivo para esse servidor no campo Name
    • OBS: Esse nome pode ser alterado posteriormente, mas é importante que esse nome identifique unicamente esse servidor para evitar transtornos futuros
      name-instance.png
  4. Clique no botão Image and shape e selecione a opção Canonical Ubuntu 22.04
    image_and_shape_instance.png
    • A seleção apresentará a opção conforme abaixo
      image_and_shape_ubuntu_instance.png

OBS: Para criar seus próprios pares de chaves, você pode usar uma ferramenta de terceiros como OpenSSH em sistemas de estilo UNIX (incluindo Linux, Solaris, BSD e OS X) ou o Gerador de Chaves PuTTY no Windows.
Um bom tutorial para Ubuntu 22.04 encontra-se aqui: https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys-on-ubuntu-22-04

  1. Na opção Add SSH keys clique na opção Upload public key files e selecione sua chave pública. Guarde bem seu par de chaves, pois sem ele, não terá como acessar seu servidor.
    add_ssh_keys.png

SUPER DICA
Por default, uma instância disponibiliza 50GB de HD. O total de HD disponibilizado na sua conta Always Free é de 200GB. Então é possível criar até dois servidores com 100GB cada. Uma das opções do Boot volume é Specify a custom boot volume size que preenchemos com 100GB.

specify_a_custom_boot_volume_-_100gb_size.png

  1. Logo após clicar em Create, a tela abaixo será exibida
    provisioning.png
    • Dentro de alguns istantes teremos mais informações da instância Running incluindo o IP Público para acesso remoto
      running.png

Acessando o servidor via ssh

ssh ubuntu@134.65.23.213
The authenticity of host '134.65.23.213 (134.65.23.213)' can't be established.
ED25519 key fingerprint is SHA256:aMMDD2JLiP1e9OsGeMsIkxKMToaFH0Ugqv1nfH2bq+A.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '134.65.23.213' (ED25519) to the list of known hosts.
Welcome to Ubuntu 22.04.1 LTS (GNU/Linux 5.15.0-1021-oracle x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Fri Dec 16 14:12:32 UTC 2022

  System load:  0.20751953125     Processes:             118
  Usage of /:   2.0% of 96.73GB   Users logged in:       0
  Memory usage: 23%               IPv4 address for ens3: 10.0.0.30
  Swap usage:   0%

0 updates can be applied immediately.


The list of available updates is more than a week old.
To check for new updates run: sudo apt update


The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

ubuntu@ubuntu-04:~$ 

Obtendo informações iniciais

ubuntu@ubuntu-04:~$ free -h
               total        used        free      shared  buff/cache   available
Mem:           964Mi       195Mi       361Mi       1.0Mi       406Mi       613Mi
Swap:             0B          0B          0B

ubuntu@ubuntu-04:~$ df -hT
Filesystem     Type   Size  Used Avail Use% Mounted on
tmpfs          tmpfs   97M  1.1M   96M   2% /run
/dev/sda1      ext4    97G  2.0G   95G   2% /
tmpfs          tmpfs  483M     0  483M   0% /dev/shm
tmpfs          tmpfs  5.0M     0  5.0M   0% /run/lock
/dev/sda15     vfat   105M  5.3M  100M   5% /boot/efi
tmpfs          tmpfs   97M  4.0K   97M   1% /run/user/1001
ubuntu@ubuntu-04:~$ 

Permitr acesso ao root via chave privada

ubuntu@ubuntu-04:~$ sudo cp /home/ubuntu/.ssh/authorized_keys /root/.ssh/authorized_keys

Agora saia dessa sessão como usuário ubuntu e conecte-se como root

ubuntu@ubuntu-04:~$ exit
logout
Connection to 134.65.23.213 closed.

jarbelix@jarbelix-Nitro-AN515-44:~$ ssh root@134.65.23.213
Welcome to Ubuntu 22.04.1 LTS (GNU/Linux 5.15.0-1021-oracle x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Fri Dec 16 14:17:14 UTC 2022

  System load:  0.02978515625     Processes:             114
  Usage of /:   2.0% of 96.73GB   Users logged in:       0
  Memory usage: 22%               IPv4 address for ens3: 10.0.0.30
  Swap usage:   0%


0 updates can be applied immediately.


The list of available updates is more than a week old.
To check for new updates run: sudo apt update


The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

root@ubuntu-04:~# 

Criar swap de 4GB

fallocate -l 4G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0' | tee -a /etc/fstab

Validando a swap disponível

free -h
               total        used        free      shared  buff/cache   available
Mem:           964Mi       188Mi       364Mi       1.0Mi       411Mi       620Mi
Swap:          4.0Gi          0B       4.0Gi

Melhorar a utilização do swap

cat <<EOF > /etc/sysctl.d/99-swappiness.conf
# https://www.shellhacks.com/swappiness-in-linux-ubuntu-how-to-change/
vm.swappiness=5
EOF

Habilitar o swappiness sem reboot

sysctl -f --system

Validando o swappiness

cat /proc/sys/vm/swappiness

Atualizar sistema

apt update

apt dist-upgrade
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
Try Ubuntu Pro beta with a free personal subscription on up to 5 machines.
Learn more at https://ubuntu.com/pro
The following NEW packages will be installed:
  linux-headers-5.15.0-1025-oracle linux-image-5.15.0-1025-oracle
  linux-modules-5.15.0-1025-oracle linux-modules-extra-5.15.0-1025-oracle
  linux-oracle-headers-5.15.0-1025
The following packages have been kept back:
  apport python3-apport python3-problem-report python3-tz
The following packages will be upgraded:
  binutils binutils-common binutils-x86-64-linux-gnu ca-certificates cloud-init initramfs-tools
  initramfs-tools-bin initramfs-tools-core kpartx libbinutils libbpf0 libctf-nobfd0 libctf0
  libexpat1 libglib2.0-0 libglib2.0-bin libglib2.0-data libnetplan0 libnfsidmap1 libpython3.10
  libpython3.10-minimal libpython3.10-stdlib libsqlite3-0 libxml2 linux-headers-oracle
  linux-image-oracle linux-oracle login multipath-tools netplan.io nfs-common passwd
  python3-distupgrade python3.10 python3.10-minimal rsync snapd tmux tzdata
  ubuntu-advantage-tools ubuntu-release-upgrader-core
41 upgraded, 5 newly installed, 0 to remove and 4 not upgraded.
25 standard LTS security updates
Need to get 155 MB of archives.
After this operation, 584 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y

Desabilitar regras de firewall

iptables -F
netfilter-persistent save
systemctl disable --now netfilter-persistent

Validando regras de firewall

iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain InstanceServices (0 references)
target     prot opt source               destination

Liberando portas de entrada na Oracle

SUPER-DICA
Por segurança, a configuração default no Virtual Cloud Networks, as Ingress Rules liberam apenas a porta 22.
Para disponibilizar seviços é necessário liberar as portas necessárias. Veja abaixo um exemplo

Referências

  1. Use Oracle Cloud Infrastructure sem pagar nada por isso! - https://youtu.be/r6ygZXh4YjY
  2. Criação de VPS Grátis na Oracle Cloud 24GB RAM e 4CPU - https://youtu.be/u_CLq1Ksx3Y