小丸子學MongoDB系列之——安裝MongoDB

wxjzqym發表於2015-12-02

1.下載MongoDB3.0軟體包並解壓
[root@vm1 ~]# cd /appbase/apps
[root@vm1 ~]# rz
[root@vm1 ~]# tar xzvf mongodb-linux-x86_64-rhel62-3.0.3.tgz
[root@vm1 ~]# ln -s mongodb-linux-x86_64-rhel62-3.0.3 mongodb-3.0.3

2.建立個人使用者
[root@vm1 ~]# mkdir /appbase/users
[root@vm1 ~]# groupadd -g 511 dbg
[root@vm1 ~]# useradd -u 511 -g dbg -d /appbase/users/mgousr01 mgousr01
[root@vm1 ~]# echo oracle|passwd --stdin mgousr01


3.配置MongoDB
[root@vm1 ~]# su - mgousr01
[mgousr01@vm1 ~]$ vi .bash_profile
export MONGODB_HOME=/appbase/apps/mongodb-3.0.3
export PATH=$MONGODB_HOME/bin:$PATH
[mgousr01@vm1 ~]$ source .bash_profile

[mgousr01@vm1 ~]$ mkdir -p mongodb/{bin,conf,data,logs,pid}

[mgousr01@vm1 ~]$ vi /appbase/users/mgousr01/mongodb/conf/single.conf
dbpath=/appbase/users/mgousr01/mongodb/data/ 
logpath=/appbase/users/mgousr01/mongodb/logs/single.log
pidfilepath=/appbase/users/mgousr01/mongodb/pid/single.pid
directoryperdb=true
logappend=true
bind_ip=192.168.157.128    
port=37017
oplogSize=10240
fork=true


4.啟動MongoDB
[mgousr01@vm1 ~]$ vi /appbase/users/mgousr01/mongodb/bin/start_mongodb.sh
mongod -f /appbase/users/mgousr01/mongodb/conf/signle.conf

[mgousr01@vm1 ~]$ chmod +x /appbase/users/mgousr01/mongodb/bin/start_mongodb.sh

[mgousr01@vm1 ~]$ /appbase/users/mgousr01/mongodb/bin/start_mongodb.sh
mongod: /usr/lib64/libssl.so.10: no version information available (required by mongod)
mongod: /usr/lib64/libcrypto.so.10: no version information available (required by mongod)
mongod: /usr/lib64/libcrypto.so.10: no version information available (required by mongod)
Error reading config file: No such file or directory
注:這裡報錯的原因是當前的openssl版本太舊
解決方法如下:
[root@vm1 ~]# rpm -e openssl --nodeps
[root@vm1 ~]# rpm -ivh openssl-1.0.1e-42.el6.x86_64.rpm


--登入MongoDB
[mgousr01@vm1 ~]$  mongo 192.168.157.128:37017
MongoDB shell version: 3.0.3
connecting to: 192.168.157.128:37017/test
Server has startup warnings:
2015-12-02T17:27:33.632+0800 I CONTROL  [initandlisten]
2015-12-02T17:27:33.632+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2015-12-02T17:27:33.632+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2015-12-02T17:27:33.633+0800 I CONTROL  [initandlisten]
2015-12-02T17:27:33.633+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2015-12-02T17:27:33.633+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2015-12-02T17:27:33.633+0800 I CONTROL  [initandlisten]
> exit
bye
注:連線過程中出現兩個警告,根據提示修改引數即可,注意修改後需重啟mongodb例項警告才會消失
解決方法如下:
[root@vm1 ~]# echo never >/sys/kernel/mm/transparent_hugepage/enabled
[root@vm1 ~]# echo never> /sys/kernel/mm/transparent_hugepage/defrag


[mgousr01@vm1 bin]$   mongo 192.168.157.128:37017
MongoDB shell version: 3.0.3
connecting to: 192.168.157.128:37017/test
> show dbs;
local  0.078GB
至此,Mongodb安裝成功

注:MongoDB還是非常佔用磁碟空間的,當然這也和MongoDB的啟動引數有關
[mgousr01@vm1 ~]$ du -sh mongodb/data/*
3.1G    mongodb/data/journal
81M     mongodb/data/local
4.0K    mongodb/data/mongod.lock
4.0K    mongodb/data/storage.bson

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/20801486/viewspace-1851786/,如需轉載,請註明出處,否則將追究法律責任。

相關文章