1、 Make repo file
Refer to the mongodb official installation document, use the following script to make a Yum library to install mongodb4.2, but the installation process prompts "Failed to synchronize cache for repo'mongodb-org-4.2'"
[ mongodb-org-4.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
The reason is that the official installation package of centos8 has not yet been provided, because the $releasever variable is 8, so try to write the address to 7 to see if the centos7-based version can be installed.
Okay, use vim to create a repo file
sudo vim /etc/yum.repos.d/mongodb-org-4.2.repo
Enter the following configuration to the repo file, then save and exit vim
[ mongodb-org-4.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
2、 Use yum command to install
sudo yum install -y mongodb-org
The installation process used to be because the network was too slow and the download was unsuccessful. Just perform one more time. After a while, it prompts that the installation is successful and the process goes smoothly.
3、 Start mongodb
You can use it after installing and starting the service
The start, stop, and restart commands are as follows:
sudo service mongod start
sudo service mongod stop
sudo service mongod restart
4、 Open mongodb remote connection
The configuration file of mongodb is /etc/mongod.conf
If you want to open remote access, you need to modify the bindIp value of the file: 0.0.0.0, otherwise it will not be able to connect through other computers.
sudo vim /etc/mongod.conf
After the file is modified, restart to make the configuration effective
sudo service mongod restart
If you still cannot connect remotely, you can let the firewall open port 27017 (this port is the default port of mongodb, you can modify the port of mongodb through the configuration file)
firewall-cmd --permanent --zone=public--add-port=27017/tcp
firewall-cmd --reload
Refer to the official installation instructions:
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/#run-mongodb-community-edition
to sum up
The above is the method for centos8 to install mongodb 4.2 using yum introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message, and the editor will reply to you in time. Thank you very much for your support to the ZaLou.Cn website!
If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!
Recommended Posts