mongodb 安装配置实践
发表于:2024-11-26 作者:千家信息网编辑
千家信息网最后更新 2024年11月26日,首先从官网下载mongodb的安装包http://www.mongodb.org/downloads我的系统是redhat5.8所有选择相应的版本包就ok现在最新版是3.0.3解压mongodb-li
千家信息网最后更新 2024年11月26日mongodb 安装配置实践
首先从官网下载mongodb的安装包http://www.mongodb.org/downloads我的系统是redhat5.8所有选择相应的版本包就ok现在最新版是3.0.3
解压mongodb-linux-x86_64-rhel55-3.0.3.tgz
[root@mongodb ~]# tar zxvf mongodb-linux-x86_64-rhel55-3.0.3.tgz -C /opt/mongodb-linux-x86_64-rhel55-3.0.3/READMEmongodb-linux-x86_64-rhel55-3.0.3/THIRD-PARTY-NOTICESmongodb-linux-x86_64-rhel55-3.0.3/GNU-AGPL-3.0mongodb-linux-x86_64-rhel55-3.0.3/bin/mongodumpmongodb-linux-x86_64-rhel55-3.0.3/bin/mongorestoremongodb-linux-x86_64-rhel55-3.0.3/bin/mongoexportmongodb-linux-x86_64-rhel55-3.0.3/bin/mongoimportmongodb-linux-x86_64-rhel55-3.0.3/bin/mongostatmongodb-linux-x86_64-rhel55-3.0.3/bin/mongotopmongodb-linux-x86_64-rhel55-3.0.3/bin/bsondumpmongodb-linux-x86_64-rhel55-3.0.3/bin/mongofilesmongodb-linux-x86_64-rhel55-3.0.3/bin/mongooplogmongodb-linux-x86_64-rhel55-3.0.3/bin/mongoperfmongodb-linux-x86_64-rhel55-3.0.3/bin/mongodmongodb-linux-x86_64-rhel55-3.0.3/bin/mongosmongodb-linux-x86_64-rhel55-3.0.3/bin/mongo[root@mongodb opt]# ln -sv mongodb-linux-x86_64-rhel55-3.0.3/ mongodbcreate symbolic link `mongodb' to `mongodb-linux-x86_64-rhel55-3.0.3/'
3.创建mongodb用户
[root@mongodb /]# useradd mongodb
4.创建相应文件目录并修改权限
[root@mongodb /]# mkdir /data/db -p[root@mongodb /]# chown mongodb:mongodb /data/ -R[root@mongodb opt]# chown -R mongodb:mongodb /opt/*
5.添加PATH环境变量在shell下正常访问mongodb的应用工具
[root@mongodb bin]# vim /etc/profile.d/mongodb.shexport PATH=$PATH:/opt/mongodb/bin[root@mongodb bin]# source /etc/profile.d/mongodb.sh [root@mongodb bin]# echo $PATH /usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/opt/mongodb/bin
6.创建mongodb的PID存放目录
[root@mongodb run]# mkdir /var/run/mongodb[root@mongodb run]# chown mongodb:mongodb /var/run/mongodb/ -R[root@mongodb opt]# mongod --dbpath /data/db/ --logpath /var/log/mongodb.log --logappend --port 27017 --pidfilepath /var/run/mongodb/mongodb.pid --maxConns 250 --rest --httpinterface --forkabout to fork child process, waiting until server is ready for connections.forked process: 4060child process started successfully, parent exiting--maxConns 250 :表示最大连接数是250个--rest --httpinterface : web接口,指定这项28017端口才能启用--fork :后台运行
7.安装过程中遇见的问题
装好之后连接出现以下警告
(1).[root@mongodb ~]# mongoMongoDB shell version: 3.0.3connecting to: testServer has startup warnings: 2015-06-15T20:27:49.892+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.2015-06-15T20:27:49.892+0800 I CONTROL [initandlisten]
出现这个问题就查看关于mongodb的文件权限,主要是/opt /data/db/ /var/run/mongodb/ /var/log/mongodb.log的权限因为启动初始化时以root用户的权限在运行,所以这些目录下的权限可能会变成root root
(2).[mongodb@mongodb db]$ mongod --dbpath /data/db/ --logpath /var/log/mongodb.log --logappend --port 27017 --pidfilepath /var/run/mongodb/mongodb.pid --maxConns 250 --rest --httpinterface --fork2015-06-15T17:41:25.721+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.2015-06-15T17:41:25.721+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'2015-06-15T17:41:25.721+0800 I CONTROL [initandlisten] 2015-06-15T17:41:25.721+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.2015-06-15T17:41:25.721+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
修改两个参数即可
echo "never" > /sys/kernel/mm/transparent_hugepage/enabled echo "never" > /sys/kernel/mm/transparent_hugepage/defrag
8.安装成功并登录
[root@mongodb ~]# ss -tanlp | grep mongod0 0 *:27017 *:* users:(("mongod",4095,6))0 0 *:28017 *:* users:(("mongod",4095,8)) [root@mongodb ~]# mongoMongoDB shell version: 3.0.3connecting to: test> help db.help() help on db methods db.mycoll.help() help on collection methods sh.help() sharding helpers rs.help() replica set helpers help admin administrative help help connect connecting to a db help help keys key shortcuts help misc misc things to know help mr mapreduce show dbs show database names show collections show collections in current database show users show users in current database show profile show most recent system.profile entries with time >= 1ms show logs show the accessible logger names show log [name] prints out the last segment of log in memory, 'global' is default useset current database db.foo.find() list objects in collection foo db.foo.find( { a : 1 } ) list objects in foo where a == 1 it result of the last line evaluated; use to further iterate DBQuery.shellBatchSize = x set default number of items to display on shell exit quit the mongo shell
登录web接口 28017端口
9.关闭服务器
(1).[root@mongodb ~]# mongod --shutdown killing process with pid: 3936(2).[root@mongodb ~]# killall mongod
10.给mongodb编写配置文件/etc/mongodb.conf
[root@mongodb ~]# grep -v ^# /etc/mongodb.conf logpath=/var/log/mongodb.loglogappend=truefork = truedbpath=/data/dbpidfilepath = /var/run/mongodb/mongodb.pidrest = truehttpinterface = true
启动
[root@mongodb ~]# mongod -f /etc/mongodb.conf about to fork child process, waiting until server is ready for connections.forked process: 4169child process started successfully, parent exiting[root@mongodb ~]# ss -tanlp | grep mongod0 0 *:27017 *:* users:(("mongod",4169,6))0 0 *:28017 *:* users:(("mongod",4169,8))
11.用service mongodb * 来启动mongodb
启动脚本:/etc/rc.d/init.d/mongod
#!/bin/bash# mongod - Startup script for mongod# chkconfig: 35 85 15# description: Mongo is a scalable, document-oriented database.# processname: mongod# config: /etc/mongod.conf# pidfile: /var/run/mongo/mongod.pid. /etc/rc.d/init.d/functions# things from mongod.conf get there by mongod reading itCONFIGFILE="/etc/mongodb.conf"OPTIONS=" -f $CONFIGFILE"SYSCONFIG="/etc/sysconfig/mongod"DBPATH=`awk -F= '/^dbpath=/{print $2}' "$CONFIGFILE"`PIDFILE=`awk -F= '/^dbpath\s=\s/{print $2}' "$CONFIGFILE"`mongod=${MONGOD-/opt/mongodb/bin/mongod}MONGO_USER=mongodbMONGO_GROUP=mongodbif [ -f "$SYSCONFIG" ]; then . "$SYSCONFIG"fi# Handle NUMA access to CPUs (SERVER-3574)# This verifies the existence of numactl as well as testing that the command worksNUMACTL_ARGS="--interleave=all"if which numactl >/dev/null 2>/dev/null && numactl $NUMACTL_ARGS ls / >/dev/null 2>/dev/nullthen NUMACTL="numactl $NUMACTL_ARGS"else NUMACTL=""fistart(){ echo -n $"Starting mongod: " daemon --user "$MONGO_USER" $NUMACTL $mongod $OPTIONS RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod}stop(){ echo -n $"Stopping mongod: " killproc -p "$PIDFILE" -d 300 /opt/mongodb/bin/mongod RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mongod}restart () { stop start}ulimit -n 12000RETVAL=0case "$1" in start) start ;; stop) stop ;; restart|reload|force-reload) restart ;; condrestart) [ -f /var/lock/subsys/mongod ] && restart || : ;; status) status $mongod RETVAL=$? ;; *) echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}" RETVAL=1esacexit $RETVAL
测试启动
[root@mongodb ~]# service mongod startStarting mongod: about to fork child process, waiting until server is ready for connections.forked process: 4426child process started successfully, parent exiting [ OK ][root@mongodb init.d]# ss -tanlp | grep mongod0 0 *:27017 *:* users:(("mongod",4426,6))0 0 *:28017 *:* users:(("mongod",4426,8)) [root@mongodb ~]# mongoMongoDB shell version: 3.0.3connecting to: test> [root@mongodb ~]# service mongod startStarting mongod: about to fork child process, waiting until server is ready for connections.forked process: 4426child process started successfully, parent exiting [ OK ][root@mongodb ~]# service mongod stopStopping mongod: [ OK ]
权限
文件
目录
接口
用户
端口
问题
登录
运行
配置
最大
成功
两个
参数
变量
后台
工具
最新版
服务器
版本
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
python 服务器推送
服务器图形界面监控
松江区品牌软件开发服务要多少钱
关于网络安全的五点
15年10月软件开发工具
掌控计算机网络技术的基础概念
怀旧服服务器刷副本
医学文献检索数据库
五年级网络安全的手抄报图片
宾馆服务器是网管还是软件
数据库施耐德
网络安全课程的总结
宁波什么是软件开发流程
中国科技数据库医药期刊怎么样
昌吉软件开发商
上海中兴软件开发待遇怎么样
青少年网络安全教育家长感言
传奇世界服务器分布
明日之后四字服务器下载网易版
家用宽带 做服务器
数据库系统三级结构的缺点
数据库备份文件恢复路径
网络安全面临的挑战与应对
嘉祥软件开发有限公司
昌平区网络技术咨询职责
掌控计算机网络技术的基础概念
正规的浪潮存储服务器哪里有
有哪些软件开发技术
宁波大学计算机复试数据库技术
服务器的钱