1] To get started we first need add a yum repository
# vi /etc/yum.repos.d/mongodb-org-4.0.repo
add the following and save the file
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
2] Now proceed to install MongoDB
# yum install mongodb-org
3] Lets configure MongoDB for security and take care of MongoDB warning.
# vi /etc/mongod.conf
and to enable security search for
#security:
and change it to
security:
authorization: enabled
and save the file
4] We need to disable hugepage which affects the performance on MongoDB and also take care of MongoDB warnings. It is enabled by default in Centos7 and there are various ways to disable it and below is one of them
# vi /etc/rc.local
and append following lines at the end of the file and save the 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
for it to work we need to make rc.local executable and reboot the server
# chmod +x /etc/rc.d/rc.local
# reboot
5] Login again to start and enable auto start for MongoDB
# systemctl start mongod && systemctl enable mongod
# systemctl status mongod
6] Now lets go ahead and connect to MongoDB and create admin user and database to store credential details. Please ensure secure password is used for admin.
$ mongo
> use admin
> db.createUser({user: "admin", pwd: "Password", roles:[{role: "userAdminAnyDatabase", db: "admin"}]})
> quit()
and login with admin credentials
$ mongo -u adminm -p --authenticationDatabase admin
Now proceed to use MongoDB to create databases, collections etc.
# vi /etc/yum.repos.d/mongodb-org-4.0.repo
add the following and save the file
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
2] Now proceed to install MongoDB
# yum install mongodb-org
3] Lets configure MongoDB for security and take care of MongoDB warning.
# vi /etc/mongod.conf
and to enable security search for
#security:
and change it to
security:
authorization: enabled
and save the file
4] We need to disable hugepage which affects the performance on MongoDB and also take care of MongoDB warnings. It is enabled by default in Centos7 and there are various ways to disable it and below is one of them
# vi /etc/rc.local
and append following lines at the end of the file and save the 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
for it to work we need to make rc.local executable and reboot the server
# chmod +x /etc/rc.d/rc.local
# reboot
5] Login again to start and enable auto start for MongoDB
# systemctl start mongod && systemctl enable mongod
# systemctl status mongod
6] Now lets go ahead and connect to MongoDB and create admin user and database to store credential details. Please ensure secure password is used for admin.
$ mongo
> use admin
> db.createUser({user: "admin", pwd: "Password", roles:[{role: "userAdminAnyDatabase", db: "admin"}]})
> quit()
and login with admin credentials
$ mongo -u adminm -p --authenticationDatabase admin
Now proceed to use MongoDB to create databases, collections etc.
No comments:
Post a Comment