mongodb/install.sh

raw link view readme
1 sed "s/\"80\"/\"27017\"/;s/WWW (HTTP)/Mongo/;/.*/d" /usr/lib/firewalld/services/http.xml > /etc/firewalld/services/mongo.xml
2 systemctl start firewalld
3 systemctl enable firewalld
4 firewall-cmd --permanent --zone=public --add-interface=eth0
5 firewall-cmd --permanent --add-service=mongo --zone=public
6 firewall-cmd --reload
7
8 rpm --import https://www.mongodb.org/static/pgp/server-3.4.asc
9
10 cat > /etc/yum.repos.d/mongodb-org-3.4.repo <<\EOF
11 [mongodb-org-3.4]
12 name=MongoDB Repository
13 baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
14 gpgcheck=1
15 enabled=1
16 gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
17 EOF
18
19 yum install mongodb-org -y
20
21 echo never > /sys/kernel/mm/transparent_hugepage/enabled
22 echo never > /sys/kernel/mm/transparent_hugepage/defrag
23
24 fdisk /dev/sdc <
25 n
26 p
27 1
28
29
30 w
31 EOF
32
33 mkfs.xfs /dev/sdc1
34
35 echo "$(xfs_admin -u /dev/sdc1 | sed "s/ //g") /var/lib/mongo xfs defaults,noatime 0 0" >> /etc/fstab
36
37 mount /var/lib/mongo
38
39 chown mongod:mongod /var/lib/mongo
40 chmod g+s /var/lib/mongo
41
42 restorecon -vR /var/lib/mongo
43
44 sed -i.original "/bindIp/d" /etc/mongod.conf
45 sed -i -E "s/port: ([0-9]+)/port: \1\n http:\n enabled: false\n RESTInterfaceEnabled: false/g" /etc/mongod.conf
46
47 systemctl start mongod
48 systemctl enable mongod
49
50 mongo admin <<\EOF
51 db.createUser({
52 user: "dbetz",
53 pwd: "test1",
54 roles: [
55 {
56 role: "userAdminAnyDatabase",
57 db: "admin"
58 }
59 ]
60 })
61 EOF
62
63 mongo --username dbetz --password test1 admin <<\EOF
64 db.grantRolesToUser("dbetz", ["restore"])
65 EOF
66
67 sed -i -E "s/#security:/security:\n authorization: enabled/g" /etc/mongod.conf
68 systemctl restart mongod
69
70 wget https://jampadcdn01.azureedge.net/armtemplates/mongodb/mongolibrary.tar.gz -O /var/tmp/mongo-library.tar.gz
71 cd /var/tmp
72 mkdir /var/tmp/mongo-library
73 tar -zxf mongo-library.tar.gz -C mongo-library
74 mongorestore --username dbetz --password test1 --authenticationDatabase admin --db library --dir /var/tmp/mongo-library
75
76 mongo --username dbetz --password test1 admin <<\EOF
77 db.createUser({
78 user: "user01",
79 pwd: "taco1",
80 roles: [{
81 role: "readWrite",
82 db: "library"
83 }]
84 })
85 EOF
86
87 mongo --username dbetz --password test1 admin <<\EOF
88 db.createUser({
89 user: "user02",
90 pwd: "taco2",
91 roles: [{
92 role: "read",
93 db: "library"
94 }]
95 })
96 EOF
97
98 mongo --username dbetz --password test1 admin <<\EOF
99 db.createUser({
100 user: "hamletuser",
101 pwd: "taco3",
102 roles: [{
103 role: "readWrite",
104 db: "librarygen"
105 }]
106 })
107 EOF
108
109 wget https://linux.azure.david.betz.space/raw/mongodb/generate/setup_data_generation.sh -O /root/setup_data_generation.sh
110 sed -i 's/\r//' /root/setup_data_generation.sh
111 chmod +x /root/setup_data_generation.sh
112