MERN

by lblaboon
3 deployments · 0 still active · last rev. 8 days ago

Basic MERN configuration

Compatible with: Debian 9
						#!/bin/bash

# <UDF name="dbpass" Label="MongoDB admin password" example="s3cure_p4ssw0rd" />

# Set hostname
HOSTNAME=$(hostname)
FQDN=$(hostname -f)
IPV4=$(hostname -I | cut -d ' ' -f 1)
IPV6=$(hostname -I | cut -d ' ' -f 2)
hostnamectl set-hostname $HOSTNAME
echo "${IPV4} ${FQDN} ${HOSTNAME}" >> /etc/hosts
echo "${IPV6} ${FQDN} ${HOSTNAME}" >> /etc/hosts

# Update system
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get upgrade -y

# Install/configure UFW
apt-get install -y ufw
ufw default allow outgoing
ufw default deny incoming
ufw allow ssh
systemctl start ufw
systemctl enable ufw

# Install MongoDB
apt-get install -y dirmngr
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
echo 'deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/4.0 main' > /etc/apt/sources.list.d/mongodb-org-4.0.list
apt-get update
apt-get install -y mongodb-org

# Configure MongoDB
sed -i 's/^#security:$/security:\n\ \ authorization:\ enabled/' /etc/mongod.conf
systemctl start mongod
systemctl enable mongod
mongo <<EOF
use admin
db.createUser({user: "admin", pwd: "${DBPASS}", roles:[{role: "userAdminAnyDatabase", db: "admin"}]})
EOF

# Install NodeJS
curl -sL https://deb.nodesource.com/setup_11.x | bash -
apt-get install -y nodejs

# Install ExpressJS
npm install --global express
npm link express

# Cleanup
rm /root/StackScript
echo "Installation complete!"