<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Servers Archives : vedmant.com : coding blog</title>
	<atom:link href="https://vedmant.com/category/servers/feed/" rel="self" type="application/rss+xml" />
	<link>https://vedmant.com/category/servers/</link>
	<description>Sharing my personal experience in web development</description>
	<lastBuildDate>Wed, 01 Aug 2018 09:33:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8</generator>
	<item>
		<title>How to setup Node.js production application on Apache multiple virtual host server</title>
		<link>https://vedmant.com/setup-node-js-production-application-apache-multiple-virtual-host-server/</link>
					<comments>https://vedmant.com/setup-node-js-production-application-apache-multiple-virtual-host-server/#comments</comments>
		
		<dc:creator><![CDATA[vedmant]]></dc:creator>
		<pubDate>Thu, 28 Sep 2017 12:47:53 +0000</pubDate>
				<category><![CDATA[Node.js]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Reverse Proxy]]></category>
		<category><![CDATA[Web Sockets]]></category>
		<guid isPermaLink="false">https://vedmant.com/?p=201</guid>

					<description><![CDATA[<p>When it comes to using Node.js on backend it&#8217;s quite different from what people used to do for PHP server configuration. Process manager First and most important is not to run your application directly with node app.js command instead use one of the following packages: forever, PM2, and some others. This will help maintain your &#8230; <a href="https://vedmant.com/setup-node-js-production-application-apache-multiple-virtual-host-server/" class="more-link">Continue reading <span class="screen-reader-text">How to setup Node.js production application on Apache multiple virtual host server</span></a></p>
<p>The post <a href="https://vedmant.com/setup-node-js-production-application-apache-multiple-virtual-host-server/">How to setup Node.js production application on Apache multiple virtual host server</a> appeared first on <a href="https://vedmant.com">vedmant.com :: coding blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>When it comes to using Node.js on backend it&#8217;s quite different from what people used to do for PHP server configuration.</p>
<h3>Process manager</h3>
<p>First and most important is not to run your application directly with <code>node app.js</code> command instead use one of the following packages: <a href="https://github.com/foreverjs/forever" rel="noopener" target="_blank">forever</a>, <a href="https://github.com/Unitech/pm2" rel="noopener" target="_blank">PM2</a>, and some others. This will help maintain your Node application process and restart it if it crashes.</p>
<p>My own pick is PM2 as it&#8217;s the most popular and has lots of features, great app monitoring, easy installations and usage.</p>
<p>Installation is quite simple, just using npm or yarn package managers. You probably will install it globally under root user so it can be accessible for all server users.</p>
<pre class="brush: plain; title: ; notranslate">
&#x5B;root@theserver ~]$ npm -g install pm2 
# Or
&#x5B;root@theserver ~]$ yarn global add pm2 
</pre>
<p>Then switch to the user, your virtual host will be using, let&#8217;s call it <code>theproject</code>, and run pm2 startup</p>
<pre class="brush: plain; title: ; notranslate">
&#x5B;theproject@theserver ~]$ pm2 startup
</pre>
<p>It will respond with a message like this:<br />
[PM2] Init System found: systemd<br />
[PM2] To setup the Startup Script, copy/paste the following command: <the command here>
<p>It will require to run command with root privileges, using sudo user or root user directly:</p>
<pre class="brush: plain; title: ; notranslate">
&#x5B;root@theserver ~]$ &lt;the command from pm2 startup here&gt;
</pre>
<p>If everything is successful it will add a PM2 service that will run on the system boot under your user <code>theproject</code>. It&#8217;s not recommended to install pm2 <code>pm2 startup</code> under the root user directly as it will run all your application scripts under root user as well.</p>
<p>Then you will need to add PM2 process configuration file, it supports json, js, yaml formats, here is the simplest example, <code>process.yaml</code> file:</p>
<pre class="brush: plain; title: ; notranslate">
apps:
  - name: theproject
    script: app.js
    exec_mode: fork
</pre>
<p>Check more info about process file <a href="http://pm2.keymetrics.io/docs/usage/application-declaration/" rel="noopener" target="_blank">here</a>.</p>
<p>To run your application, <code>cd</code> to your project folder, and run <code>pm2 start process.yml</code></p>
<pre class="brush: plain; title: ; notranslate">
&#x5B;theproject@theserver ~]$ cd theproject
&#x5B;theproject@theserver theproject]$ pm2 start process.yml
</pre>
<p>It will start your application and print current status table.</p>
<p>To make sure your app will start again after server restart, run:</p>
<pre class="brush: plain; title: ; notranslate">
&#x5B;theproject@theserver theproject]$ pm2 save
</pre>
<p>You can nicely monitor your app using command <code>pm2 monit</code>, check current list of apps <code>pm2 list</code> and view last log records <code>pm2 logs</code>. To get further insights into your app, go to <a href="https://keymetrics.io/" rel="noopener" target="_blank">https://keymetrics.io/</a> setup account and follow instructions, the functionality is really awesome and must have for any production project.</p>
<h3>Apache configuration</h3>
<p>When our app is up and running on server we actually need to access it somehow using our domain name and 80 port, yet our app is running on some port like 3000 and is available only on 127.0.0.1 (localhost) ip (if not, it might be a security issue).</p>
<p>On 80 port we already have Apache running, so we can use Apache as a reverse proxy for our application. For you you will need to make sure Apache has <code>mod_proxy</code> installed and enabled.</p>
<p>Apache Virtual host configuration will be following:</p>
<pre class="brush: plain; title: ; notranslate">
&lt;VirtualHost *:80&gt;
  ServerName theproject.com
  ServerAlias www.theproject.com
  ErrorLog /home/theproject/logs/error_log
  CustomLog /home/theproject/logs/access_log combined

  ProxyRequests Off
  ProxyPreserveHost On

  ProxyPass / http://localhost:3000/
  ProxyPassReverse / http://localhost:3000/

  # This is needed only if you want to use web sockets
  RewriteEngine On
  RewriteCond %{REQUEST_URI}  ^/socket.io            &#x5B;NC]
  RewriteCond %{QUERY_STRING} transport=websocket    &#x5B;NC]
  RewriteRule /(.*)           ws://localhost:3000/$1 &#x5B;P,L]
&lt;/VirtualHost&gt;
</pre>
<p>After restarting Apache you should be able to successfully access your app using your domain address http://theproject.com.</p>
<p>This configuration also supports socket.io in case you may use web sockets with your application, which is very common with Node apps.</p>
<p>The post <a href="https://vedmant.com/setup-node-js-production-application-apache-multiple-virtual-host-server/">How to setup Node.js production application on Apache multiple virtual host server</a> appeared first on <a href="https://vedmant.com">vedmant.com :: coding blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://vedmant.com/setup-node-js-production-application-apache-multiple-virtual-host-server/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>Simple MySql daily and weekly backups on Linux</title>
		<link>https://vedmant.com/simple-mysql-daily-weekly-backups-linux/</link>
					<comments>https://vedmant.com/simple-mysql-daily-weekly-backups-linux/#respond</comments>
		
		<dc:creator><![CDATA[vedmant]]></dc:creator>
		<pubDate>Sat, 13 May 2017 21:51:02 +0000</pubDate>
				<category><![CDATA[Servers]]></category>
		<guid isPermaLink="false">https://vedmant.com/?p=153</guid>

					<description><![CDATA[<p>Recently I had a task to create automatic Mysql database backups daily and weekly and keep some number of those backups. After some short googling I come up with a quite small and simple shell script that just works. To make this happen we need few following steps: Create a new file in /etc/cron.daily/ folder &#8230; <a href="https://vedmant.com/simple-mysql-daily-weekly-backups-linux/" class="more-link">Continue reading <span class="screen-reader-text">Simple MySql daily and weekly backups on Linux</span></a></p>
<p>The post <a href="https://vedmant.com/simple-mysql-daily-weekly-backups-linux/">Simple MySql daily and weekly backups on Linux</a> appeared first on <a href="https://vedmant.com">vedmant.com :: coding blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Recently I had a task to create automatic Mysql database backups daily and weekly and keep some number of those backups.</p>
<p>After some short googling I come up with a quite small and simple shell script that just works.</p>
<p>To make this happen we need few following steps:</p>
<ol>
<li>Create a new file in <code>/etc/cron.daily/</code> folder with execute permission, supposed we switched to root user already
<pre class="brush: bash; title: ; notranslate">
touch /etc/cron.daily/db-backup-mydb
chmod 700 /etc/cron.daily/db-backup-mydb
vim /etc/cron.daily/db-backup-mydb
</pre>
<p>I used 700 permission so only root user can read the file, cause it will store password to our database</p>
</li>
<li>
<p>Press key &#8220;i&#8221; and paste the following code:</p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/sh

# Setup some variables
backupfolder=&quot;/home/myapp/backup&quot;
user=&quot;user&quot;
prefix=&quot;db_daily_&quot;
now=&quot;$(date +'%Y%m%d-%H%M%S')&quot;
filename=&quot;$prefix$now.sql.gz&quot;
database=&quot;mydb&quot;
db_user=&quot;mydbuser&quot;
password=&quot;mypass&quot;

fullpathbackupfile=&quot;$backupfolder/$filename&quot;
logfile=&quot;$backupfolder/&quot;backup_log_&quot;$(date +'%Y_%m')&quot;.txt

# Do a backup
echo &quot;mysqldump started at $(date +'%Y-%m-%d %H:%M:%S')&quot; &gt;&gt; &quot;$logfile&quot;
mysqldump --user=$db_user --password=$password --default-character-set=utf8 --single-transaction $database | gzip &gt; &quot;$fullpathbackupfile&quot;
echo &quot;mysqldump finished at $(date +'%Y-%m-%d %H:%M:%S')&quot; &gt;&gt; &quot;$logfile&quot;

# Change file permission
chown $user:$user &quot;$fullpathbackupfile&quot;
chown $user:$user &quot;$logfile&quot;
echo &quot;file permission changed&quot; &gt;&gt; &quot;$logfile&quot;

# Delete backup files older than 8 days
find &quot;$backupfolder&quot; -name $prefix* -mtime +8 -exec rm {} \;
echo &quot;old files deleted&quot; &gt;&gt; &quot;$logfile&quot;
echo &quot;operation finished at $(date +'%Y-%m-%d %H:%M:%S')&quot; &gt;&gt; &quot;$logfile&quot;
echo &quot;*****************&quot; &gt;&gt; &quot;$logfile&quot;

exit 0
</pre>
<p>Also edit variables you need and replace database credentials at line starting with <code>mysqldump</code> after it press &#8220;Esc&#8221;.</p>
</li>
<li>
<p>Then save the file by pressing &#8220;:&#8221; (colon), then &#8220;wq&#8221; and press enter.</p>
</li>
<li>
<p>Run it to rest that it creates backups successfully:</p>
<pre class="brush: bash; title: ; notranslate">
/etc/cron.daily/db-backup-mydb
</pre>
<p>When you open your <code>/home/myapp/backups</code> folder you will see sql.gz backup file and a log file with debug information about backup process.</p>
</li>
</ol>
<p>To make weekly backups the only few things you need to change is to place the script into <code>/etc/cron.weekly/</code> folder, replace filename part &#8220;daily&#8221; to &#8220;weekly&#8221; and change &#8220;-mtime +8&#8221; to &#8220;-mtime +56&#8221; to keep last 8 weekly backups.</p>
<p>The post <a href="https://vedmant.com/simple-mysql-daily-weekly-backups-linux/">Simple MySql daily and weekly backups on Linux</a> appeared first on <a href="https://vedmant.com">vedmant.com :: coding blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://vedmant.com/simple-mysql-daily-weekly-backups-linux/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>MySql (MariaDB) crashes on small RAM VPS, what to do</title>
		<link>https://vedmant.com/mysql-mariadb-crashes-small-ram-vps/</link>
					<comments>https://vedmant.com/mysql-mariadb-crashes-small-ram-vps/#comments</comments>
		
		<dc:creator><![CDATA[vedmant]]></dc:creator>
		<pubDate>Sat, 18 Jun 2016 21:34:25 +0000</pubDate>
				<category><![CDATA[Servers]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[Server]]></category>
		<guid isPermaLink="false">https://vedmant.com/?p=113</guid>

					<description><![CDATA[<p>Recently I encountered one weird problem, my MariaDB database started to crash from time to time on one of my small RAM (512mb) virtual private servers. After some short googling I found out what what is potential problem with MariaDB on small RAM machines and how to fix it. First of all, if you have this &#8230; <a href="https://vedmant.com/mysql-mariadb-crashes-small-ram-vps/" class="more-link">Continue reading <span class="screen-reader-text">MySql (MariaDB) crashes on small RAM VPS, what to do</span></a></p>
<p>The post <a href="https://vedmant.com/mysql-mariadb-crashes-small-ram-vps/">MySql (MariaDB) crashes on small RAM VPS, what to do</a> appeared first on <a href="https://vedmant.com">vedmant.com :: coding blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Recently I encountered one weird problem, my MariaDB database started to crash from time to time on one of my small RAM (512mb) virtual private servers. After some short googling I found out what what is potential problem with MariaDB on small RAM machines and how to fix it.</p>
<p>First of all, if you have this kind of problem, check MariaDB logs </p>
<pre class="brush: bash; title: ; notranslate">
tail -n 100 /var/log/mariadb/mariadb.log
</pre>
<p>you may find something like this:</p>
<pre class="brush: plain; title: ; notranslate">
160608 12:08:05 InnoDB: Completed initialization of buffer pool
160608 12:08:05 InnoDB: Fatal error: cannot allocate memory for the buffer pool
160608 12:08:05 &#x5B;ERROR] Plugin 'InnoDB' init function returned error.
160608 12:08:05 &#x5B;ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
160608 12:08:05 &#x5B;ERROR] mysqld: Out of memory (Needed 128917504 bytes)
</pre>
<p>After some research I figured out that mysql require a lot resources for performance schema, and disabling it will help on small memory machines. <a href="https://mariadb.com/blog/starting-mysql-low-memory-virtual-machines">source</a></p>
<pre class="brush: bash; title: ; notranslate">
sudo vim /etc/my.cnf
</pre>
<p>add</p>
<pre class="brush: bash; title: ; notranslate">
performance_schema = off
</pre>
<p>to section</p>
<pre class="brush: plain; title: ; notranslate">
&#x5B;mysqld]
</pre>
<p>To ensure that database server will restart on crash, on OS with Systemd like CentOS 7 you need to do following</p>
<p>Open following file for edit</p>
<pre class="brush: bash; title: ; notranslate">
sudo vim /etc/systemd/system/mariadb.service
</pre>
<p>and add following lines</p>
<pre class="brush: plain; title: ; notranslate">
.include /lib/systemd/system/mariadb.service

&#x5B;Service]
Restart=always
RestartSec=3
</pre>
<p>Then you need to restart reload Systemd configuration</p>
<pre class="brush: bash; title: ; notranslate">
sudo systemctl daemon-reload
</pre>
<p>and restart MariaDB service</p>
<pre class="brush: bash; title: ; notranslate">
systemctl restart mariadb
</pre>
<p>To ensure that Systemd restarts service you can do following:</p>
<pre class="brush: bash; title: ; notranslate">
ps -ef|grep maria
</pre>
<p>You will see something like this</p>
<pre class="brush: bash; title: ; notranslate">
mysql    26647 26368  0 Jun12 ?        00:06:22 /usr/libexec/mysqld ....
</pre>
<p>Try to kill the process using</p>
<pre class="brush: bash; title: ; notranslate">
kill 26647
</pre>
<p>Wait 3 seconds and check if MariaDB started again</p>
<pre class="brush: bash; title: ; notranslate">
ps -ef|grep maria
</pre>
<p>The post <a href="https://vedmant.com/mysql-mariadb-crashes-small-ram-vps/">MySql (MariaDB) crashes on small RAM VPS, what to do</a> appeared first on <a href="https://vedmant.com">vedmant.com :: coding blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://vedmant.com/mysql-mariadb-crashes-small-ram-vps/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
