Centos7 uses Yum source to install mongodb version 4.2 database
1. Modify the support of yum installation source for mongodbOfficial documents available:
This month is also built with reference to official documents
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/#configure-the-package-management-system-yum
Formal operation
(1) Modify the repo source file for installing mongoDB, yumvi /etc/yum.repos.d/mongodb-org-4.2.repo
Add the following information to the file
[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(2) Install and start mongo
yum install mongodb-org -y
This operation will take a certain time, when the execution is completed
Use the following command to enter the client
mongo
exmple: the command to operate mongo is as follows (on, off, start, view status)
Start: systemctl start mongod Restart: systemctl restart mongod Close: systemctl stop mongod View running status: systemctl status mongodStart Mongo by executing systemctl start mongod command
(3) Check whether mongo is onsystemctl status mongod #The following message indicates mongo is on ● mongod.service - MongoDB Database Server Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2020-01-17 19:37:33 CST; 5s ago Docs: https://docs.mongodb.org/manual Process: 18740 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS) Process: 18738 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS) Process: 18734 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS) Process: 18733 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS) Main PID: 18743 (mongod) CGroup: /system.slice/mongod.service └─18743 /usr/bin/mongod -f /etc/mongod.conf
View mongo logs
more /var/log/mongodb/mongod.log(4) Possible problems in startup
If the error code code=14 appears after startup or in the log, it means that Mongo has been installed on the server before, but the data has not been completely cleared
Solution command: (clear the previous file and start from)
cd /tmp rm -rf mongodb-27017.sock systemctl restart mongod(5) Enable remote access to mongo Library
First, close the mongo Library (the configuration file was not modified at the time of previous startup)
systemctl stop mongod
Enter mongo configuration file
cd /etc/ ll vim mongo.conf
If there is no vim command, you can install it with the following command
sudo yum install -y vim
Modify the file to the following location (change 127.0.0.1 to 0.0.0.0)
# network interfaces net: port: 27017 bindIp: 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
Exit after saving
(6) Firewall settingsIt is better to use firewall for cenos7
If not, install with the following command
yum install firewalld firewalld-config
Check whether the firewall is on
firewall-cmd --state
If it is not turned on and it is determined that it is not necessary to turn on, skip the following
View the list of open firewall ports
firewall-cmd --permanent --list-port
If there is no 27017 port, open it
firewall-cmd --zone=public --add-port=27017/tcp --permanent firewall-cmd --zone=public --add-port=27017/udp --permanent
service iptables restart
firewall-cmd --reload
If it is a ECs, you need to add the 27017 port configuration to the security group configuration
(7) Restart mongo and connectsystemctl start mongod
Check whether it is on
systemctl status mongod netstat -untlp
Using navicat12 or studio3T connection test
So far, the Mongodb database without password has been set up
Are you fat tiger? 26 original articles published, 22 praised, 3028 visited Private letter follow