MongoDB 基礎(四)Red Hat Enterprise 6.4 x64 安裝MongDB 3.0及配置
來源:程序員人生 發(fā)布時間:2015-05-25 09:25:44 閱讀次數(shù):4159次
mongodb-org
該包為元數(shù)據(jù)包,安裝時將自動安裝以下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.
1. 創(chuàng)建yum源倉庫文件:
vi /etc/yum.repos.d/mongodb-org⑶.0.repo
[mongodb-org⑶.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⑶.0.2 mongodb-org-server⑶.0.2 mongodb-org-shell⑶.0.2 mongodb-org-mongos⑶.0.2 mongodb-org-tools⑶.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系統(tǒng)或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
Mongodb實例默許存儲數(shù)據(jù)的數(shù)據(jù)文件路徑為/var/lib/mongo,存儲日志文件路徑為/var/log/mongodb ,使用mongod賬戶運行。也能夠在文件/etc/mongod.conf 配置數(shù)據(jù)文件和日志文件的目錄。
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=<size>
# 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隨系統(tǒng)自啟動:
chkconfig mongod on
啟用Mongodb服務:
service mongod start
驗證Mongodb已成功啟動:(查看日志是不是有等待連接的信息)
tail ⑸ /var/log/mongodb/mongod.log
[initandlisten] waiting for connections on port <port>
此時也看到數(shù)據(jù)已生成:

直接在命令行輸入 mongo 可進入數(shù)據(jù)庫中:

至此,完成!~
官方參考:Install MongoDB on Red Hat Enterprise or CentOS Linux
生活不易,碼農辛苦
如果您覺得本網(wǎng)站對您的學習有所幫助,可以手機掃描二維碼進行捐贈