CentOS 7+linux+mongodb installation and configuration

1, Install centOS7 and create virtual machine

First, install VMware Workstation. I use Chinese

File - new virtual machine

Select the system image after the next step. You need to prepare it yourself

Continue to the next step and choose the installation location by yourself. The minimum requirement is 20G,

 

After the address is matched, continue to the next step

You can use the default. Continue to the next step. Use the default and click finish

 

Wait for the installation to complete

Select language, select Chinese, and click continue

Look where there's a yellow warning. Just finish it

 

Set user password

 

Then wait for the installation, which will take a long time

 

After the installation is completed, restart to enter the linux system

 

Virtual machine created successfully

First add permissions to the cxz user I just created, and then use the cxz account to operate the system

Enter the password just set by root first. The password will not be displayed. Be careful not to enter it incorrectly

Edit the / etc/sudoers file

vi /etc/sudoers #Enter the file and press i to enter

Find root ALL=(ALL) ALL,

Append cxz ALL=(ALL) ALL (indicates that cxz users can execute all commands, but a password is required)

Press ecs to enter: wq! Force save exit

There are three other kinds, please refer to (transfer) sudo configuration file / etc/sudoers detailed explanation and practical usage - liujiacai - blog Garden

Switch users

su cxz ##Switch cxz account if you want to switch root, enter su

ping the Internet first to see if there is one

If it returns connect: network is unreachable

Enter ip addr first

Find < broadcast The front is my name

Run the command CD / etc / sysconfig / network scripts, enter the directory / etc / sysconfig / network scripts / and find the ifcfg-ens33 file

 3. Modify the file with the command sudo vi ifcfg-ens33 and change the ONBOOT to yes:

sudo vi ifcfg-ens33  ##Modify ONBOOT:yes

4. Finally, execute the command sudo service network restart to ping the Internet

sudo service network restart

Second, install mongodb

Install the required plug-ins first

sudo yum install libcurl openssl xz-libs

 

Download mongodb's taz package using wget

MongoDB Community Download | MongoDB Get link

Select a directory to download the compressed package. If wget is not installed, install yum install wget

##sudo yum install wget
sudo wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon-4.4.13.tgz

##After downloading, unzip the tar -zxvf compressed package name
sudo tar -zxvf mongodb-linux-x86_64-amazon-4.4.13.tgz 

##After decompression, move the file and rename it for management
sudo mv mongodb-linux-x86_64-amazon-4.4.13   /usr/local/mongoDB  ##You can configure the path file name by yourself

##Enter mongoDB
cd /usr/local/mongoDB

##Create a new data directory to store database data 
sudo mkdir data
##Create a new log directory to store logs  
sudo mkdir log
##Create a new mongodb configuration file
sudo vi cfg/mongodb.cfg ##In / usr/local/mongoDB directory

Configure mongodb cfg

 

dbpath=/usr/local/mongoDB/data
logpath=/usr/local/mongoDB/log/mongodb.log
logappend=true
fork=true
bind_ip=0.0.0.0
port=27017

After saving

Enter mongoDB/bin

cd bin ##In / usr/local/mongoDB directory

##Configure config
sudo ./mongod --config /usr/local/mongoDB/cfg/mongodb.cfg ##In / usr/local/mongoDB/bin directory

##Start mongodb
sudo ./mongo  ##In / usr/local/mongoDB/bin directory

Start complete

1. Check the virtual machine port usage

netstat -ntlp

If prompted

netstat: command not found

Enter a command to view

yum search netstat

obtain

Install plug-ins

sudo yum install net-tools.x86_64 #Run netstat -ntlp after installation

You can see that the port is open

At this time, mongoDB compass is used to connect, and it is found that the connection cannot be made,

Check the firewall status

systemctl status firewalld.service

You need to turn off the firewall of the virtual machine

sudo systemctl stop firewalld.service

When using mongoDB compass connection, ok

Tags: Linux CentOS MongoDB

Posted by kevinkhan on Thu, 14 Apr 2022 19:29:44 +0930