CentOS8 -Install nginx, Apache, Redis, php7.4-fpm, MySQL, PostgreSQL

From Rhomicom Wiki
Jump to navigation Jump to search

Install nginx

 sudo dnf update
 sudo dnf install nginx mod_ssl
 sudo systemctl start nginx
 grep processor /proc/cpuinfo | wc -l
 ulimit -n

TEST

 curl -4 http://your_url

CENTOS 8

#WHEN yum update gives error. 
cd /etc/yum.repos.d/. 
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*. 
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*. 
yum update -y.

SSL

 Visit SELinux,Fail2ban,Security Configurations for all other Security Configurations

Or Install Apache

 yum -y install httpd httpd-tools mod_ssl
 sudo systemctl status httpd
 sudo systemctl start httpd.service
 sudo systemctl enable httpd.service

Install MySQL

 sudo dnf install mysql-server
 sudo systemctl start mysqld
 sudo systemctl enable mysqld
 sudo mysql_secure_installation
 sudo grep 'temporary password' /var/log/mysqld.log
 mysql -u [user] -p
 create database [database_name];
 mysql -u [new_user] -p [database_name] < [file_name].sql
 mysql -u root -p rhomicom < rhomicom.sql
 #Backup of all databases
 mysqldump -u [user] -p all-databases > [file_name].sql

