Tuesday, February 19, 2019

Node.js Centos 7 production configuration


Install nodejs

Download
wget --no-check-certificate https://nodejs.org/dist/v10.15.1/node-v10.15.1-linux-x64.tar.xz
Move the downloaded file /usr/local
Then unpack
tar xf node-v10.15.1-linux-x64.tar.xz
Add node executables to the path by adding symlinks to /usr/bin
ln -s /usr/local/node/bin/node /usr/bin/node
ln -s /usr/local/node/bin/npm /usr/bin/npm
ln -s /usr/local/node/bin/npx /usr/bin/npx

Install pm2

To run node as service we need to install a nodejs package
npm install pm2@latest –g
We need to run set the path to pm2
ln -s /usr/local/node/bin/pm2 /usr/bin/pm2
ln -s /usr/local/node/bin/pm2 /usr/bin/pm2-runtime

For security reasons we should run our app NOT as root. We create a new user nodejs to run our app
useradd nodejs
chown -R nodejs:nodejs /usr/local/node
chown –R nodejs:nodejs /usr/local/node-v10.15.1-linux-x64
# as root
pm2 startup system –u nodejs –-hp /home/nodjs

To start the application as the nodejs user, switch to the user nodejs
su nodejs
pm2 start /usr/local/node/apps/chat/server.js
pm2 list
# to automatically start the app on reboots
pm2 save

You should see that the app is running as user nodejs 



Likewise to stop
#other commands
pm2 stop /usr/local/node/apps/chat/server.js
pm2 delete /usr/local/node/apps/chat/server.js

Monday, February 11, 2019

Install ArangoDB on Centos 7


The instructions on the official arangodb website do not work, so I’m documenting the steps I took so that it may help others.

The first problem is adding arangodb as a repo due to invalid SSL certificates. To get around the issue:


The added ‘k’ parameter connects to the repo insecurely skipping the step of verifying the certificates.

Before we can run the yum command to install arangodb, we need to configure the arangodb.repo to skip SSL checks by adding the following to the file /etc/yum.repos.d/arangodb.repo
sslverify=0

Then run the command to install:
yum install arangodb3

References: