Server Setup on CentOS 7 for Keitaro TDS

Here is the instruction that helps you setup a newly installed server based on CentOS 7 to achieve stability and high performance of Keitaro TDS.

How to check CentOS version?

Make sure that the 7th version of CentOS is installed:

cat /etc/redhat-release

CentOS repositories and Kernel configuration

At first upgrade your current system packages

yum -y update

Add REMI and EPEL repositories.They have the latest versions of NGinx, PHP, MariaDB.

sudo yum install -y epel-release
cd /etc/yum.repos.d


# CentOS 6
rpm -Uvh
#CentOS 7
rpm -Uvh

Installing of utilities:

yum -y install htop nano

Installing variables of the operating system for stability of Redis:

echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf
echo "net.core.somaxconn=512" >> /etc/sysctl.conf
echo "fs.file-max = 70000" >> /etc/sysctl.conf
sysctl -p



yum -y install mariadb mariadb-server

Launch and add to the autoloading:

systemctl start mariadb
chkconfig mariadb on



yum -y install redis

Launch and add to the autoloading:

systemctl start redis
chkconfig redis on



yum -y install nginx 

Edit the configuration file:

nano /etc/nginx/nginx.conf

Set worker_processes auto; and below add the line worker_rlimit_nofile 10000; — it indicates how many file descriptors will be used by Nginx.

worker_processes auto;
worker_rlimit_nofile 10000;

Launch and add to the autoloading:

systemctl start nginx
chkconfig nginx on


Installing of PHP 7.0 and additional extensions:

yum -y install php70 php70-php-fpm php70-php-devel php70-php-mysqlnd php70-php-pecl-redis php70-php-mbstring php70-php-pear  php70-php-ioncube-loader php70-php-pecl-zip

Creating a symlinks (Optional):

ln -s /bin/php70 /bin/php
ln -s /etc/opt/remi/php70 /etc/php

Open the configuration file:

nano /etc/opt/remi/php70/php-fpm.d/www.conf

Insert the values:

user = nginx
group = nginx

listen = /var/run/php7-fpm.sock
listen.owner = nginx = nginx
listen.mode = 0660

pm = ondemand
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.process_idle_timeout = 10s
pm.max_requests = 500

Save and close. CTRL+XYENTER.

Launch and add to the autoloading:

systemctl start php70-php-fpm
chkconfig php70-php-fpm on



yum install -y monit

Create files for a monitoring process in the directory /etc/monit.d/.


check process nginx with pidfile /var/run/
    start program = "/bin/systemctl start nginx"
    stop program = "/bin/systemctl stop nginx"


check process mariadb with pidfile /var/run/mariadb/
    start program = "/bin/systemctl start mariadb"
    stop program = "/bin/systemctl stop mariadb"


check process php56-php-fpm with pidfile /opt/remi/php56/root/var/run/php-fpm/
    start program = "/bin/systemctl start php56-php-fpm"
    stop program = "/bin/systemctl stop php56-php-fpm"

Check if the configuration file is correct::

monit -t

Restart monit:

monit reload

You can run all the processes:

monit start all

Launch and add to the autoloading:

systemctl start monit
chkconfig monit on

Creating SWAP

On the servers with memory less than 1 Gb you need to enable swap. Otherwise, your server can get a lack of memory for the database.

Preparing the swap file:

cd /var
touch swap.img
chmod 600 swap.img

File formatting. File size 1024*1000 = 1 024 000 byte.

dd if=/dev/zero of=/var/swap.img bs=1024k count=1000

Connecting the swap file:

mkswap /var/swap.img
swapon /var/swap.img
echo "/var/swap.img    none    swap    sw    0    0" >> /etc/fstab

Настройка MySQL/MariaDB (не обязательно)

nano /etc/my.cnf

Добавьте под секцию [mysqld]

skip-name-resolve = 1 
query-cache-type = 0
query-cache-size = 32M
innodb-buffer-pool-size = 500M # a half of your RAM size

Creating a database

Running a shell MySQL/MariaDB:


Creating a user:

CREATE USER 'tds'@'localhost' IDENTIFIED BY '012e-f23rh2e';

Create a new database:


Giving access to a user on a database:

GRANT ALL PRIVILEGES ON tds. * TO 'tds'@'localhost';

Keitaro TDS

Script for a quickly generation of host configuration for nginx and php-fpm

bash <(curl -s '')

You will be asked some questions. Here is an example of using the script:

Please, enter domain name:
Please, enter server IP:
Please, enter domain directory:
Please, enter config directory:

Checking if the configuration is correct.

nginx -t

Here is an example of the correct configuration:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Creating a directory for TDS.

mkdir -p /var/www/
chown nginx:nginx /var/www/
chmod 777 /var/www/

Download the installer.

wget  -O /var/www/ 

You can open in browser now and start the installation.


If you see an error in the browser “File not found”, probably SeLinux is enabled. You can configure the rules in the following way:

yum install -y policycoreutils-devel
grep nginx /var/log/audit/audit.log | audit2allow -M nginx
semodule -i nginx.pp


During the installation you will be asked to add a task to the crontab. Here is an instruction below.

Editing of the tasks list for the user nginx:

crontab -e -u nginx

Press i, insert:

* * * * * php /var/www/

Press ESC, enter the save and close file command :wq.

Playbook for Ansible

Ansible-script for automatic server preparation: