The process really is straightforward, but do note than jails looking for non-existent log sources (e.g. files) can cause fail2ban to not start.
I don't know the details on ubuntu, but for centos, I would do:
- pick my firewall (which would end up being firewalld, because that is the CentOS7 default)
- install fail2ban and the correct firewall bindings
- start fail2ban, and ensure it works (by default, it will have the SSH jail active).
- think about what you need next
One thing you might consider is simply extending the block put in place by the SSH jail, to completely block any offending source (i.e. don't just have it block port 22, but all traffic).
If you do find you need other jails and/or filters, I would:
- use /etc/fail2ban/jail.d to store my jail configs, in order to ensure I can remove anything causing issues without needing to go through a large config file
- make sure you test new jails, notably by not using them for SSH initially, and ensuring they apply only to the services whose logs the jail is monitoring.
I have a small example in ansible online, see https://github.com/iwaseatenbyagrue/ansible/blob/master/roles/fail2ban/tasks/suricata.yml and https://github.com/iwaseatenbyagrue/ansible/blob/master/roles/fail2ban/templates/ (e.g. https://github.com/iwaseatenbyagrue/ansible/blob/master/roles/fail2ban/templates/jail.suricata.j2)
The overall code isn't necessarily ship shape just yet, so I can't recommend you use it (at least not without being 100% certain you understand it all), but hopefully those snippets are of some use.