-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_mongo34.sh
46 lines (38 loc) · 1.25 KB
/
install_mongo34.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
#!/bin/bash
# by feixueruge 2019.03.22
# install mongo-server by shell scripts
#install mongodb
apt install -y mongodb
sleep 10
# stop the service
echo "stop mongodb"
service mongodb stop
# mongodbpath=/disk_d/database/mongodb
mkdir -p /disk_d/database/mongodb
chown mongodb:mongodb /disk_d/database/mongodb
cp -ra /var/lib/mongodb /disk_d/database/mongodb
sleep 10
# modify the config
sed -i /dbpath/s/var/disk_d/g /etc/mongodb.conf
sed -i /dbpath/s/lib/database/g /etc/mongodb.conf
# start the mongodb
echo "start mongodb***************************************************"
service mongodb start
sleep 10
#create user and mhsb database
mongo 127.0.0.1/admin --eval "db.createRole({role:'sysadmin',roles:[], privileges:[{resource:{anyResource:true},actions:['anyAction']}]})"
mongo 127.0.0.1/mhsb --eval "db.createUser({user:'root',pwd:'123456',roles:[{role:'sysadmin',db:'admin'}]})"
# wait for over
sleep 10
# stop the service
echo "stop mongodb"
service mongodb stop
sleep 10
# modify the config
sed -i 's/^bind_ip/#&/' /etc/mongodb.conf
sed -i 's/#port = 27017/port = 8051/' /etc/mongodb.conf
sed -i 's/#auth/auth/' /etc/mongodb.conf
# start the mongodb
echo "start mongodb***************************************************"
service mongodb start
echo "finshed"