Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
tutorial:adm:server_preparation_tmp [2020/03/10 10:14] urbanl [Database server installation - CentOS7] |
tutorial:adm:server_preparation_tmp [2020/07/24 08:35] fiserp [DB server configuration] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | <note important> | + | <note important> |
+ | |||
+ | **This tutorial is under development, | ||
Author: Ludek Urban | Author: Ludek Urban | ||
Line 5: | Line 7: | ||
- | ====== Server preparation - Linux ====== | + | ====== Server preparation - Linux - CentOS8 |
{{tag> | {{tag> | ||
- | This tutorial shows how to prepare the server for test or production | + | This tutorial shows how to prepare the server for test or production |
===== Basic system setup ===== | ===== Basic system setup ===== | ||
- | * 1 server (can be virtualized) for all: backend, frontend and database. | + | * 1 server (can be virtualized) for everything: backend, frontend and database. |
- | * OS Linux with EPEL repository enabled - CENTOS, basic network enabled installation | + | * OS Linux with EPEL repository enabled - CentOS, basic network enabled installation |
- | * It is possible to use Debian but you have to adjust | + | * It is possible to use Debian |
- | * PostgreSQL - installed from a new repository | + | * PostgreSQL |
- | * Java - distribution repository (OpenJDK 1.8) | + | * Java 11 - installed from OS packages. |
- | * Apache Tomcat - manually | + | * Apache Tomcat |
- | * Services | + | * Apache HTTPd 2.4.x - installed from OS packages. Can be replaced by nGinx. |
- | * Services run under dedicated | + | * All services |
+ | * Each service runs under dedicated non-privileged | ||
===== Instalation and software configuration ===== | ===== Instalation and software configuration ===== | ||
- | Prerequisities - Basic installation of CentOS | + | Prerequisities - Basic installation of CentOS |
<code bash> | <code bash> | ||
# EPEL installation | # EPEL installation | ||
- | yum clean all | + | dnf clean all |
- | yum install | + | dnf -y install |
- | yum update -y | + | dnf update -y |
# other recommended packages installation | # other recommended packages installation | ||
- | yum install | + | dnf -y install mc haveged nmap screen sysstat telnet |
# enable haveged after OS start | # enable haveged after OS start | ||
systemctl start haveged.service | systemctl start haveged.service | ||
systemctl enable haveged.service | systemctl enable haveged.service | ||
- | # remove unnecessary software | + | |
- | yum remove -y postfix | + | |
- | systemctl stop avahi-daemon.socket avahi-daemon.service | + | |
- | systemctl disable avahi-daemon.socket avahi-daemon.service | + | |
- | yum remove -y avahi-autoipd avahi | + | |
# set the hostname | # set the hostname | ||
hostnamectl set-hostname FQDN_server_name | hostnamectl set-hostname FQDN_server_name | ||
Line 45: | Line 45: | ||
</ | </ | ||
- | When installing | + | ===== PostgreSQL |
- | <code> | + | <note tip>If you are installing |
- | # check installed packages. It's recommanded | + | We install PostgreSQL 12 database binaries and change database data directory from ''/ |
- | yum list installed | + | ==== Database server |
- | # other recommended packages | + | * Software installation on CentOS8(versions can vary): |
- | yum install | + | |
- | </ | + | |
- | When installing on Debian, install these packages: | ||
- | < | ||
- | screen dnsutils sysstat lsof haveged nmap tcpdump traceroute tcptraceroute curl iptables-persistent | ||
- | </ | ||
- | ===== PostgreSQL ===== | ||
- | <note tip>If you are install CzechIdM on Sql server, please follow [[tutorial: | ||
- | CentOS7 default repository version of PostgreSQL is 9.2 but IdM not support that version. In our tutorial, we will install newer version 9.6. Moreover, we install database data into /data not /var/lib which is the default option. | ||
- | ==== Database server installation - CentOS7 and CentOS8 -!CHANGED ==== | ||
- | * Software installation on CentOS7(versions can vary): | ||
<code bash> | <code bash> | ||
- | yum install -y https:// | + | # enable module postgres 12 |
- | yum install -y postgresql96-server postgresql96-contrib pgstat2_96 pg_top96 | + | dnf module enable postgresql:12 |
- | </ | + | dnf -y install postgresql-server |
- | #TODO | + | |
- | * Software installation on CentOS7(versions can vary): | + | |
- | <code bash> | + | |
- | # add repository | + | |
- | yum install | + | |
- | # disable centos8 build-in module | + | |
- | yum module disable postgresql | + | |
- | # install postgresql | + | |
- | yum install -y postgresql11-server | + | |
</ | </ | ||
- | * create new system | + | * create new directory |
- | < | + | |
- | mkdir -p / | + | < |
+ | mkdir -p / | ||
chown -R postgres: | chown -R postgres: | ||
chmod 700 /data/pgsql | chmod 700 /data/pgsql | ||
</ | </ | ||
- | | + | |
+ | | ||
<code bash> | <code bash> | ||
- | cp / | + | cp / |
</ | </ | ||
- | In the file ''/ | + | |
+ | In the file ''/ | ||
< | < | ||
# Location of database directory | # Location of database directory | ||
- | Environment=PGDATA=/ | + | Environment=PGDATA=/ |
</ | </ | ||
- | * In the file '' | + | * In the file '' |
< | < | ||
- | PGDATA=/ | + | PGDATA=/ |
</ | </ | ||
Line 110: | Line 94: | ||
<code bash> | <code bash> | ||
- | / | + | postgresql-setup |
</ | </ | ||
+ | Change SELINUX labels: | ||
+ | < | ||
+ | chcon -Rt postgresql_db_t / | ||
+ | chcon -Rt postgresql_log_t / | ||
+ | </ | ||
* Enable and start database: | * Enable and start database: | ||
<code bash> | <code bash> | ||
- | systemctl start postgresql-11.service | + | systemctl start postgresql.service |
- | systemctl enable postgresql-11.service | + | systemctl enable postgresql.service |
</ | </ | ||
Line 125: | Line 113: | ||
<code bash> | <code bash> | ||
- | [root@tomcat1 system]# systemctl status postgresql-9.6.service -l | + | [root@HOSTNAME data]# systemctl status postgresql.service -l |
- | ● postgresql-9.6.service - PostgreSQL | + | ● postgresql.service - PostgreSQL database server |
- | | + | |
- | | + | |
- | Main PID: 2626 (postmaster) | + | Main PID: 25715 (postmaster) |
- | | + | Tasks: 8 (limit: 52428) |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | └─2634 postgres: stats collector | + | |
+ | | ||
+ | ├─25722 postgres: stats collector | ||
+ | | ||
- | lis 18 23:50:06 tomcat1.localdomain | + | Mar 11 10:48:06 HOSTNAME |
- | lis 18 23:50:06 tomcat1.localdomain | + | Mar 11 10:48:06 HOSTNAME postmaster[25715]: |
- | lis 18 23:50:06 tomcat1.localdomain | + | Mar 11 10:48:06 HOSTNAME |
- | lis 18 23:50:06 tomcat1.localdomain | + | Mar 11 10:48:06 HOSTNAME postmaster[25715]: |
+ | Mar 11 10:48:06 HOSTNAME postmaster[25715]: | ||
+ | Mar 11 10:48:06 HOSTNAME postmaster[25715]: | ||
+ | Mar 11 10:48:06 HOSTNAME postmaster[25715]: | ||
+ | Mar 11 10:48:06 HOSTNAME | ||
+ | Mar 11 10:48:06 HOSTNAME | ||
</ | </ | ||
- | ==== Database server installation - Debian Stretch ==== | + | |
- | Install the database from OS packages: | + | |
- | < | + | |
- | apt-get install postgresql-9.6 | + | |
- | </ | + | |
- | We will move the database - create directory structure: | + | |
- | < | + | |
- | mkdir -p / | + | |
- | chown -R postgres: | + | |
- | chmod -R 700 / | + | |
- | </ | + | |
- | Create the file .bash\_profile in postgres user's home (default / | + | |
- | < | + | |
- | PGDATA=/ | + | |
- | </ | + | |
- | Stop the database: | + | |
- | < | + | |
- | systemctl stop postgresql | + | |
- | </ | + | |
- | Move database directory (run this as root): | + | |
- | < | + | |
- | mv / | + | |
- | </ | + | |
- | In the PostgreSQL configuration file / | + | |
- | < | + | |
- | data_directory = '/ | + | |
- | </ | + | |
- | Enable and start the database: | + | |
- | < | + | |
- | systemctl start postgresql | + | |
- | systemctl enable postgresql | + | |
- | </ | + | |
==== DB server configuration ==== | ==== DB server configuration ==== | ||
- | First of all, enable | + | * Enable |
- | In the file ''/ | + | In the file ''/ |
< | < | ||
host all | host all | ||
host all | host all | ||
</ | </ | ||
- | + | and change the value at the end of each line to '' | |
- | and change the value at the end of each line into md5 like this: | + | |
< | < | ||
host all | host all | ||
Line 193: | Line 157: | ||
</ | </ | ||
- | Now we can do DB sizing. | + | * Adjust |
- | In a file ''/ | + | * In following snippet, we presume the system has 3GB of memory |
+ | * We also log queries running longer than 200ms. | ||
+ | In a file ''/ | ||
< | < | ||
- | max_connections = 100 # (change requires restart) | + | # This is an EXAMPLE. Use the calculator to adjust for your deployment! |
- | shared_buffers = 768MB # min 128kB | + | # DB Version: 12 |
+ | # OS Type: linux | ||
+ | # DB Type: web | ||
+ | # Total Memory (RAM): 3 GB | ||
+ | # Connections num: 100 | ||
+ | # Data Storage: ssd | ||
+ | max_connections = 100 | ||
+ | shared_buffers = 768MB | ||
effective_cache_size = 2304MB | effective_cache_size = 2304MB | ||
- | work_mem = 7864kB | ||
maintenance_work_mem = 192MB | maintenance_work_mem = 192MB | ||
- | |||
- | min_wal_size = 1GB | ||
- | max_wal_size = 2GB | ||
checkpoint_completion_target = 0.7 | checkpoint_completion_target = 0.7 | ||
wal_buffers = 16MB | wal_buffers = 16MB | ||
- | |||
default_statistics_target = 100 | default_statistics_target = 100 | ||
+ | random_page_cost = 1.1 | ||
+ | effective_io_concurrency = 200 | ||
+ | work_mem = 3932kB | ||
+ | min_wal_size = 1GB | ||
+ | max_wal_size = 4GB | ||
log_min_duration_statement = 200 | log_min_duration_statement = 200 | ||
</ | </ | ||
- | Restart DB: '' | + | Restart DB: '' |
- | + | ||
- | For Debian installation, | + | |
- | < | + | |
- | / | + | |
- | / | + | |
- | </ | + | |
< | < | ||
- | ===== Java - CentOS7 | + | ===== Java - CentOS8 |
- | Java must be installed before Tomcat start. It is recommended to use OpenJDK (at least 1.8) from standard OS repository. | + | Java must be installed before Tomcat start. It is recommended to use OpenJDK (at least 1.11) from standard OS repository. |
Installation: | Installation: | ||
<code bash> | <code bash> | ||
- | yum install -y java-1.8.0-openjdk-headless java-1.8.0-openjdk-devel | + | yum install -y java-11-openjdk-headless java-11-openjdk-devel |
</ | </ | ||
Line 237: | Line 205: | ||
</ | </ | ||
- | ===== Java - Debian ===== | ||
- | |||
- | Java must be installed before Tomcat start. It is recommended to use OpenJDK (at least 1.8) from standard OS repository. | ||
- | |||
- | Installation: | ||
- | <code bash> | ||
- | apt-get install openjdk-8-jdk-headless openjdk-8-jre-headless | ||
- | </ | ||
- | |||
- | Then create the file ''/ | ||
- | <file bash java.sh> | ||
- | [ -d / | ||
- | </ | ||
===== Tomcat ===== | ===== Tomcat ===== | ||
- | * Create a new group and add user for the tomcat to run under (for Debian, use / | + | * Create a new group and add user for the tomcat to run under: |
< | < | ||
Line 259: | Line 214: | ||
useradd -r -s / | useradd -r -s / | ||
getent passwd tomcat | getent passwd tomcat | ||
- | tomcat: | + | #tomcat: |
</ | </ | ||
Line 341: | Line 296: | ||
* Tomcat will be started under user '' | * Tomcat will be started under user '' | ||
- | * For Debian, change the JAVA\_HOME to '' | ||
* After every systemd configuration change it is necessary to reload: | * After every systemd configuration change it is necessary to reload: | ||
Line 423: | Line 377: | ||
It is advised to follow these steps for production usage: | It is advised to follow these steps for production usage: | ||
- | * Remove unnecessary | + | * Remove unnecessary |
<code bash> | <code bash> | ||
Line 435: | Line 389: | ||
<Server port=" | <Server port=" | ||
</ | </ | ||
+ | |||
* Make Tomcat listen only on localhost: | * Make Tomcat listen only on localhost: | ||
- | * In the ''/ | + | * In the ''/ |
+ | |||
+ | * Set the '' | ||
+ | * In the ''/ | ||
+ | |||
+ | * In same file configure ajp port('' | ||
+ | |||
+ | < | ||
+ | < | ||
+ | address=" | ||
+ | secretRequired=" | ||
+ | secret=" | ||
+ | port=" | ||
+ | redirectPort=" | ||
+ | </ | ||
* Do not show aplication server version: | * Do not show aplication server version: | ||
Line 465: | Line 434: | ||
<file txt tomcat> | <file txt tomcat> | ||
/ | / | ||
- | rotate | + | rotate |
daily | daily | ||
dateext | dateext | ||
Line 489: | Line 458: | ||
* Adjust particular SELinux labels. Example ([[https:// | * Adjust particular SELinux labels. Example ([[https:// | ||
</ | </ | ||
- | |||
- | Please note that on Debian, the log is not rotate during the first day, but after the second day. | ||
Line 507: | Line 474: | ||
<code bash> | <code bash> | ||
yum install -y httpd httpd-tools mod_ssl mod_security mod_security_crs | yum install -y httpd httpd-tools mod_ssl mod_security mod_security_crs | ||
- | </ | ||
- | |||
- | On Debian install those packages and allow modules: | ||
- | < | ||
- | apt-get install apache2 libapache2-mod-security2 modsecurity-crs | ||
- | a2enmod ssl | ||
- | a2enmod proxy | ||
- | a2enmod proxy_ajp | ||
- | a2enmod proxy_http | ||
- | a2enmod security2 | ||
- | a2enmod rewrite | ||
- | a2enmod headers | ||
</ | </ | ||
HTTPd basic configuration: | HTTPd basic configuration: | ||
- | Change MPM to worker (lower system requirements) - in the file ''/ | + | Change MPM to worker (lower system requirements) - in the file ''/ |
<code bash> | <code bash> | ||
Line 553: | Line 508: | ||
</ | </ | ||
- | Virtualhost configuration to forward the communication from port 80 to 443. Add following section and change string ' | + | Virtualhost configuration to forward the communication from port 80 to 443. Add following section and change string ' |
<code xml> | <code xml> | ||
< | < | ||
Line 561: | Line 516: | ||
</ | </ | ||
- | Set the proxy in the virtualhost for https (443/tcp) - at the end of the file ''/ | + | Set the proxy in the virtualhost for https (443/tcp) - at the end of the file ''/ |
< | < | ||
+ | Protocols | ||
ProxyRequests | ProxyRequests | ||
ProxyPreserveHost on | ProxyPreserveHost on | ||
ProxyAddHeaders on | ProxyAddHeaders on | ||
- | ProxyPass / ajp:// | + | ProxyPass / ajp:// |
- | ProxyPassReverse / ajp:// | + | ProxyPassReverse / ajp:// |
</ | </ | ||
Line 593: | Line 549: | ||
</ | </ | ||
< | < | ||
- | |||
- | On Debian, create symlinks to sites-enabled: | ||
- | < | ||
- | cd / | ||
- | ln -s ../ | ||
- | ln -s ../ | ||
- | </ | ||
Syntax check before httpd restart: | Syntax check before httpd restart: | ||
Line 611: | Line 560: | ||
</ | </ | ||
+ | Allow in SELINUX to httpd connect to network: | ||
+ | < | ||
+ | / | ||
+ | </ | ||
+ | |||
Enable httpd after OS start: | Enable httpd after OS start: | ||
<code bash> | <code bash> | ||
Line 617: | Line 571: | ||
===== mod_security configuration ===== | ===== mod_security configuration ===== | ||
- | Mod_security files locations (on CentOS7): | + | Mod_security files locations (on CentOS8): |
* Audit log: ''/ | * Audit log: ''/ | ||
* Directory with activated rules: ''/ | * Directory with activated rules: ''/ | ||
- | * basic configuration file for mod\_security: | + | * basic configuration file for mod\_security: |
* The file for chosen rules deactivation: | * The file for chosen rules deactivation: | ||
Line 636: | Line 590: | ||
==== Disabling mod_security rules ==== | ==== Disabling mod_security rules ==== | ||
- | In the file ''/ | + | These rules are disabled for modsec_crs 3.0. |
+ | |||
+ | In the file ''/ | ||
<code xml> | <code xml> | ||
< | < | ||
- | SecRuleRemoveById | + | SecRuleRemoveById |
- | SecRuleRemoveById | + | SecRuleRemoveById |
- | SecRuleRemoveById | + | SecRuleRemoveById |
+ | | ||
+ | | ||
# Allow Czech signs | # Allow Czech signs | ||
- | SecRuleRemoveById | + | SecRuleRemoveById |
- | SecRuleRemoveById | + | SecRuleRemoveById |
- | SecRuleRemoveById | + | SecRuleRemoveById |
- | SecRuleRemoveById | + | SecRuleRemoveById |
| | ||
# Too restrictive for login format | # Too restrictive for login format | ||
- | SecRuleRemoveById | + | SecRuleRemoveById |
+ | |||
# Needed by Websockets | # Needed by Websockets | ||
< | < | ||
- | SecRuleRemoveById | + | SecRuleRemoveById |
</ | </ | ||
| | ||
- | # These break Certificate Authority module | ||
- | < | ||
- | SecRuleRemoveById 960915 | ||
- | SecRuleRemoveById 200003 | ||
- | </ | ||
- | |||
- | # Modsec can throw false positives on some files due to multipart boundary check | ||
- | < | ||
- | SecRuleRemoveById 960915 | ||
- | SecRuleRemoveById 200003 | ||
- | </ | ||
- | |||
# do not log request/ | # do not log request/ | ||
SecAuditLogParts ABFHZ | SecAuditLogParts ABFHZ | ||
Line 674: | Line 620: | ||
</ | </ | ||
- | ==== mod_security configuration - CentOS7 | + | ==== mod_security configuration - CentOS8 |
- | In the file / | + | In the file / |
- | Whole rule after the changes looks like this: | + | |
+ | * find the rule 900200 | ||
< | < | ||
- | SecAction | + | # Default HTTP policy: allowed_methods (rule 900200) |
- | "id:' | + | SecRule & |
- | phase:1, \ | + | "id:901160,\ |
- | | + | phase:1,\ |
- | setvar:' | + | pass,\ |
- | setvar:' | + | |
- | setvar:' | + | |
- | setvar:' | + | |
- | setvar:' | + | |
- | nolog, \ | + | |
- | pass" | + | |
</ | </ | ||
- | ==== mod_security configuration - Debian ==== | + | * find the rule 900220 and add support for content\_type=application/json, application/hal+json and text/plain on the line starting with tx.allowed\_request\_content\_type, |
- | Enable mod\_security configuration: | + | |
- | < | + | |
- | cd /etc/modsecurity | + | |
- | cp modsecurity.conf-recommended modsecurity.conf | + | |
- | </ | + | |
- | Uncomment following rules in the ''/ | ||
< | < | ||
- | SecAction \ | + | # Default HTTP policy: allowed_request_content_type (rule 900220) |
- | " | + | SecRule &TX:allowed_request_content_type "@eq 0" \ |
- | phase:1,\ | + | "id:901162,\ |
- | nolog,\ | + | phase:1,\ |
- | pass,\ | + | pass,\ |
- | t:none,\ | + | nolog,\ |
- | setvar:' | + | setvar:' |
- | + | ||
- | SecAction | + | |
- | " | + | |
- | phase:1,\ | + | |
- | | + | |
- | | + | |
- | | + | |
- | setvar:' | + | |
</ | </ | ||
Line 758: | Line 687: | ||
</ | </ | ||
- | ===== Workaround for slow HTTPD shutdown ===== | ||
- | In some RHEL/CentOS versions Apache HTTPD shutsdown or restarts itself very slowly. It is caused by [[https:// | ||
- | Workaround is to edit '''/ | ||
- | < | ||
- | KillMode=none | ||
- | </ | ||
- | Then reload systemd: | ||
- | |||
- | < | ||
- | systemctl daemon-reload | ||
- | </ | ||
- | |||
- | It is absolutely correct to create new versions of unity in /etc, that has the option: | ||
- | |||
- | < | ||
- | cp / | ||
- | vim / | ||
- | systemctl daemon-reload | ||
- | </ | ||
- | |||
- | The patch of httpd should come soon so the first option is OK too. | ||
- | |||
- | ===== SSO ===== | ||
- | |||
- | If you want to enable SSO to CzechIdM, additional configuration must be done with mod\_auth\_kerb. See [[tutorial: | ||
- | |||
- | ====== nginx as reverse proxy ====== | ||
- | |||
- | In case that you want to use nginx instead of Apache httpd, the configuration is as follows. | ||
- | |||
- | <code ini> | ||
- | server { | ||
- | listen | ||
- | server_name | ||
- | client_max_body_size 1G; | ||
- | ssl on; | ||
- | ssl_certificate | ||
- | ssl_certificate_key | ||
- | gzip on; | ||
- | gzip_proxied any; | ||
- | gzip_types | ||
- | text/css | ||
- | | ||
- | text/xml | ||
- | | ||
- | application/ | ||
- | | ||
- | application/ | ||
- | |||
- | location / { | ||
- | proxy_hide_header X-Frame-Options; | ||
- | add_header X-Frame-Options SAMEORIGIN; | ||
- | proxy_pass http:// | ||
- | proxy_set_header Host $host; | ||
- | proxy_set_header X-Real-IP $remote_addr; | ||
- | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
- | proxy_set_header X-Forwarded-Proto " | ||
- | proxy_ssl_session_reuse off; | ||
- | proxy_redirect off; | ||
- | |||
- | # WebSocket support | ||
- | proxy_http_version 1.1; | ||
- | proxy_set_header Upgrade $http_upgrade; | ||
- | proxy_set_header Connection " | ||
- | } | ||
- | } | ||
- | </ | ||