Download the installation package & decompress it
-
Using the wget command https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.8.tgz directly
TODO: How do I check the version number of centOS 7.0
-
Download the file to a local PC and use FileZilla to send the file to the server
-
Tar -zxvf mongodb-linux-x86_64-ubuntu1604-4.2.8.tgz
Download summary
- I install myself in the process, directly download the package, than in the server
wget
Download faster - If I decompress the mongoDB/bin directory on the server, sometimes there are many startup files missing. The solution is to try several times and upload the files separately from the local server
Move files
Generally, files will be moved to their own directory
# file2 must exist first
mv file1 file2 Move file1 to file2
mv file1/* file2 Move all files under file1 to the file2 folder
I usually keep a copy of the installation package on the server, so I use CP (it may not be installed well in the early stage, so it needs to be re-installed).
cp file1/* file2 Copy all files below file1 into file2
# here is my operationCp mongdbxxx 4.2.8 / * / usr /local/mongodb/
Copy the code
Create log files and db files to store
By default, MonoDB will not create its own directory for storing data and log directory, you need to manually specify their own
You can manually create the folder yourself and then specify it by launching it from the configuration file
mkdir /usr/local/mongodb/data Create data store path
mkdir /usr/local/mongodb/log Create a path for storing logs
Copy the code
Create a startup profile
- Create a file
mkdir /usr/mongo/mongo.conf
- Write files
vim /usr/mongo/mongo.conf
dbpath=/usr/local/mongodb/data # specify a directory for storing data logpath=/usr/local/mongodb/logs/mongo.log # specify a directory for storing logs logappend=true #? journal=true #? quiet=true #? port=27017 # port fork=true Run in the background, that is, the thread is always runningBind_ip = 0.0.0.0Allow any IP to connect, i.e. access to surgery Copy the code
Start the server
-
Start the command/usr/local/mongo/mongo – Linux – x86_64 – rhel70-4.2.8 / bin/mongod — config/usr/local/mongo/mongo. Conf
-
After the server is started, access the IP address :27017 (the IP address is the public IP address of the server). The following information is displayed
Start the client and create a banker
-
Start the
/usr/local/mongodb/bin/mongo Copy the code
-
Go to shell and create an account
use admin db.createUser( { user:"root".pwd:"root", roles:[{role:"root",db:"admin"}]})# check your accountShow users or the system. Users. The find ()How do I exit the shell exitenter# enable permission auth=trueStartup file plus, you need to log in to boot againCopy the code
-
Close the mongo
Exit using db.shutdownServer()
Note: If auth=true is set in the configuration file, then the permission must be verified before closing
use admin db.auth('root'.'root') db.shutdownServer() Copy the code
Do note: Using kill to kill directly can cause major problems
After changing the conf file, start again as shown in the figure
Start the server /usr/local/ mongo/mongo - Linux - x86_64 - rhel70-4.2.8 / bin/mongod -- config/usr /local/mongodb/mongo.conf Start the client /usr/local/ mongo/mongo - Linux - x86_64 - rhel70-4.2.8 / bin/mongoCopy the code
There is a problem with TODO. It should require permissions
If you kill a process accidentally, an error may occur. The client cannot connect to the server and the server cannot start
Operating as follows
0, ps - ef | grep mongodCheck the mongoDb process ID1, sudokill-9 4018 Kill the subprocess. 2. Go to the mongodb installation directory and delete the mongod. Lock file in the data directorylocal/mongodb/bin/mongod --config /usr/local/mongodb/etc/mongodb.conf
Pay special attention to any errors in the middle, remember to read the prompt several timesThere was no /data/db folder, but I didn't know what to use it for, so I manually created a new /data/db folderCopy the code
Record some basic Linux commands
# ali cloud
Check whether the server is connected to the outside worldTelnet 192.168.157.129 80# note:Sometimes you can't Telnet out, or CTRL + C out; In this case, run CTRL +] and enter quit on the Telnet command line to exitCheck whether the server is accessible from outside.
# A static web page was deployed before, and could not be accessed, so the following troubleshooting methods were recorded
systemctl status firewalld
# running open
# firewalld closed
# Enable a port externally
firewall-cmd --permanent --zone=public --add-port=3306/tcp
# success
# FirewallD is not running
# nginx error checking
Check ng syntax
nginx -t
# View process && Force kill process
# Check the nginx process
ps -ef|grep nginx
# kill process
kill -QUIT 2072
# Simple and brutal killing
pkill -9 nginx
# Check the process for a specific portLsof - I: 80 can also process whether there is a process to port 80 at run netstat tunlp | grep: 80Copy the code
Refer to the link
Rookie tutorial 1 2 3