标签:linux centos nosql mongodb 安装
/** * CentOS-6.4-minimal版中安装MongoDB-x86_64-3.0.2 * @see -------------------------------------------------------------------------------------------------------- * @see 安装MongoDB * @see [Jadyer@CentOS64 ~]$ cd /app/software/ * @see [Jadyer@CentOS64 software]$ tar zxvf mongodb-linux-x86_64-3.0.2.tgz * @see [Jadyer@CentOS64 software]$ mv mongodb-linux-x86_64-3.0.2 /app/mongodb-3.0.2 * @see [root@CentOS64 ~]# vi /etc/profile * @see #Set MongoDB Environment Variable * @see MONGODB_HOME=/app/mongodb-3.0.2 * @see PATH=$PATH:$MONGODB_HOME/bin * @see export MONGODB_HOME PATH * @see [root@CentOS64 ~]# source /etc/profile * @see [root@CentOS64 ~]# mongod -version * @see [Jadyer@CentOS64 ~]$ mongod -version * @see -------------------------------------------------------------------------------------------------------- * @see 配置MongoDB * @see [Jadyer@CentOS64 ~]$ cd /app/mongodb-3.0.2/ * @see [Jadyer@CentOS64 mongodb-3.0.2]$ mkdir data #创建MongoDB存放数据文件的目录 * @see [Jadyer@CentOS64 mongodb-3.0.2]$ mkdir logs #创建MongoDB存放日志文件的目录 * @see [Jadyer@CentOS64 mongodb-3.0.2]$ touch logs/mongodb.log #创建一个空的日志文件 * @see [Jadyer@CentOS64 mongodb-3.0.2]$ cd bin * @see [Jadyer@CentOS64 bin]$ vi startup.sh * @see mongod --dbpath /app/mongodb-3.0.2/data --logpath /app/mongodb-3.0.2/logs/mongodb.log --logappend --fork --rest --httpinterface * @see [Jadyer@CentOS64 bin]$ chmod 755 startup.sh * @see [Jadyer@CentOS64 bin]$ vi shutdown.sh * @see mongod --dbpath /app/mongodb-3.0.2/data --shutdown * @see [Jadyer@CentOS64 bin]$ chmod 755 shutdown.sh * @see [Jadyer@CentOS64 bin]$ vi client.sh * @see mongo 127.0.0.1:27017/admin * @see [Jadyer@CentOS64 bin]$ chmod 755 client.sh * @see -------------------------------------------------------------------------------------------------------- * @create 2015-6-3 下午8:05:59 * @author 玄玉<http://blog.csdn.net/jadyer> */
/** * @see -------------------------------------------------------------------------------------------------------- * 启动MongoDB * @see 启动时,执行上面编写的startup.sh就可以了 * @see 但启动之前,有4点需要注意 * @see 1.用root启动时会有警告提示,可以为mongo单独创建一个用户来启动,以下简称"mongo用户" * @see 2.mongo用户的[ulimit -n]和[ulimit -u]要相同,否则也会有警告提示 * @see 3.先要用root用户执行下面两个命令,否则启动后,客户端连接时会有警告提示 * @see [root@CentOS64 Jadyer]# echo "never" > /sys/kernel/mm/transparent_hugepage/enabled * @see [root@CentOS64 Jadyer]# echo "never" > /sys/kernel/mm/transparent_hugepage/defrag * @see 4.使用wiredTiger引擎时,需要加上directoryperdb参数,让数据库分文件夹,不然小文件太多了 * @see 比如:numactl --interleave=all /usr/local/mongodb/bin/mongod --fork --httpinterface --noauth --bind_ip=0.0.0.0 --port=27017 --storageEngine=wiredTiger --directoryperdb --dbpath=/data/mongodata/data/db1 --logpath=/data/mongodata/logs/mongodb.log --logappend * @see -------------------------------------------------------------------------------------------------------- * @see 管理MongoDB * @see [Jadyer@CentOS64 ~]$ cd /app/mongodb-3.0.2/bin/ * @see [Jadyer@CentOS64 bin]$ ./startup.sh * @see [Jadyer@CentOS64 bin]$ ./client.sh * @see MongoDB shell version: 3.0.2 * @see connecting to: 127.0.0.1:27017/admin * @see > show dbs * @see local 0.078GB #此时是看不见admin的,但mongodb3.0中有一个能管理用户的userAdminAnyDatabase * @see > db.createUser({user:"xuanyu",pwd:"222222",roles:[{role:"userAdminAnyDatabase",db:"admin"}]}) * @see > show users #查看刚才创建的用户 * @see > db.system.users.find() #该命令也能查看创建的用户,而且信息更详细 * @see > db.shutdownServer() #关闭数据库(也可用上面编写的shutdown.sh) * @see [Jadyer@CentOS64 bin]$ vi startup.sh #加入[--auth]参数 * @see [Jadyer@CentOS64 bin]$ ./startup.sh * @see [Jadyer@CentOS64 bin]$ ./client.sh * @see MongoDB shell version: 3.0.2 * @see connecting to: 127.0.0.1:27017/admin * @see > show dbs #此时会报告not authorized on admin to execute command { listDatabases: 1.0 } * @see > db.auth("xuanyu", "222222") #返回1表示认证通过 * @see 1 * @see > show dbs * @see admin 0.078GB * @see local 0.078GB * @see > show collections #这时也会报错not authorized on admin...(因为"xuanyu"用户只有用户管理的权限) * @see > cls #清屏 * @see > use jishu * @see switched to db jishu * @see > db.createUser({user:"xuanyudev", pwd:"222222", roles:[{role:"readWrite",db:"jishu"},{role:"read",db:"jishu22"}]}) * @see > show users #查看刚才创建的用户 * @see > use admin * @see switched to db admin * @see > db.system.users.find() #查看数据库中的所有用户 * @see > use jishu * @see switched to db jishu * @see > show collections #这时还会报告not authorized on admin...(因为没权限,先赋权) * @see > db.auth("xuanyudev", "222222") * @see 1 * @see > show collections #如此便可以了 * @see -------------------------------------------------------------------------------------------------------- * @see 一些文章 * @see MongoDB的真正性能-实战百万用户一-一亿的道具 * @see http://www.cnblogs.com/crazylights/archive/2013/05/08/3068098.html * @see MONGODB中OBJECTID的误区,以及引起的一系列问题 * @see http://www.cnphp6.com/archives/64392 * @see -------------------------------------------------------------------------------------------------------- * @create 2015-6-3 下午8:11:34 * @author 玄玉<http://blog.csdn.net/jadyer> */
CentOS-6.4-minimal版中安装MongoDB-x86_64-3.0.2
标签:linux centos nosql mongodb 安装
原文地址:http://blog.csdn.net/jadyer/article/details/46350597