{"id":385,"date":"2019-05-10T23:58:44","date_gmt":"2019-05-10T23:58:44","guid":{"rendered":"https:\/\/unsrewiki.1sys1.com\/?p=385"},"modified":"2019-05-22T18:56:37","modified_gmt":"2019-05-22T18:56:37","slug":"building-and-scaling-a-website-part-2","status":"publish","type":"post","link":"https:\/\/server-help.org\/index.php\/2019\/05\/10\/building-and-scaling-a-website-part-2\/","title":{"rendered":"Building and Scaling a Website &#8211; Part 2"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Scaling<\/h2>\n\n\n\n<p>In Part 2 we will further scale your website to use 3 servers with a Load Balancer, Private Network, and Shared Storage.<\/p>\n\n\n\n<p>One Server will act as the MySQL Server while the other 2 will Load Balance to handle Web requests.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Shared Storage<\/h2>\n\n\n\n<p>1). In the IONOS Cloud Panel go to Infrastructure &gt; Shared Storage &gt; Create<\/p>\n\n\n\n<p>Make sure to assign it to your current Cloud Server you configured in Part 1.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"415\" src=\"https:\/\/unsrewiki.1sys1.com\/wp-content\/uploads\/2019\/05\/2-1-1024x415.png\" alt=\"\" class=\"wp-image-398\" srcset=\"https:\/\/server-help.org\/wp-content\/uploads\/2019\/05\/2-1-1024x415.png 1024w, https:\/\/server-help.org\/wp-content\/uploads\/2019\/05\/2-1-300x122.png 300w, https:\/\/server-help.org\/wp-content\/uploads\/2019\/05\/2-1-768x311.png 768w, https:\/\/server-help.org\/wp-content\/uploads\/2019\/05\/2-1.png 1041w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>2). Next click on Access in the top-right and go to <\/p>\n\n\n\n<p>    Kerberos configuration:  Download File<\/p>\n\n\n\n<p>3). Transfer or copy the files within to \/etc<\/p>\n\n\n\n<p>4). yum install -y nfs-utils<\/p>\n\n\n\n<p>5). systemctl enable nfs-secure<\/p>\n\n\n\n<p>6). systemctl start nfs-secure<\/p>\n\n\n\n<p>7). reboot<\/p>\n\n\n\n<p>8). mkdir \/shared<\/p>\n\n\n\n<p>9). vi \/etc\/fstab<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vid1557507882.nas2.lan:\/vid1557507882 \/shared nfs sec=krb5 0 0<\/code><\/pre>\n\n\n\n<p>10). hostnamectl set-hostname mywebsite.com<\/p>\n\n\n\n<p>11). mount -a<\/p>\n\n\n\n<p>12). df -h<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Filesystem                             Size  Used Avail Use% Mounted on\n\/dev\/mapper\/centos-root                 28G  2.1G   26G   8% \/\ndevtmpfs                               223M     0  223M   0% \/dev\ntmpfs                                  235M     0  235M   0% \/dev\/shm\ntmpfs                                  235M  9.5M  225M   5% \/run\ntmpfs                                  235M     0  235M   0% \/sys\/fs\/cgroup\n\/dev\/sda1                              509M  200M  309M  40% \/boot\nvid1557507882.nas2.lan:\/vid1557507882   50G  128K   50G   1% \/shared\ntmpfs                                   47M     0   47M   0% \/run\/user\/0\n<\/code><\/pre>\n\n\n\n<p>13). cp -a \/var\/www\/mywebsite.com\/ \/shared\/mywebsite.com<\/p>\n\n\n\n<p>14).  vi \/etc\/httpd\/conf.d\/mywebsite.conf <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;Directory \"\/shared\/mywebsite.com\">\nRewriteEngine On\nRewriteCond %{HTTPS} off [OR]\nRewriteCond %{HTTP_HOST} ^www\\. [NC]\nRewriteCond %{HTTP_HOST} ^(?:www\\.)?(.+)$ [NC]\nRewriteRule ^(.*)$ https:\/\/mywebsite.com\/$1 [R=301,L]\n&lt;\/Directory>\n&lt;VirtualHost *:80>\n    ServerName mywebsite.com\n    ServerAlias www.mywebsite.com\n    DocumentRoot \"\/shared\/mywebsite.com\"\n&lt;\/VirtualHost>\n&lt;VirtualHost *:443>\n    ServerName mywebsite.com\n    ServerAlias www.mywebsite.com\n    DocumentRoot \"\/shared\/mywebsite.com\"\n    SSLEngine on\n    SSLCertificateFile \"\/etc\/letsencrypt\/live\/mywebsite.com\/cert.pem\"\n    SSLCACertificateFile \"\/etc\/letsencrypt\/live\/mywebsite.com\/chain.pem\"\n    SSLCertificateKeyFile \"\/etc\/letsencrypt\/live\/mywebsite.com\/privkey.pem\"\n&lt;\/VirtualHost><\/code><\/pre>\n\n\n\n<p>15). useradd nfs<\/p>\n\n\n\n<p>16). passwd nfs<\/p>\n\n\n\n<p>17). su nfs<\/p>\n\n\n\n<p>18). kinit nfs\/uid929361.nas2.lan -kt \/etc\/krb5.keytab<\/p>\n\n\n\n<p>19). crontab -e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1 * * * * kinit nfs\/uid929361.nas2.lan -kt \/etc\/krb5.keytab<\/code><\/pre>\n\n\n\n<p>20). exit<\/p>\n\n\n\n<p>21). vi \/etc\/httpd\/conf\/httpd.conf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>User nfs\nGroup root\n&lt;Directory \"\/shared\/mywebsite.com\/\">\n    AllowOverride all\n    # Allow open access:\n    Require all granted\n&lt;\/Directory><\/code><\/pre>\n\n\n\n<p>22). chmod 755 -R \/shared\/mywebsite.com<\/p>\n\n\n\n<p>23). Check to make sure your site&#8217;s .htaccess only shows the following:<\/p>\n\n\n\n<p>cat \/shared\/mywebsite.com\/.htaccess<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># BEGIN WordPress\n&lt;IfModule mod_rewrite.c>\nRewriteEngine On\nRewriteBase \/\nRewriteRule ^index\\.php$ - [L]\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule . \/index.php [L]\n&lt;\/IfModule>\n# END WordPress<\/code><\/pre>\n\n\n\n<p>24). apachectl -k restart<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">SSL<\/h2>\n\n\n\n<p>1). mkdir \/shared\/ssl<\/p>\n\n\n\n<p>2). cd \/shared\/ssl<\/p>\n\n\n\n<p>3).  git clone https:\/\/github.com\/certbot\/certbot <\/p>\n\n\n\n<p>4). certbot<\/p>\n\n\n\n<p>5). mkdir \/shared\/keys<\/p>\n\n\n\n<p>6). .\/certbot-auto certonly &#8211;webroot -w \/shared\/mywebsite.com\/ &#8211;register-unsafely-without-email &#8211;config-dir \/shared\/keys -d mywebsite.com<\/p>\n\n\n\n<p>7). vi \/etc\/httpd\/conf.d\/mywebsite.conf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;Directory \"\/shared\/mywebsite.com\">\nRewriteEngine On\nRewriteCond %{HTTPS} off [OR]\nRewriteCond %{HTTP_HOST} ^www\\. [NC]\nRewriteCond %{HTTP_HOST} ^(?:www\\.)?(.+)$ [NC]\nRewriteRule ^(.*)$ https:\/\/mywebsite.com\/$1 [R=301,L]\n&lt;\/Directory>\n&lt;VirtualHost *:80>\n    ServerName mywebsite.com\n    ServerAlias www.mywebsite.com\n    DocumentRoot \"\/shared\/mywebsite.com\"\n&lt;\/VirtualHost>\n&lt;VirtualHost *:443>\n    ServerName mywebsite.com\n    ServerAlias www.mywebsite.com\n    DocumentRoot \"\/shared\/mywebsite.com\"\n    SSLEngine on\n    SSLCertificateFile \"\/shared\/keys\/live\/mywebsite.com\/cert.pem\"\n    SSLCACertificateFile \"\/shared\/keys\/live\/mywebsite.com\/chain.pem\"\n    SSLCertificateKeyFile \"\/shared\/keys\/live\/mywebsite.com\/privkey.pem\"\n&lt;\/VirtualHost><\/code><\/pre>\n\n\n\n<p>8). apachectl -k restart<\/p>\n\n\n\n<p>9). crontab -e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0 23 * * * \/shared\/ssl\/certbot\/certbot-auto renew --register-unsafely-without-email --post-hook \"apachectl -k restart\"<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL<\/h2>\n\n\n\n<p>1). mysqldump -uwordpress -p wp &gt; backup.sql<\/p>\n\n\n\n<p>2). Login to your new Server you have assigned to be your MySQL Server<\/p>\n\n\n\n<p>3). Transfer the backup from step 1 to it.<\/p>\n\n\n\n<p>4).  yum update <\/p>\n\n\n\n<p>5).  vi \/etc\/yum.repos.d\/MariaDB.repo <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[mariadb]\nname = MariaDB\nbaseurl = http:\/\/yum.mariadb.org\/10.2\/centos7-amd64\ngpgkey=https:\/\/yum.mariadb.org\/RPM-GPG-KEY-MariaDB\ngpgcheck=1<\/code><\/pre>\n\n\n\n<p>6).  yum install MariaDB-client MariaDB-server <\/p>\n\n\n\n<p>7).  service mariadb start <\/p>\n\n\n\n<p>8). mysql_secure_installation <\/p>\n\n\n\n<p>9). \/etc\/my.cnf.d\/server.cnf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bind-address=0.0.0.0<\/code><\/pre>\n\n\n\n<p>10).  service mariadb restart <\/p>\n\n\n\n<p>11).  mysql -uroot -p <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Create DATABASE wp;\nCREATE USER 'wordpress'@'%' IDENTIFIED BY 'Xsfd2V^dg1';\nGRANT ALL PRIVILEGES ON *.* TO wordpress@'%' IDENTIFIED BY 'Xsfd2V^dg1' WITH GRANT OPTION;<\/code><\/pre>\n\n\n\n<p>12). mysql -uwordpress -p wp &lt; backup.sql<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Private Networking<\/h2>\n\n\n\n<p>1).  In your IONOS Cloud Panel shutdown both servers<\/p>\n\n\n\n<p>2).  In your IONOS Cloud Panel go to Actions &gt; Clone to make an identical copy of your current webserver.<\/p>\n\n\n\n<p>3). In your IONOS Cloud Panel create a new private network.<\/p>\n\n\n\n<p>Assign all 3 servers to this same network.<\/p>\n\n\n\n<p>4). Assign the now Cloned Web Server to your shared storage<\/p>\n\n\n\n<p>4). Restart your servers<\/p>\n\n\n\n<p>5). Login to your first server<\/p>\n\n\n\n<p>6).  ifconfig<\/p>\n\n\n\n<p>You should now see a new interface that you didn&#8217;t have before<\/p>\n\n\n\n<p>7). vi \/etc\/sysconfig\/network-scripts\/ens224<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DEVICE=ens224\nBOOTPROTO=none\nONBOOT=yes\nIPADDR=192.168.0.1\nNETMASK=255.255.255.0\nUSERCTL=no\nVLAN=yes<\/code><\/pre>\n\n\n\n<p>8). ifup ens224<\/p>\n\n\n\n<p>9). Repeat steps 5-7 and be sure to adjust the device name and to use new IPs on line IPADDR, 192.168.0.1, 192.168.0.2, etc<\/p>\n\n\n\n<p>10). You should now be able to ping using the new private IPs between the servers<\/p>\n\n\n\n<p>11). vi \/shared\/mywebsite.com\/wp-config.php<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/** MySQL hostname *\/\ndefine( 'DB_HOST', '192.168.0.1' );<\/code><\/pre>\n\n\n\n<p>12). systemctl stop NetworkManager.service<\/p>\n\n\n\n<p>13). systemctl disable NetworkManager.service<\/p>\n\n\n\n<p>14). systemctl enable network.service<\/p>\n\n\n\n<p>15). systemctl start network.service<\/p>\n\n\n\n<p>16). vi \/etc\/rc.local<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ifup ens224<\/code><\/pre>\n\n\n\n<p>17). chmod +x \/etc\/rc.local<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Load Balancing<\/h2>\n\n\n\n<p>1). Create a new Load Balancer in your IONOS Cloud Panel<\/p>\n\n\n\n<p>Assign only your 2 Web Servers to it<\/p>\n\n\n\n<p>2). Configure it how you want but my preferred settings are: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Health Check: ICMP Test ( 5s ) \nPersistence:No\nBalancing procedure: Round Robin<\/code><\/pre>\n\n\n\n<p>If you are running a online shop you will want to have Persistence enabled to ensure a better online shop experience.<\/p>\n\n\n\n<p>3). Update your Website&#8217;s DNS A record to point to the new Load Balancer IP.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion of Part 2<\/h2>\n\n\n\n<p>You have now created a scalable cluster of 3 servers.<\/p>\n\n\n\n<p>In the future if you need more or less resources for Apache you can clone or remove one of your Web Servers . Make sure to add them to the Private Network or Load Balancer if adding more and configure the LAN interface on a new IP as well.<\/p>\n\n\n\n<p>In Part 3 we will explore creating a scalable MySQL Cluster to handle increased MySQL load as well.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Scaling In Part 2 we will further scale your website to use 3 servers with a Load Balancer, Private Network, and Shared Storage. One Server will act as the MySQL Server while the other 2 will Load Balance to handle Web requests. Shared Storage 1). In the IONOS Cloud Panel go to Infrastructure &gt; Shared&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,4,1],"tags":[],"_links":{"self":[{"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/posts\/385"}],"collection":[{"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/comments?post=385"}],"version-history":[{"count":30,"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/posts\/385\/revisions"}],"predecessor-version":[{"id":525,"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/posts\/385\/revisions\/525"}],"wp:attachment":[{"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/media?parent=385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/categories?post=385"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/tags?post=385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}