-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstall_mongo.sh
executable file
·141 lines (96 loc) · 4.58 KB
/
install_mongo.sh
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
SCRIPT_NAME=$(basename $BASH_SOURCE)
SCRIPT_LOGFILE="./logs/"$(basename -s .sh $BASH_SOURCE)".log"
mkdir -p ./logs && chmod 755 ./logs
echo "running "$SCRIPT_NAME
DISTRIBUTOR=$(lsb_release -i | awk -F"\t" '{print $2}')
if [ "$DISTRIBUTOR" = "Ubuntu" ]; then
. /etc/lsb-release
echo $DISTRIB_DESCRIPTION
if [ "$DISTRIB_RELEASE" = "14.04" ]; then
#
# tested: works on ubuntu 14.04.3 gnome
#
if hash mongo 2>/dev/null; then
echo " mongo package already installed"
else
echo " mongo package not installed"
# https://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
sudo apt-get -y update
sudo apt-get -y install mongodb-org
sudo service mongod restart
###########################################################################
# Warning solution "WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'"
#
# To remove warning, add this after "chown $DAEMONUSER /var/run/mongodb.pid" line in "/etc/init/mongod.conf" file:
#if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
# echo never > /sys/kernel/mm/transparent_hugepage/enabled
#fi
#
#if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
# echo never > /sys/kernel/mm/transparent_hugepage/defrag
#fi
###########################################################################
# Links:
#
# http://askubuntu.com/questions/597372/how-do-i-modify-sys-kernel-mm-transparent-hugepage-enabled
# http://stackoverflow.com/questions/28911634/how-to-avoid-transparent-hugepage-defrag-warning-from-mongodb
# http://docs.mongodb.org/manual/tutorial/transparent-huge-pages/
fi
elif [ "$DISTRIB_RELEASE" = "16.04" ]; then
if hash mongo 2>/dev/null; then
echo " mongo package already installed"
else
echo " mongo package not installed"
# https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-16-04
# install package
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt-get update
sudo apt-get install -y mongodb-org
# create service file
sudo touch /etc/systemd/system/mongodb.service
echo '[Unit]' | sudo tee -a /etc/systemd/system/mongodb.service
echo 'Description=High-performance, schema-free document-oriented database' | sudo tee -a /etc/systemd/system/mongodb.service
echo 'After=network.target' | sudo tee -a /etc/systemd/system/mongodb.service
echo '' | sudo tee -a /etc/systemd/system/mongodb.service
echo '[Service]' | sudo tee -a /etc/systemd/system/mongodb.service
echo 'User=mongodb' | sudo tee -a /etc/systemd/system/mongodb.service
echo 'ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf' | sudo tee -a /etc/systemd/system/mongodb.service
echo '' | sudo tee -a /etc/systemd/system/mongodb.service
echo '[Install]' | sudo tee -a /etc/systemd/system/mongodb.service
echo 'WantedBy=multi-user.target' | sudo tee -a /etc/systemd/system/mongodb.service
# start the service
sudo systemctl start mongodb
# start whe computer starts
sudo systemctl enable mongodb
###########################################################################
# Warning solution "WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'"
#
# To remove warning, add this after "chown $DAEMONUSER /var/run/mongodb.pid" line in "/etc/init/mongod.conf" file:
#if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
# echo never | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
#fi
#
#if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
# echo never | sudo tee /sys/kernel/mm/transparent_hugepage/defrag
#fi
###########################################################################
# Links:
#
# http://askubuntu.com/questions/597372/how-do-i-modify-sys-kernel-mm-transparent-hugepage-enabled
# http://stackoverflow.com/questions/28911634/how-to-avoid-transparent-hugepage-defrag-warning-from-mongodb
# http://docs.mongodb.org/manual/tutorial/transparent-huge-pages/
fi
else
echo ""
echo "Sorry, your ubuntu version is not supported. You are running $DISTRIB_RELEASE"
echo ""
fi
else
echo ""
echo "Sorry, this script only works with Ubuntu. You are running $DISTRIBUTOR"
echo ""
fi