Skip to content

cheat sheet :- Linux(Ubuntu) Server -> Node, Mongo, Redis, PM2, Nginx Install and Basic Configuration

node

https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-16-04

install nodejs and npm

cd ~
curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt-get install nodejs
sudo apt-get install build-essential
sudo node -v
INSTALL NPM
sudo apt-get install npm

Mongo

https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-mongodb-on-ubuntu-16-04

Install Mongo server

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
sudo apt-get update
sudo apt-get install mongodb-org
sudo systemctl start mongod
sudo systemctl status mongod
q
sudo systemctl enable mongod
mongo
use admin

db.createUser({user:"manoj",pwd:"manoj",roles:[{role:"userAdminAnyDatabase",db:"admin"}]})

 CTRL+C
sudo nano /etc/mongod.conf
. . .
security:
authorization: "enabled"
. . .
CTRL + X
Y Enter
sudo systemctl restart mongod

To verify

mongo
show dbs

It should show unauthorized

 exit

Configuring Remote Access

sudo ufw status - > if incative
sudo ufw enable
sudo ufw allow OpenSSH
sudo ufw allow 27017

redis

https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-redis-on-ubuntu-16-04

sudo apt-get update
sudo apt-get install build-essential tcl
cd /tmp
curl -O http://download.redis.io/redis-stable.tar.gz
tar xzvf redis-stable.tar.gz
cd redis-stable
make
sudo make install
sudo mkdir /etc/redis
sudo cp /tmp/redis-stable/redis.conf /etc/redis
sudo nano /etc/redis/redis.conf

change supervised no to supervised systemd

dir ./ to dir /var/lib/redis
sudo nano /etc/systemd/system/redis.service

[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always


[Install]
WantedBy=multi-user.target

sudo adduser --system --group --no-create-home redis
sudo mkdir /var/lib/redis
sudo chown redis:redis /var/lib/redis
sudo chmod 770 /var/lib/redis
sudo systemctl start redis
sudo systemctl status redis
sudo systemctl restart redis
sudo systemctl enable redis

PM2

sudo npm install -g pm2

Start Application

pm2 start server.js

NGINX

https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-16-04

sudo apt-get update
sudo apt-get install nginx
sudo ufw app list
sudo ufw allow 'Nginx HTTP'
sudo ufw status
sudo systemctl status nginx
sudo systemctl stop nginx
sudo systemctl start nginx
sudo systemctl restart nginx
sudo systemctl reload nginx
sudo systemctl disable nginx
sudo systemctl enable nginx

Setup NGINX Proxy

sudo nano /etc/nginx/sites-available/default

location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}

Leave a Reply

%d bloggers like this: