-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgo-mongo-installation-linux.sh
More file actions
222 lines (177 loc) · 4.64 KB
/
go-mongo-installation-linux.sh
File metadata and controls
222 lines (177 loc) · 4.64 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/bash
#!/Created By Amit Kumar
[ "$UID" -eq 0 ] || exec sudo bash "$0" "$@"
set -e
VERSION="1.10.1"
if [ -n "`$SHELL -c 'echo $ZSH_VERSION'`" ]; then
# assume Zsh
shell_profile="zshrc"
elif [ -n "`$SHELL -c 'echo $BASH_VERSION'`" ]; then
# assume Bash
shell_profile="bashrc"
fi
echo "System Info :\n";
Kernel=$(uname -s)
case "$Kernel" in
Linux) Kernel="linux" ;;
Darwin) Kernel="mac" ;;
FreeBSD) Kernel="freebsd" ;;
* ) echo "Your Operating System -> ITS NOT SUPPORTED" ;;
esac
echo "Operating System Kernel : $Kernel"
# Get the machine Architecture
Architecture=$(uname -m)
echo "Operating System Architecture : $Architecture"
if [ -d "$HOME/.go" ] || [ -d "$HOME/go" ]; then
echo "The 'go' or '.go' directories already exist. Removing previous installed GO."
rm -rf "$HOME/.go/"
rm -rf "$HOME/go/"
sed -i '/# GoLang/d' "$HOME/.${shell_profile}"
sed -i '/export GOROOT/d' "$HOME/.${shell_profile}"
sed -i '/:$GOROOT/d' "$HOME/.${shell_profile}"
sed -i '/export GOPATH/d' "$HOME/.${shell_profile}"
sed -i '/:$GOPATH/d' "$HOME/.${shell_profile}"
echo "Go removed."
fi
arch=$(uname -i)
if [[ $arch == i*86 ]]; then
DFILE="go$VERSION.linux-386.tar.gz"
echo "32"
elif [[ $arch == x86_64* ]]; then
DFILE="go$VERSION.linux-amd64.tar.gz"
echo "64"
elif [[ $arch == arm* ]]; then
DFILE="go$VERSION.linux-armv6l.tar.gz"
echo "arm"
else
DFILE="go$VERSION.darwin-amd64.tar.gz"
echo "darwin"
fi
if [ -d "$HOME/.go" ] || [ -d "$HOME/go" ]; then
echo "The 'go' or '.go' directories already exist. Exiting."
exit 1
fi
echo "Downloading $DFILE ..."
wget https://storage.googleapis.com/golang/$DFILE -O /tmp/go.tar.gz
if [ $? -ne 0 ]; then
echo "Download failed! Exiting."
exit 1
fi
echo "Extracting File..."
tar -C "$HOME" -xzf /tmp/go.tar.gz
mv "$HOME/go" "$HOME/.go"
touch "$HOME/.${shell_profile}"
{
echo '# GoLang'
echo 'export GOROOT=$HOME/.go'
echo 'export PATH=$PATH:$GOROOT/bin'
echo 'export GOPATH=$HOME/go'
echo 'export PATH=$PATH:$GOPATH/bin'
} >> "$HOME/.${shell_profile}"
mkdir -p $HOME/go/{src,pkg,bin}
#echo -e "\nGo $VERSION was installed.\nMake sure to relogin into your shell or run:"
#echo -e "\n\tsource $HOME/.${shell_profile}\n\nto update your environment variables."
#echo "Tip: Opening a new terminal window usually just works. :)"
#exec bash
source $HOME/.${shell_profile}
chmod -R 777 $HOME/go
echo ""
echo -e "Go Installed"
echo ""
echo "Installing Mongo"
rm -f /tmp/go.tar.gz
echo -----------------------------------------------------------------
echo - Mongo - Ubuntu -
echo -----------------------------------------------------------------
echo "Unistalling Previous Repo"
apt-get purge mongodb-org*
rm -r /var/log/mongodb
rm -r /var/lib/mongodb
echo "Installing repo"
echo "Installing binaries"
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
apt-get update
apt-get install -y mongodb-org
apt-get update
cat > /etc/systemd/system/mongodb.service <<'EOF'
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target
EOF
echo "File Edited"
#sudo systemctl start mongodb
#sudo systemctl status mongodb
systemctl enable mongod.service
service mongod stop
echo "Setting up default settings"
rm -rf /var/lib/mongodb/*
cat > /etc/mongod.conf <<'EOF'
storage:
dbPath: /var/lib/mongodb
directoryPerDB: true
journal:
enabled: true
engine: "wiredTiger"
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
net:
port: 27017
bindIp: 0.0.0.0
maxIncomingConnections: 100
replication:
oplogSizeMB: 128
replSetName: "rs1"
security:
authorization: disabled
EOF
service mongod start
sleep 5
mongo admin <<'EOF'
use admin
rs.initiate()
exit
EOF
sleep 5
echo "Adding admin user"
mongo admin <<'EOF'
use admin
rs.initiate()
var user = {
"user" : "admin",
"pwd" : "admin",
roles : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
]
}
db.createUser(user);
exit
EOF
echo "Adding lam user"
mongo admin <<'EOF'
use lam
rs.initiate()
var user = {
"user" : "admin",
"pwd" : "admin123",
roles : [
{
"role" : "dbOwner",
"db" : "lam"
}
]
}
db.createUser(user);
exit
EOF
echo "Complete"