“This is the 13th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021”
preface
The mongodb website provides instructions for installing and configuring Linux operating systems
Docs.mongodb.com/master/admi…
This section uses CentOS (RedHat) as an example
Docs.mongodb.com/master/tuto…
Combine with the official statement and add to it.
Configuration yum
You first need to configure Mongo’s YUM so that you can install with yum
Create /etc/ym.repos. D /mongodb-org-3.2.repo and add the contents
[mongo - org - 3.2] name = directing a Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/ gpgcheck = 1 enabled = 1 gpgkey=https://www.mongodb.org/static/pgp/server-3.2.ascCopy the code
Install the mongo
With yum configured, you can follow mongo through yum
sudo yum install -y mongodb-org
Copy the code
Could not resolve host: repo.mongodb.org; Unknown Error Is caused by unstable access to foreign websites. Try again.
Configuring the Firewall
You also need to disable SELinux and configure a firewall, otherwise you cannot access it
If semanage is not available, install it first
yum -y install policycoreutils-python
Copy the code
Then configure a firewall to open port 27017
semanage port -a -t mongod_port_t -p tcp 27017
Copy the code
Finally, close SELinux and modify the /etc/selinux/config file
SELINUX=disabled
Copy the code
Start the Mongo
After the installation is complete, the mongo configuration file /etc/mongod. Conf is automatically generated, in which you can view the database address and log address. The default database path path/var/lib/mongo, days the default path/var/log/mongo/mongod log
We can also reconfigure mongod. Conf as follows:
#processManagement: # fork: true net: bindIp: 127.0.0.1 Port: 27017 Storage: dbPath: / MNT /mongo systemLog: destination: file path: "/mnt/mongodb/mongodb.log" logAppend: true storage: journal: enabled: trueCopy the code
Change path in dbPath and systemLog.
Then start the Mongo service
sudo service mongod start
It can also be started directly with the mongo command as follows:
/usr/bin/mongod -dbpath=/mnt/mongo -logpath=/mnt/mongodb/mongodb.log -logappend -port=27017 -fork --maxConns=20000 - bind_ip = 127.0.0.1 wiredTigerCacheSizeGB = 0.2Copy the code
Note: this command is followed by –bind_ip=127.0.0.1, so that the external network can be accessed without default, so that if the account password authentication is not enabled, it is vulnerable to attack. However, if you want to access the Internet, you can not add, so it is best to enable account password authentication to prevent attacks.
Connecting to a Database
Run mongo in the terminal. If you enter the database, the installation is successful.