INSTALL REDIS

 dnf module install redis
 
 sysctl vm.overcommit_memory=1 (# nano /etc/sysctl.conf)
 echo never > /sys/kernel/mm/transparent_hugepage/enabled
 systemctl start redis
 systemctl enable redis
 systemctl status redis
 ss -tlpn
 redis-cli (#PING -> PONG)

INSTALL PHP

 sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
 sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
 sudo dnf install dnf-utils
 sudo dnf module list php
 sudo dnf module install php:remi-7.4
 sudo dnf install -y php-fpm php-cli php-common php-zip php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-pdo php-mysqlnd php-pgsql
 sudo dnf install php-fpm php-opcache php-openssl php-curl php-cli php-common php-zip php-gd php-xml php-pear php-bcmath php-json php-pdo php-mysqlnd php-pgsql php-mbstring  php-soap php-sockets php-pecl-apcu php-json php-ctype php-dom php-exif php-mysqli php-iconv php-fileinfo
 php -v
 sudo nano /etc/php.ini   #Add cgi.fix_pathinfo=0
  max_execution_time = 600
  max_input_time = 600
  disable_functions =exec,passthru,shell_exec,system,proc_open,popen,curl_multi_exec,parse_ini_file,show_source,phpinfo,apache_child_terminate,apache_setenv,define_syslog_variables, eval, ftp_connect, ftp_exec, ftp_get, ftp_login, ftp_nb_fput, ftp_put, ftp_raw, ftp_rawlist,highlight_file,ini_alter,ini_get_all,ini_restore,inject_code,mysql_pconnect,openlog,phpAds_remoteInfo,phpAds_XmlRpc,phpAds_xmlrpcDecode,phpAds_xmlrpcEncode,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,posix_setuid,posix_uname,proc_close,proc_get_status,proc_nice,proc_terminate,syslog,xmlrpc_entity_decode,curl_exec
 sudo nano /etc/php-fpm.d/www.conf
 sudo nano /etc/php-fpm.d/www.conf  #(Change user and group to nginx)
 sudo systemctl start php-fpm
 systemctl status php-fpm.service
 sudo systemctl restart nginx
 nano /etc/php.ini
  # session.save_handler = redis
  # session.save_path = tcp://127.0.0.1:6379
 nano /etc/php-fpm.d/www.conf
  # php_value[session.save_handler] = redis
  # php_value[session.save_path]    = tcp://127.0.0.1:6379

Install PostgreSQL

  dnf module list postgresql
  sudo dnf module enable postgresql:12
  sudo dnf install postgresql-server
  sudo postgresql-setup --initdb
  sudo systemctl start postgresql
  sudo systemctl enable postgresql

  su - postgres -c "psql"
  \password postgres
  systemctl restart postgresql
  OR pg_ctl reload
  OR pg_ctl restart

  cd /var/lib/pgsql/data/
  nano pg_hba.conf
  nano postgresql.conf

  SELECT * FROM pg_settings;
  SELECT * FROM pg_settings WHERE pending_restart = true;
  SELECT * FROM pg_stat_user_tables;
  show work_mem;
  SHOW ALL;
  alter system set work_mem='64MB';
  SELECT pg_reload_conf();
  \l  #SHOW DATABASE
  \c testdb;
  "\s" to see your command history there.
  \timing
  select 1;

 pg_dump --file "/opt/apache/tacms/communications.sql" --host "tacms-pgdb" --port "5432" --username "postgres" --verbose --role "postgres" --format=p --encoding "UTF8" --column-inserts --table "public.communications" "tacmsapi"

VACUUM FULL FREEZE VERBOSE ANALYZE
REINDEX DATABASE {:dbase_name}

pg_dump -h localhost -p 5432 -U postgres -F c -b -v -f "/home/dbadmin/schema_dbs/test_db_$(date +%d%m%y)_test_db.backup" test_db
pg_dump -n 'accb' -h localhost -p 5432 -U postgres -F c -b -v -f "/home/dbadmin/schema_dbs/accb_$(date +%d%m%y)_test_db.backup" test_db
pg_restore -h localhost -p 5432 -U postgres -d test_db -v "/home/rhoportal/others/test_db_12345.backup"


https://pgtune.leopard.in.ua/

# DB Version: 14
# OS Type: linux
# DB Type: web
# Total Memory (RAM): 32 GB
# CPUs num: 8
# Connections num: 9997
# Data Storage: ssd

ALTER SYSTEM SET max_connections = '9997';
ALTER SYSTEM SET shared_buffers = '8GB';
ALTER SYSTEM SET effective_cache_size = '24GB';
ALTER SYSTEM SET maintenance_work_mem = '2GB';
ALTER SYSTEM SET checkpoint_completion_target = '0.9';
ALTER SYSTEM SET wal_buffers = '16MB';
ALTER SYSTEM SET default_statistics_target = '100';
ALTER SYSTEM SET random_page_cost = '1.1';
ALTER SYSTEM SET effective_io_concurrency = '200';
ALTER SYSTEM SET work_mem = '64MB';
ALTER SYSTEM SET min_wal_size = '1GB';
ALTER SYSTEM SET max_wal_size = '4GB';
ALTER SYSTEM SET max_worker_processes = '8';
ALTER SYSTEM SET max_parallel_workers_per_gather = '0';
ALTER SYSTEM SET max_parallel_workers = '8';
ALTER SYSTEM SET max_parallel_maintenance_workers = '4';

# DB Version: 13
# OS Type: linux
# DB Type: web
# Total Memory (RAM): 16 GB
# CPUs num: 4
# Connections num: 9997
# Data Storage: ssd

ALTER SYSTEM SET max_connections = '9997';
ALTER SYSTEM SET shared_buffers = '4GB';
ALTER SYSTEM SET effective_cache_size = '12GB';
ALTER SYSTEM SET maintenance_work_mem = '1GB';
ALTER SYSTEM SET checkpoint_completion_target = '0.9';
ALTER SYSTEM SET wal_buffers = '16MB';
ALTER SYSTEM SET default_statistics_target = '100';
ALTER SYSTEM SET random_page_cost = '1.1';
ALTER SYSTEM SET effective_io_concurrency = '200';
ALTER SYSTEM SET work_mem = '64MB';
ALTER SYSTEM SET min_wal_size = '1GB';
ALTER SYSTEM SET max_wal_size = '4GB';
ALTER SYSTEM SET max_worker_processes = '4';
ALTER SYSTEM SET max_parallel_workers_per_gather = '0';
ALTER SYSTEM SET max_parallel_workers = '4';
ALTER SYSTEM SET max_parallel_maintenance_workers = '2';
ALTER SYSTEM SET checkpoint_completion_target = '0.9';
ALTER SYSTEM SET archive_mode = 'on';
ALTER SYSTEM SET archive_command = '/bin/true';
ALTER SYSTEM SET autovacuum_vacuum_scale_factor = '0.4';
ALTER SYSTEM SET bgwriter_lru_maxpages = '1000';
ALTER SYSTEM SET bgwriter_lru_multiplier = '10.0';
ALTER SYSTEM SET wal_compression = 'ON';
ALTER SYSTEM SET log_checkpoints = 'ON';
ALTER SYSTEM SET log_autovacuum_min_duration = '0';
alter user postgres set max_parallel_workers_per_gather=0;

max_connections = '200'
shared_buffers = '32GB'
checkpoint_timeout = '1h'
max_wal_size = '96GB'
checkpoint_completion_target = '0.9'
archive_mode = 'on'
archive_command = '/bin/true'
random_page_cost = '1.0'
effective_cache_size = '80GB'
maintenance_work_mem = '2GB'
autovacuum_vacuum_scale_factor = '0.4'
bgwriter_lru_maxpages = '1000'
bgwriter_lru_multiplier = '10.0'
wal_compression = 'ON'
log_checkpoints = 'ON'
log_autovacuum_min_duration = '0'


nano postgresql.conf

shared_preload_libraries = 'pg_cron'             (-- Need server restart)
cron.database_name = 'postgres'
	
-- run as superuser:
CREATE EXTENSION pg_cron;

-- optionally, grant usage to regular users:
GRANT USAGE ON SCHEMA cron TO postgres;
SELECT cron.schedule('manual vacuum', '0 0 * * 5', 'VACUUM FULL FREEZE VERBOSE ANALYZE');
select * from cron.job;
select * from cron.job_run_details;
SHOW cron.log_run;
SELECT cron.unschedule(2);
SELECT cron.schedule('0 0 * * *', $$DELETE FROM cron.job_run_details WHERE end_time < now() – interval '7 days'$$);

INSTALL WEBMIN

 yum -y install perl-Digest-Perl-MD5
 yum -y install perl-Digest-MD5
 yum -y install perl-DBD-Pg
 nano /etc/yum.repos.d/webmin.repo
  [Webmin]
  name=Webmin Distribution Neutral
  #baseurl=http://download.webmin.com/download/yum
  mirrorlist=http://download.webmin.com/download/yum/mirrorlist
  enabled=1
  wget http://www.webmin.com/jcameron-key.asc
  rpm --import jcameron-key.asc
  yum -y update
  yum -y install webmin
  service webmin start
  chkconfig webmin on
  sudo firewall-cmd --zone=public --add-port=10000/tcp --permanent
  sudo firewall-cmd --reload

INSTALL JAVA

 sudo dnf install java-11-openjdk-devel
 #OPEN JRE
 sudo yum -y install java-1.8.0-openjdk
 #OPEN JDK
 sudo yum -y install java-1.8.0-openjdk-devel
 #ORACLE JDK -- AFTER DOWNLOAD
 sudo yum localinstall jdk-8u181-linux-x64.rpm
 java -version
 sudo alternatives --config java
 sudo sh -c "echo export JAVA_HOME=/usr/java/jdk1.8.0_181-amd64/jre >> /etc/environment"

INSTALL FONTS

 sudo yum -y install wkhtmltopdf;
 yum -y install curl cabextract xorg-x11-font-utils fontconfig
 rpm -i http://mirror.centos.org/centos/8/AppStream/x86_64/os/Packages/libmspack-0.7-0.3.alpha.el8.4.x86_64.rpm
 rpm -i https://pkgs.dyn.su/el8/base/x86_64/cabextract-1.9-2.el8.x86_64.rpm
 rpm -i https://downloads.sourceforge.net/project/mscorefonts2/rpms/msttcore-fonts-installer-2.6-1.noarch.rpm
 rpm -i msttcore-fonts-installer-2.6-1.noarch.rpm
 rpm -i http://li.nux.ro/download/nux/dextop/el7/x86_64/webcore-fonts-3.0-1.noarch.rpm
 dnf install xorg-x11-fonts-misc
 #On Ubuntu
 fc-cache -f -v
 sudo cp -r ~/Downloads/fonts /usr/share/fonts/truetype/
 #Font files should have the permission of 644 and the containing folder should have 755
 sudo apt-get install font-manager