Setup Process

From PM Wiki
Jump to navigation Jump to search

Server Specification

We’re assuming the following conditions were met for the system:

  • At least 16Gb of ram
  • At least 200Gb SSD running on Raid10 for redundancy (I recommend to use NVMe for the best performance)
  • At least 10 CPU Cores
  • 1Gbps private ethernet connections between servers
  • CentOS 7 minimal install

Here is the recommended spec for the servers

  • 192Gb ram
  • 120Gb RAID1 SSD for the OS boot and 256Gb RAID1 NVMe for the data partition
  • 1Gbps NIC that will run on 2 VLAN, 1 for private network and 1 for public network
  • Dual E5-4650v2

Please follow these steps in this specific order.

General Installation

Here are the legworks that will need to be ran across all of the servers

yum -y install epel-release
rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum -y update && yum clean all
yum -y install httpd httpd-devel mod_ssl && yum clean all
yum -y install gcc make openssl-devel python34 python34-devel python34-setuptools python-pip python-setuptools nano wget vim\vim-enhanced bash-completion yum-utils git
yum groupinstall -y base && yum groupinstall -y 'Development Tools
yum clean all
yum-config-manager --enable remi-php74
For normal server
yum install -y php php-devel php-pear php-common php-dba php-gd php-intl php-ldap php-mbstring php-mysqlnd php-odbc php-pdo php-pecl-memcache php-pgsql php-pspell php-recode php-snmp php-soap php-xml php-zip php-xmlrpc
For AWS 
run "sudo amazon-linux-extras install php8.0" and "yum -y install php-pear php-devel php-mbstring php-xml php-zip php-gd php-intl php-ldap"
printf "\n" | pecl install mongodb
echo short_open_tag=On >> /etc/php.ini
echo extension=mongodb.so >> /etc/php.ini
yum -y install libgearman libgearman-devel
For normal server
cd /opt && git clone https://github.com/wcgallego/pecl-gearman.git
cd /opt/pecl-gearman && phpize && ./configure && make && make install
For AWS
cd /opt && git clone https://github.com/php/pecl-networking-gearman.git
cd /opt/pecl-networking-gearman && phpize && ./configure && make && make install

echo extension=gearman.so >> /etc/php.ini 


sed -i 's/allow_url_include = Off/allow_url_include = On/g' /etc/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 200M/g' /etc/php.ini
sed -i 's/post_max_size = 8M/post_max_size = 200M/g' /etc/php.ini
sed -i 's/memory_limit = 128M/memory_limit = -1/g' /etc/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 1800/g' /etc/php.ini
echo date.timezone = America/New_York >> /etc/php.ini
sed -i 's/AllowOverride None/AllowOverride All/g' /etc/httpd/conf/httpd.conf 
yum install ntp ntpdate -y && ntpdate -u -s 0.centos.pool.ntp.org 1.centos.pool.ntp.org 2.centos.pool.ntp.org && \cp -r /usr/share/zoneinfo/America/New_York /etc/localtime
easy_install pip
pip install supervisor

Code Deployment:

There are several ways that you can deploy the code to the servers, git, deployhq, Jenkins, scp are some of the most common ways, or you can also just zip and upload via filezilla. I will not cover the code deployment in this tutorial. Here are the main things after you’ve already uploaded the code.

  • Make sure the main folders (bin,ddl,etc,www) reside inside this directory, /var/www/html/.
  • Make sure in the apache’s vhost config file, you point the DocumentRoot to /var/www/html/www/public for the backend, and /var/www/html/www for the frontend.
  • Make sure to edit the .env for the backend to reflect the correct credentials to the MongoDB and MySQL
  • Make sure to edit the config.php file to reflect the correct API server’s URL
  • Make sure to edit the /var/www/html/www/public/index.php to add the correct URL of the frontend’s URL
  • Run “composer require” to install all necessary 3rd party libraries
  • Make sure you set permissions accordingly and disable selinux
  • “chmod 755 -R /var/www/html/www/public” AND “chmod 755 -R “/var/www/html/www/writable”
  • “chown apache:apache -R /var/www/html/www/public” AND “chown apache:apache -R /var/www/html/www/writable”
  • setenforce 0

Database Deployment

You can use PHPMySQL or plenty of other platforms out there to import the SQL file in the “DDL” folder. I recommend Heidi as it’s the tool that I use to export the SQL file in the development environment.

Gearmand Deployment

On the worker’s servers, we can launch gearmand by issuing these commands "yum -y install libgearman libgearman-devel gearmand" and “gearmand --listen 0.0.0.0 --port 8888 --log-file /var/log/gearmand.log -d” In this command, we set it to listen on ALL IPs via port 8888 in this machine, this is very insecure. I recommend that we set it to only listen to private IP that can communicate with other machines in the network, ie 192.168.X.Y. One thing about gearmand is, its log file can get pretty big over time, so we definitely need to keep an eye on the log file to make sure it won’t take up too much space on the hard drive.

On AWS, do this

cd /tmp
wget https://github.com/gearman/gearmand/releases/download/1.1.20/gearmand-1.1.20.tar.gz
tar zxf gearmand-1.1.20.tar.gz
cd gearmand-1.1.20
./configure 
make
make install
useradd -M -G daemon gearmand
mkdir -p /var/run/gearmand/
touch /var/log/gearmand.log
chown gearmand:gearmand /var/log/gearmand.log
touch /etc/sysconfig/gearmand
chmod 777 /etc/sysconfig/gearmand
echo -e 'OPTIONS="--listen=10.30.1.86 --port=8888 --job-retries=3 --verbose ERROR --log-file=/var/log/gearmand.log"' > /etc/sysconfig/gearmand
chmod 644 /etc/sysconfig/gearmand
cp support/gearmand.init /etc/init.d/gearmand
chmod a+x /etc/init.d/gearmand
chkconfig --add gearmand
chkconfig gearmand on
service gearmand start

Supervisor Deployment

On the worker’s machine, make sure to install composer using this tutorial first, "https://phoenixnap.com/kb/how-to-install-and-use-php-composer-on-centos-7", then go to /var/www/html/www to run "composer update" to upgrade composer, after that, run this command “supervisord -c /var/www/html/etc/supervisord.conf” This command will launch supervisord and kick start the worker’s processes. All changes can be made in the config file, such as increasing the workers for each process, change the http monitor port. To monitor the processes, we can go to “http://Worker_Machine_IP:9400” with the username and password as “shuser” and “shuser”.

Gearmand Monitor

In order to be able to monitor the gearmand’s queue and its job, we need to install the following code. https://github.com/yugene/Gearman-Monitor

On the frontend, make a new folder in /var/www/html, call it “gearmandmonitor”, we will need to pull the code from that repo and deploy it on server, make a new vhost in apache’s config file, and then run composer install so it can install all necessary libraries.

Once all is done, we will need to add the gearmand’s server info into the _config.php file, and that’s all needed to be done. Ie,

$cfgServers[$i]['address'] = 'gearmand_server_ip_production:8888';
$cfgServers[$i]['name'] = 'Production';
++ $i;
$cfgServers[$i]['address'] = 'gearmand_server_ip_staging:8888';
$cfgServers[$i]['name'] = 'Staging';
++ $i;
$cfgServers[$i]['address'] = 'gearmand_server_ip_dev:8888';
$cfgServers[$i]['name'] = 'Development';
++ $i;