mongodb-org 該包為元數據包,安裝時將自動安裝以下4個組件包
mongodb-org-server 該包包含mongod守護進程、相關配置和初始腳本 mongodb-org-mongos 該包包含mongos守護進程 mongodb-org-shell 該包包含mongo shell mongodb-org-tools 該包包含以下mongodb工具: mongoimport bsondump, mongodump,mongoexport, mongofiles, mongooplog, mongoperf, mongorestore, mongostat, andmongotop.
vi /etc/yum.repos.d/mongodb-org-3.0.repo
[mongodb-org-3.0] name=MongoDB Repository baseurl=http://repo.mongodb.org/yum/redhat/6/mongodb-org/3.0/x86_64/ gpgcheck=0 enabled=1
2. 安裝MongoDB包和相關工具:
yum install -y mongodb-org
要是安裝指定版本的MongoDB,應獨立指定每個組件包和附加在包名後面的版本號,如:
sudo yum install -y mongodb-org-3.0.2 mongodb-org-server-3.0.2 mongodb-org-shell-3.0.2 mongodb-org-mongos-3.0.2 mongodb-org-tools-3.0.2也可以定義任何可用的MongoDB版本,當有更新的版本時yum將自動更新Mongodb包。為了防止無意的的更新,可以在/etc/yum.conf中使用exclude指令,如:
exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools
3. 相關配置:
如果開啟了防火牆,必須配置SELinux允許MongoDB運行在Red Hat系統或者CentOS Linux。 管理員應該設置以下3個選項: 1. 允許端口27017訪問(沒有則先下載工具semanage): yum -y install policycoreutils-python semanage port -a -t mongod_port_t -p tcp 27017 2. 在配置文件/etc/selinux/config設置SELinux模式為permissive: vi /etc/selinux/config SELINUX=enforcing 改為 SELINUX=permissive 3. 徹底禁用SELinux: SELINUX=disabled
vi /etc/mongod.conf
# mongod.conf #where to log logpath=/var/log/mongodb/mongod.log logappend=true # fork and run in background fork=true #port=27017 dbpath=/var/lib/mongo # location of pidfile pidfilepath=/var/run/mongodb/mongod.pid # Listen to local interface only. Comment out to listen on all interfaces. bind_ip=127.0.0.1 # Disables write-ahead journaling # nojournal=true # Enables periodic logging of CPU utilization and I/O wait #cpu=true # Turn on/off security. Off is currently the default #noauth=true #auth=true # Verbose logging output. #verbose=true # Inspect all client data for validity on receipt (useful for # developing drivers) #objcheck=true # Enable db quota management #quota=true # Set oplogging level where n is # 0=off (default) # 1=W # 2=R # 3=both # 7=W+some reads #diaglog=0 # Ignore query hints #nohints=true # Enable the HTTP interface (Defaults to port 28017). #httpinterface=true # Turns off server-side scripting. This will result in greatly limited # functionality #noscripting=true # Turns off table scans. Any query that would do a table scan fails. #notablescan=true # Disable data file preallocation. #noprealloc=true # Specify .ns file size for new databases. # nssize=# Replication Options # in replicated mongo databases, specify the replica set name here #replSet=setname # maximum size in megabytes for replication operation log #oplogSize=1024 # path to a key file storing authentication info for connections # between replica set members #keyFile=/path/to/keyfile
4. 運行mongodb
設置Mongodb隨系統自啟動: chkconfig mongod on 啟用Mongodb服務: service mongod start 驗證Mongodb已成功啟動:(查看日志是否有等待連接的信息) tail -5 /var/log/mongodb/mongod.log [initandlisten] waiting for connections on port
直接在命令行輸入 mongo 可進入數據庫中:
至此,完成!~