-
Notifications
You must be signed in to change notification settings - Fork 1
/
user-data-file.mongo
49 lines (39 loc) · 1.48 KB
/
user-data-file.mongo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
NODENAME='temp-mongo'
# MongoDb details
#
# MongoDB server version: 3.2.10
#
# Predefined credentials:
# user: admin
# pass: change-password-to-strong
# authDB: admin
#
# Persistent DB storage: /data
# Access port: 27017
#
echo 'UPDATE AND INSTALL UTILS'
sudo apt-get -yq update
sudo apt-get -yq install curl ca-certificates
echo 'SET HOSTNAME'
echo $NODENAME | sudo tee /etc/hostname
echo "$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4) $NODENAME" | sudo tee -a /etc/hosts
sudo hostname $NODENAME
echo 'INSTALL LINUX IMAGE EXTRA'
sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe"
sduo apt-get -yq update
sudo apt-get -yq install linux-image-extra-$(uname -r)
sudo apt-get -yq update
echo 'INSTALL DOCKER'
curl -sSL https://get.docker.com | sh
sudo usermod -aG docker ubuntu
echo 'Pull docker image and run MongoDB server'
sudo docker pull mongo:3.2.10 >/dev/null 2>&1
sudo docker run -d -p 27017:27017 --name mongo-server -v /data:/data/db mongo:3.2.10 --storageEngine wiredTiger --auth
echo 'Configure admin user with predefined password'
cat | sudo docker exec -i mongo-server mongo admin <<'EOF'
db.createUser({ user: 'admin', pwd: 'change-password-to-strong', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] });
EOF
echo 'Check authenticated connection to MongoDb'
echo 'show dbs' | sudo docker exec -i mongo-server mongo -u admin -p change-password-to-strong --authenticationDatabase admin
echo 'DONE'