今天在公司迁移服务器需要部署mongodb的环境,然后网上百度了好多大神的博客和文档。最终搭建完成,把具体的搭建过程分享给大家,希望能对大家有帮助。 MongoDB安装步骤
First step: Create a good directory
Mkdir-p/data_master/tools/
cd/data_master/tools/
Step two: Download the installation package and unzip it
#下载
Curl-o https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz
#解压
TAR-ZXVF mongodb-linux-x86_64-3.0.6.tgz
Step three: Copy the unpacking package to the specified directory
MV mongodb-linux-x86_64-3.0.6//usr/local/mongodb
Fourth step: Add environment variables and restart environment variables
echo "Export path=/usr/local/mongodb/bin: $PATH" >>/etc/profile
Source/etc/profile
Fifth step: Create a database directory
#MongoDB的数据存储在data目录的db目录下, but this directory is not created automatically during the installation process, so you need to create the data directory manually and create the DB directory in the data directory.
#以下实例中我们将data目录创建于根目录下 (/).
#注意:/data/db is the default startup database path for MongoDB (--dbpath).
Mkdir-p/data_master/db
Mkdir-p/data_master/mongdb/log
Sixth step: Run MongoDB service on the command line
Cd/usr/local/mongodb/bin
Recommended way to run in the background.
./mongod-dbpath/data_master/db-logpath/data_master/mongdb/log/mongo.log-logappend-fork-port 27017
-dbpath specified path-logpath specified log path-fork background run-port specified port number
Seventh Step: See if you can start
Cd/usr/local/mongodb/bin
./mongo
Eighth step: End the MongoDB process and use the configuration file startup mode instead
Ps–ef|grep MONGO
Kill-9 Process Number
cd/usr/local/mongodb/bin/
Vim mongodb.conf
Idae-mongodb config start-20180203 settings data file storage directory
DBPath =/data_master/db
Set the directory where the log files are stored and their log file names
LogPath =/data_master/mongdb/log/mongo.log
Set the port number (the default port number is 27017)
Port = 27017
Set to run as Daemon, which runs in the background
Fork = True
Nohttpinterface = True
Nohttpinterface = True
#打开认证
Auth = On
Nineth Step: Open MongoDB Service
/usr/local/mongodb/bin/mongod--config/usr/local/mongodb/bin/mongodb.conf
Tenth step: Join the boot boot
echo "/usr/local/mongodb/bin/mongod--config/usr/local/mongodb/bin/mongodb.conf" >>/etc/rc.local
Set the authenticated user and password
Use admin
Switched to DB admin
Db.createuser ({User: ' DbAdmin ', pwd: ' AQVFGJK ', roles:["root"});
Successfully added User: {"user": "DbAdmin", "Roles": ["Root"]}
Use JHPICDB
Switched to DB jhpicdb
Db.createuser ({User: ' db ', pwd: ' AQVFGJK ', roles:["ReadWrite"]});
Successfully added User: {"user": "admin", "Roles": ["ReadWrite"]}
Then download the command line login to verify the user
[Email protected] log]# MONGO
MongoDB Shell version:3.0.6
Connecting To:test
Use admin
Switched to DB admin
Db.auth ("DbAdmin", "AQMKDUYBRAVFGJK");
1
Show DBS
Admin 0.078GB
DB 49.930GB
Local 0.078GB
The above is my installation of the specific steps, thank you for your support.
MongoDB build and create user authentication