Skip to content

Instantly share code, notes, and snippets.

@lhas-dev
Created May 25, 2020 05:58
Show Gist options
  • Save lhas-dev/4dc70936e321b6eafbb51b3c3f7f9d96 to your computer and use it in GitHub Desktop.
Save lhas-dev/4dc70936e321b6eafbb51b3c3f7f9d96 to your computer and use it in GitHub Desktop.
COMO INSTALAR O POSTGRESQL EM UM SERVIDOR LINUX (UBUNTU) | DevOps #1
1) Criar Linode "gandalf-1";
2) Copiar chave SSH:
cat ~/.ssh/id_rsa.pub
3) Atualizar SO:
apt-get update && apt-get upgrade
4) Renomear hostnamee:
echo "gandalf-1" > /etc/hostname
hostname -F /etc/hostname
5) Mudar a data:
dpkg-reconfigure tzdata
6) Adicionar um usuário:
adduser lhas
adduser lhas sudo
7) Trocar de usuário:
exit
ssh lhas@ip
8) Aumentar a segurança:
cp /root/.ssh/authorized_keys /home/lhas/.ssh/authorized_keys
sudo nano /etc/ssh/sshd_config
PermitRootLogin no
PasswordAuthentication no
9) Reiniciar o server:
sudo systemctl restart sshd
10) Instalar o fail2ban:
sudo apt-get install fail2ban
ufw allow ssh
ufw enable
11) Instalar o PostgreSQL:
sudo apt-get install postgresql postgresql-contrib
12) Configurar senha para usuário `postgres`:
sudo passwd postgres
su - postgres
psql -d template1 -c "ALTER USER postgres WITH PASSWORD 'abacate123';"
13) Criar database:
createdb 01dev_production;
psql 01ev_production;
\q;
14) Criar usuário:
createuser lhas --pwprompt
15) Configurar Postgres:
nano /etc/postgresql/12/main/pg_hba.conf
local all all md5
host all all 0.0.0.0/0 md5 (opcional)
nano /etc/postgresql/12/main/postgresql.conf (opcional)
listen_addresses = '*' (opcionanl)
exit
sudo service postgresql restart
su - postgres
psql -U lhas -W 01dev_production
16) permitir usuário de criar banco: (opcional)
sudo -u postgres psql postgres
ALTER USER lhas CREATEDB;
17) backups automáticos:
su - postgres
mkdir -p ~/postgres/backups
crontab -e
0 0 * * * pg_dumpall -U postgres > ~/postgres/backups/postgresql_dump.bak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment