linux 下安装mongodb

1. 下载mongodb

2. 解压

tar -zxvf mongodb-linux-x86_64-rhel70-4.0.3.tgz

移动:mv mongodb-linux-x86_64-rhel70-4.0.3/ /usr/local/mongodb

3.创建配置文件

cd /usr/local/mongodb

mkdir etc

vim mongodb.conf

dbpath=/home/db/mongodb/data
logpath=/home/db/mongodb/log/mongodb.log
port=27017
fork=true
journal=false
storageEngine=mmapv1

4.测试

bin/mongod -f etc/mongodb.conf

[root@izuf67rz0layh3b3vvo450z mongodb]# bin/mongod -f etc/mongodb.conf 
2018-11-12T10:47:28.278+0800 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
about to fork child process, waiting until server is ready for connections.
forked process: 9656
child process started successfully, parent exiting

5.配置环境变量

vim /etc/profile

插入下列内容:

export MONGODB_HOME=/usr/local/mongodb  
export PATH=$PATH:$MONGODB_HOME/bin

注意保存后要重启系统配置:

source /etc/profile

6.配置开机启动 

[Unit]
Description=mongodb
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/etc/mongodb.conf --auth 
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/usr/local/mongodb --shutdown --config /usr/local/mongodb/etc/mongodb.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target

系统mongodb.service的操作命令如下:

复制代码
#启动服务  
systemctl start mongodb.service  
#关闭服务  
systemctl stop mongodb.service  
#开机启动  
systemctl enable mongodb.service 
复制代码

7.创建密码

use admin  //用admin身份  
db.createUser({user:"user_test",pwd:"pwd_test",roles:["root"]})//创建账号  
db.auth("user_test","pwd_test")//就可以进入了 

8.进入

mongo

use admin

db.auth('user_test','pwd_test')

 

posted @ 2018-11-12 13:14  myvic  阅读(165)  评论(0编辑  收藏  举报