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

 
退出重啓服務器測試
相關文章
相關標籤/搜索