Documentação da infraestrutura: mudanças entre as edições
(Cria seção.) |
|||
Linha 106: | Linha 106: | ||
== Ambiente de trabalho local == | == Ambiente de trabalho local == | ||
Documentação em construção. | |||
=== Máquina virtual Ubuntu 22.04 === | |||
Utilizamos KVM e imagem cloud do Ubuntu 22.04 num hospedeiro Debian 12.Etapa opcional se já estiver rodando um Ubuntu 22.04. | |||
==== Exemplo de instalação no hospedeiro ==== | |||
<syntaxhighlight lang="sh"> | |||
sudo apt install libvirt-daemon-system qemu-system-x86 qemu-utils virtinst --no-install-recommends | |||
sudo apt install dnsmasq virt-manager virt-viewer gir1.2-spiceclientgtk-3.0 --no-install-recommends | |||
sudo adduser $USER libvirt</syntaxhighlight> | |||
==== Criação da VM ==== | |||
<syntaxhighlight lang="sh"># diretórios para imagens | |||
DIRVM_TEMPLATES='~/libvirt/images/templates' | |||
DIRVM_IMAGES='~/libvirt/images' | |||
# chave pública para acessar a vm | |||
SSH_PUB_KEY='XXXXXX' | |||
# link para download da imagem | |||
IMAGE_LINK='http://cloud-images.ubuntu.com/minimal/releases/jammy/release/ubuntu-22.04-minimal-cloudimg-amd64.img' | |||
SHASUM='http://cloud-images.ubuntu.com/minimal/releases/jammy/release/SHA256SUMS' | |||
# download e verificação da imagem | |||
cd $DIRVM_TEMPLATES | |||
wget ${IMAGE_LINK} && wget ${SHASUM}{.gpg,} | |||
gpg --verify ${SHASUM/*\/}{.gpg,} | |||
sha256sum -c SHA256SUMS --ignore-missing | |||
# ver infos da imagem | |||
file ${IMAGE_LINK/*\/} | |||
qemu-img info ${IMAGE_LINK/*\/} | |||
# metadados da imagem | |||
VM_NAME='servera4a' | |||
VM_DISK="${VM_NAME}_disk.qcow2" | |||
VM_DISK_SIZE='20G' | |||
VM_VCPUS='2' | |||
VM_RAM='3072' | |||
VM_MAC='52:54:00:00:00:46' | |||
VM_BRIDGE='virbr0' | |||
# VM_BRIDGE='br0' | |||
VM_OS_VARIANT='ubuntu22.04' | |||
VM_METADATA='meta-data.yaml' | |||
VM_USERDATA='user-data.yaml' | |||
cat > ${VM_METADATA} <<EOF | |||
instance-id: $VM_NAME | |||
local-hostname: $VM_NAME | |||
EOF | |||
cat > ${VM_USERDATA} <<EOF | |||
#cloud-config | |||
users: | |||
- name: x | |||
password: xyz | |||
ssh-authorized-keys: | |||
- $SSH_PUB_KEY | |||
sudo: ['ALL=(ALL) NOPASSWD:ALL'] | |||
groups: sudo | |||
shell: /bin/bash | |||
EOF | |||
# resize da imagem | |||
sudo qemu-img convert -f qcow2 -O qcow2 ${DIRVM_TEMPLATES}/${IMAGE_LINK/*\/} ${DIRVM_IMAGES}/${VM_DISK} | |||
sudo qemu-img resize ${DIRVM_IMAGES}/${VM_DISK} ${VM_DISK_SIZE} | |||
# ver infos da imagem | |||
qemu-img info ${DIRVM_IMAGES}/${VM_DISK} | |||
virt-df -h ${DIRVM_IMAGES}/${VM_DISK} | |||
sudo virt-filesystems --long -h --all -a ${DIRVM_IMAGES}/${VM_DISK} | |||
# criar vm | |||
sudo virt-install \ | |||
--name ${VM_NAME} \ | |||
--disk ${DIRVM_IMAGES}/${VM_DISK},device=disk,bus=virtio \ | |||
--cloud-init meta-data=${VM_METADATA},user-data=${VM_USERDATA} \ | |||
--virt-type kvm \ | |||
--graphics none \ | |||
--vcpus ${VM_VCPUS} \ | |||
--memory ${VM_RAM} \ | |||
--os-variant=${VM_OS_VARIANT} \ | |||
--network network=default,model=virtio,bridge=${VM_BRIDGE},mac=${VM_MAC} \ | |||
--import \ | |||
# obtem ip da vm | |||
sudo virsh domifaddr servera4a | |||
ssh ipdamaquina</syntaxhighlight> | |||
=== Software suficiente para realizar a maior parte das ingestões === | |||
<syntaxhighlight lang="sh">sudo apt-get update | |||
# postgresql e postgis | |||
sudo apt-get install -y postgresql-14 postgis postgresql-14-postgis-3 postgresql-postgis --no-install-recommends | |||
# Extensão plpython | |||
sudo apt-get install -y postgresql-plpython3-14 --no-install-recommends | |||
# gdal e proj | |||
sudo apt-get install -y gdal-bin proj-bin --no-install-recommends | |||
# chevron para Mustache | |||
sudo apt-get install python3-pip --no-install-recommends | |||
sudo pip3 install chevron | |||
# ferramentas diversas | |||
sudo apt-get install -y git make vim wget zip unzip p7zip p7zip-rar p7zip-full --no-install-recommends | |||
# opcionais | |||
#sudo apt-get install -y bash-completion tmux silversearcher-ag --no-install-recommends</syntaxhighlight> | |||
=== Configuração do banco de dados === | |||
No arquivo <code>/etc/postgresql/14/main/pg_hba.conf</code> | |||
Ajustar as linhas | |||
<pre>local all postgres peer | |||
local all all peer | |||
host all all 127.0.0.1/32 scram-sha-256</pre> | |||
para | |||
<pre>local all postgres trust | |||
local all all trust | |||
host all all 127.0.0.1/32 trust</pre> | |||
com | |||
<syntaxhighlight lang="sh">cat /etc/postgresql/14/main/pg_hba.conf | |||
sed -E -i 's/local(\s+)all(\s+)postgres(\s+)peer/local\1all\2postgres\3trust/' /etc/postgresql/14/main/pg_hba.conf | |||
sed -E -i 's/local(\s+)all(\s+)all(\s+)peer/local\1all\2all\3trust/' /etc/postgresql/14/main/pg_hba.conf | |||
sed -E -i 's;host(\s+)all(\s+)all(\s+)127.0.0.1/32(\s+)scram-sha-256;host\1all\2all\3127.0.0.1/32\4trust;' /etc/postgresql/14/main/pg_hba.conf | |||
sudo service postgresql restart | |||
cat /etc/postgresql/14/main/pg_hba.conf</syntaxhighlight> | |||
=== Criar diretórios, grupos === | |||
<syntaxhighlight lang="sh"># cria grupo | |||
sudo groupadd www-data | |||
# adiciona usuário corrente aos grupos | |||
sudo usermod -aG www-data $USER | |||
sudo usermod -aG postgres $USER | |||
cat /etc/group | |||
cat /etc/passwd | |||
# cria diretórios e atualiza permissoes | |||
sudo mkdir -p /var/gits/_{a4a,dg,osmc} | |||
ls -la /var/gits | |||
sudo chown -R postgres:www-data /var/gits | |||
sudo chmod -R g+w /var/gits | |||
sudo chmod -R o-x /var/gits | |||
ls -la /var/gits | |||
sudo mkdir -p /tmp/{sandbox,pg_io} | |||
sudo chown -R postgres:www-data /tmp/{sandbox,pg_io} | |||
sudo chmod -R o-x /tmp/{sandbox,pg_io}</syntaxhighlight> | |||
=== Clonar repositórios === | |||
<syntaxhighlight lang="sh">for repo in \ | |||
a4a/WS \ | |||
a4a/pg_pubLib-v1 \ | |||
dg/licenses \ | |||
dg/preserv \ | |||
dg/preserv-AR \ | |||
dg/preserv-BO \ | |||
dg/preserv-BR \ | |||
dg/preserv-CL \ | |||
dg/preserv-CM \ | |||
dg/preserv-CO \ | |||
dg/preserv-EC \ | |||
dg/preserv-PE \ | |||
dg/preserv-PY \ | |||
dg/preserv-SR \ | |||
dg/preserv-UY \ | |||
dg/preserv-VE \ | |||
dg/preserv-MX \ | |||
dg/preservDataViz \ | |||
dg/stats \ | |||
osmc/benchmark \ | |||
osmc/BR_new \ | |||
osmc/CO_new \ | |||
osmc/CM \ | |||
osmc/EC_new \ | |||
osmc/GGeohash \ | |||
osmc/UY_new \ | |||
osmc/WS \ | |||
osmc/NaturalCodes | |||
do | |||
echo /var/gits/_${repo%%/*} | |||
if [[ ${repo%%/*} == 'dg' ]] | |||
then | |||
project='digital-guard' | |||
fi | |||
if [[ ${repo%%/*} == 'a4a' ]] | |||
then | |||
project='AddressForAll' | |||
fi | |||
if [[ ${repo%%/*} == 'osmc' ]] | |||
then | |||
project='osm-codes' | |||
fi | |||
echo ${project} | |||
if [ -d "/var/gits/_${repo}" ]; then | |||
pushd /var/gits/_${repo} | |||
git pull | |||
popd | |||
else | |||
pushd /var/gits/_${repo%%/*} | |||
git clone git@github.com:${project}/${repo##*/}.git | |||
#git clone https://github.com/${project}/${repo##*/}.git | |||
popd | |||
fi | |||
done</syntaxhighlight> | |||
=== Ajustar permissões === | |||
<syntaxhighlight lang="sh">pushd /var/gits/_dg/preserv/src | |||
make fix_permissions | |||
popd</syntaxhighlight> | |||
=== Criar e popular bases === | |||
<syntaxhighlight lang="sh">pushd /var/gits/_dg/preserv/src | |||
make | |||
make ini_ingest pg_db=ingest42 | |||
make ini_datalake pg_datalake=dl05s_main | |||
popd | |||
wget https://www.addressforall.org/_private/dump.zip | |||
unzip dump.zip | |||
ls | |||
cd dumptabelas | |||
PROD_DB='dl05s_main' | |||
# 05. carregar dump de jurisdiction (futuro: carregar de stable) | |||
# psql postgres://postgres@localhost/${PROD_DB} -c"ALTER TABLE optim.jurisdiction DISABLE TRIGGER ALL;" | |||
psql postgres://postgres@localhost/${PROD_DB} < pg_dump_jurisdiction.sql | |||
# psql postgres://postgres@localhost/${PROD_DB} -c"ALTER TABLE optim.jurisdiction ENABLE TRIGGER ALL;" | |||
# 06. carregar tabelas de geometrias (futuro: carregar de stable) | |||
psql postgres://postgres@localhost/${PROD_DB} < pg_dump_jurisdiction_geom.sql | |||
psql postgres://postgres@localhost/${PROD_DB} < pg_dump_jurisdiction_eez.sql | |||
# 07. carregar tabelas de abreviações (futuro: carregar de stable) | |||
psql postgres://postgres@localhost/${PROD_DB} < pg_dump_jurisdiction_abbrev_ref.sql | |||
psql postgres://postgres@localhost/${PROD_DB} < pg_dump_jurisdiction_abbrev_option.sql | |||
# 08. carregar dados de donor e donatePack | |||
psql postgres://postgres@localhost/${PROD_DB} -c"SELECT optim.insert_donor_pack(t) FROM unnest(ARRAY['BO','BR','CL','CO','EC','PE','PY','SR','UY','VE']) t;" | |||
psql postgres://postgres@localhost/${PROD_DB} -c"SELECT optim.insert_codec_type();" | |||
# 09. Carregar dados de componentes de pacotes (que já foram publicados e disponiveis para publicar) | |||
psql postgres://postgres@localhost/${PROD_DB} < pg_dump_donated_packcomponent.sql | |||
psql postgres://postgres@localhost/${PROD_DB} < pg_dump_donated_packcomponent_not_approved.sql | |||
# 10. Carregar links dos arquivos filtrados | |||
psql postgres://postgres@localhost/${PROD_DB} < pg_dump_donated_packcomponent_cloudcontrol.sql | |||
</syntaxhighlight> | |||
=== Exemplo de ingestão === | |||
<syntaxhighlight lang="sh"># semente makefile | |||
pushd /var/gits/_dg/preserv-BR/src/ | |||
make all | |||
popd | |||
pushd /var/gits/_dg/preserv-BR/data/AC/RioBranco/_pk0042.01/ | |||
make me pg_db=ingest42 orig=/tmp | |||
make all_layers pg_db=ingest42 orig=/tmp</syntaxhighlight> | |||
... | ... | ||
[[Categoria:Suporte]] | [[Categoria:Suporte]] |