程序员人生 网站导航

MongoDB 基础(四)Red Hat Enterprise 6.4 x64 安装MongDB 3.0及配置

栏目:数据库应用时间:2015-05-25 09:25:44

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.


1. 创建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系统或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实例默许存储数据的数据文件路径为/var/lib/mongo,存储日志文件路径为/var/log/mongodb ,使用mongod账户运行。也能够在文件/etc/mongod.conf 配置数据文件和日志文件的目录。
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随系统自启动: chkconfig mongod on 启用Mongodb服务: service mongod start 验证Mongodb已成功启动:(查看日志是不是有等待连接的信息) tail ⑸ /var/log/mongodb/mongod.log [initandlisten] waiting for connections on port <port>

此时也看到数据已生成:



直接在命令行输入 mongo 可进入数据库中:



至此,完成!~

官方参考:Install MongoDB on Red Hat Enterprise or CentOS Linux



------分隔线----------------------------
------分隔线----------------------------

最新技术推荐