debian安装mongoDB

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.10.tgzlinux

tar zxf mongodb-linux-x86_64-4.0.10.tgz
 
mv mongodb-linux-x86_64-4.0.10 /usr/local/mongodb
 
mkdir /data/mongodb
 
touch /var/log/mongodb/mongod.log
 
 
vim /etc/mongod.conf
 1 插入内容  2 systemLog:  3  destination: file  4    path: "/var/log/mongodb/mongod.log"
 5    logAppend: true
 6 storage:  7    dbPath: "/data/mongodb"
 8  journal:  9       enabled: true
10 processManagement: 11    fork: true
12 net: 13    bindIpAll: true
14    port: 27017
15 setParameter: 16    enableLocalhostAuthBypass: false
17 #下面为设置集群名 能够不用添加 18 replication: 19    replSetName: rs0 #设置集群名

 

 
添加rc.local文件
cat <<EOF >/etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
 
exit 0
EOF
 
赋予权限
chmod +x /etc/rc.local
 
启动rc.local服务
systemctl start rc-local
 
启动mongodb服务
/usr/local/mongodb/bin/mongod --config=/etc/mongod.conf
 
若是出现
mongod: error while loading shared libraries: libcurl.so.4: cannot open shared object file: No such file or directory
 
须要安装curl
apt-get install curl
 
 
切换到admin目录
use admin
 
添加管理用户root(全部)
db.createUser({user: "root",pwd: "*******",roles: [ { role: "root", db: "admin" } ]});
 
添加数据获取用户zz_api(读写)
db.createUser({user: "zz_api",pwd: "*******",roles: [ { role: "readWrite", db: "zz_web" } ]});
 
添加爬虫用户zz_spider(读写)
db.createUser({user: "zz_spider",pwd: "*******",roles: [ { role: "readWrite", db: "zz_web" } ]});
 
建立zz_web数据库
use zz_web
 
退出
exit
 
添加开机自启
 
vim /etc/rc.local
 
在exit 0以前添加
/usr/local/mongodb/bin/mongod --auth --config=/etc/mongodb.conf >/dev/null 2>&1
 
环境变量添加
vim /etc/profile
添加一行
export PATH=$PATH:/usr/local/mongodb/bin
使环境变量生效

source /etc/profileweb

 
退出重启服务器测试
相关文章
相关标签/搜索