mongodb/install.sh

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