141 lines
3.3 KiB
Markdown
141 lines
3.3 KiB
Markdown
# 02 - Test Ansible Bootstrap
|
|
|
|
Bu asamanin amaci Terraform ile olusturulan test makinelerini Linux, hardening, Docker ve Swarm acisindan hazir hale getirmektir. DB yazilimi kurulumu bu asamanin disindadir.
|
|
|
|
## Hedef Makineler
|
|
|
|
| Host | Rol |
|
|
| --- | --- |
|
|
| `test-swarm-01` | Swarm manager + app worker |
|
|
| `test-db-01` | Manuel DB kurulumu icin OS-hardening uygulanmis DB node |
|
|
|
|
## Onerilen Dosya Yapisi
|
|
|
|
```text
|
|
ansible/
|
|
ansible.cfg
|
|
inventory/
|
|
generated/
|
|
test.yml
|
|
group_vars/
|
|
all.yml
|
|
test.yml
|
|
playbooks/
|
|
test-bootstrap.yml
|
|
roles/
|
|
base/
|
|
hardening/
|
|
docker/
|
|
swarm/
|
|
node_dirs/
|
|
```
|
|
|
|
## Base Role
|
|
|
|
Tum test node'larina uygulanir:
|
|
|
|
- `apt update`
|
|
- temel paketler:
|
|
- `curl`
|
|
- `wget`
|
|
- `git`
|
|
- `jq`
|
|
- `unzip`
|
|
- `ca-certificates`
|
|
- `gnupg`
|
|
- `lsb-release`
|
|
- `ufw`
|
|
- `fail2ban`
|
|
- `chrony`
|
|
- `python3`
|
|
- `python3-pip`
|
|
- timezone: `Europe/Istanbul`
|
|
- hostname ayari
|
|
- sistem reboot gerekiyorsa kontrollu reboot
|
|
|
|
## Security Hardening Role
|
|
|
|
Tum test node'larina uygulanir:
|
|
|
|
- SSH password login kapatilir.
|
|
- Root SSH login kapatilir.
|
|
- Sadece SSH key ile login kalir.
|
|
- `PermitEmptyPasswords no`
|
|
- `MaxAuthTries 3`
|
|
- `fail2ban` SSH jail aktif edilir.
|
|
- `unattended-upgrades` aktif edilir.
|
|
- UFW default:
|
|
- incoming: deny
|
|
- outgoing: allow
|
|
- Public SSH sadece admin CIDR'dan acilir.
|
|
|
|
Not: Docker iptables kurallari UFW ile etkilesebilir. Hetzner Cloud firewall asil dis perimeter kabul edilir; UFW host icinde ikinci katman olarak kullanilir.
|
|
|
|
## Docker Role
|
|
|
|
Sadece `test-swarm-01` uzerinde zorunludur. `test-db-01` uzerinde DB manual kurulum stratejisine gore opsiyonel tutulabilir.
|
|
|
|
Docker kurulumu resmi Docker apt repository uzerinden yapilir:
|
|
|
|
- Docker GPG key
|
|
- Docker apt source
|
|
- paketler:
|
|
- `docker-ce`
|
|
- `docker-ce-cli`
|
|
- `containerd.io`
|
|
- `docker-buildx-plugin`
|
|
- `docker-compose-plugin`
|
|
- Docker servisi enabled + started
|
|
|
|
Docker convenience script kullanilmayacak. Production benzeri test ortami icin paket repository yolu tercih edilir.
|
|
|
|
## Swarm Role
|
|
|
|
`test-swarm-01` uzerinde:
|
|
|
|
- `docker swarm init`
|
|
- advertise addr: `10.10.10.11`
|
|
- data path addr: `10.10.10.11`
|
|
- overlay network:
|
|
- `iklimco-net`
|
|
- driver: `overlay`
|
|
- attachable: `true`
|
|
- Node `type=service` label'i ile isaretlenir:
|
|
```bash
|
|
docker node update --label-add type=service test-swarm-01
|
|
```
|
|
- Node `AVAILABILITY=Active` kalir (drain edilmez); tek node hem manager hem worker'dir.
|
|
|
|
Test tek node Swarm oldugu icin join token kullanimi yoktur.
|
|
|
|
## Node Directory Role
|
|
|
|
`test-swarm-01` uzerinde deploy on kosullari:
|
|
|
|
```text
|
|
/opt/iklimco
|
|
/opt/iklimco/ssl
|
|
/opt/iklimco/init
|
|
/opt/iklimco/init/postgresql
|
|
/opt/iklimco/init/mongodb
|
|
```
|
|
|
|
DB node uzerinde manuel DB kurulumu icin minimum:
|
|
|
|
```text
|
|
/opt/iklimco
|
|
/opt/iklimco/db
|
|
/opt/iklimco/backup
|
|
```
|
|
|
|
## Kabul Kriterleri
|
|
|
|
- `ansible -i inventory/generated/test.yml all -m ping` basarili olur.
|
|
- `test-swarm-01` uzerinde `docker info` calisir.
|
|
- `test-swarm-01` uzerinde Swarm active olur; node `AVAILABILITY=Active` (drain degil).
|
|
- `docker network ls` icinde `iklimco-net` gorulur.
|
|
- `docker node inspect test-swarm-01 --format '{{.Spec.Labels}}'` ciktisi `map[type:service]` icerir.
|
|
- `test-db-01` uzerinde public DB portu acik degildir.
|
|
- Public portlar Hetzner firewall + UFW seviyesinde `22`, `80`, `443` ile sinirlidir.
|
|
|