Centos7.5 installation and configuration MongoDB4.0.4
2018- 11- 22 10:25:39
CollectionI want to contribute
MongoDB is a database based on distributed file storage. Written in C++ language. Designed to provide scalable high-performance data storage solutions for WEB applications. MongoDB is a product between relational and non-relational databases. It is the most versatile and most like relational database among non-relational databases.
1、 Download and unzip mongodb
cd /data/
curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.4.tgz
tar zxvf mongodb-linux-x86_64-4.0.4.tgz
2、 Create mongodb related directories
mv mongodb-linux-x86_64-4.0.4 mongodb
mkdir -p mongodb/{data/db,log}
mkdir -p /etc/mongodb
3、 Create mongodb configuration file
vim /etc/mongodb/mgdb.conf
dbpath=/data/mongodb/data/db #Data file storage directory
logpath=/data/mongodb/log/mongodb.log #Log file storage directory
port=37485 #Port, default 27017, can be customized
logappend=true #Open log and add log
fork=true #Enable as a daemon, that is, run in the background
bind_ip=0.0.0.0 #Local listening IP, 0.0.0.0 means all local IP
auth=true #Do you need authentication permission to log in (user name and password)
4、 Add environment variables
vim /etc/profile
export MONGODB_HOME=/data/mongodb
export PATH=
Make environment variables take effect immediately
source /etc/profile
5、 Create mongodb startup configuration file
vim /usr/lib/systemd/system/mongodb.service
[ Unit]
Description=mongodb
After=network.target remote-fs.target nss-lookup.target
[ Service]
Type=forking
RuntimeDirectory=mongodb
PIDFile=/data/mongodb/data/db/mongod.lock
ExecStart=/data/mongodb/bin/mongod --config /etc/mongodb/mgdb.conf
ExecStop=/data/mongodb/bin/mongod --shutdown --config /etc/mongodb/mgdb.conf
PrivateTmp=true
[ Install]
WantedBy=multi-user.target
6、 Start mongodb and add it to boot
systemctl daemon-reload
systemctl start mongodb
systemctl enable mongodb
7、 Configure firewalld firewall policy
firewall-cmd --permanent --add-port=37485/tcp
firewall-cmd --reload
8、 test
(1) Create an administrative user
mongo --port 37485
use admin
db.createUser({user:"admin",pwd:"xuad830818",roles:[{role:"userAdminAnyDatabase",db: "admin"}]})
db.auth('admin','xuad830818')
(2) Create a test user
use test
db.createUser({user:"xuad",pwd:"123456",roles:[{role:"readWrite",db:"securitydata"}]})
db.auth('xuad','123456')
exit
Centos 7.5 install and configure MongoDB 4.0.4
(3) Login with test user
mongo --port 37485 -u xuad -p 123456
Centos 7.5 install and configure MongoDB 4.0.4
Recommended Posts