Home > Database > Mysql Tutorial > Mac OSX下手动安装MongoDB

Mac OSX下手动安装MongoDB

WBOY
Release: 2016-06-07 16:37:18
Original
1010 people have browsed it

1、从官网下载osx系统的mongodb包到目录/home/soft,并解压。 cd /home/softcurl -O http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.6.3.tgztar -zxvf mongodb-osx-x86_64-2.6.3.tgz 2、建立一个软连接,并创建一个数据库目录 ln -s ~/home/soft/mo

1、从官网下载osx系统的mongodb包到目录/home/soft,并解压。

cd /home/soft
curl -O http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.6.3.tgz
tar -zxvf mongodb-osx-x86_64-2.6.3.tgz
Copy after login

2、建立一个软连接,并创建一个数据库目录

ln -s ~/home/soft/mongodb-osx-x86_64-2.6.3 /usr/local/mongodb
mkdir -p /usr/local/mongodb/database
Copy after login

3、创建mongod启动的配置文件,并手动启动mongodb试试看。

vi /usr/local/mongodb/mongod.conf
Copy after login

输入以下内容后保存退出

# MongoDB数据库存储目录
dbpath = /usr/local/mongodb/database
# 日志目录
# logpath = /usr/local/var/log/mongodb.log
# 绑定ip,限定只允许本地连接
bind_ip = localhost
# 开启journaling
journal = true
# 开启REST
rest = true
# 启用更小的文件存储
# (可以节省开发环境下的空间)
smallfiles = true
Copy after login

手动启动mongodb试试是否成功:

cd /usr/local/mongodb
./bin/mongod --config=./mongod.conf
Copy after login

看输出,应该OK了。control+c可以终止。

4、把mongodb相关命令加入shell

如果是用BASH,执行

echo 'export PATH=/usr/local/mongodb/bin:$PATH' >> ~/.bash_profile
source ~/.bash_profile
Copy after login

我用的是oh-my-zsh, 修改~/.zshrc文件

vi ~/.zshrc
Copy after login

加入一行

export PATH=/usr/local/mongodb/bin:$PATH
Copy after login

保存并退出后,重新载入

source ~/.zshrc
#然后就可以直接用mongod启动了
mongod --config=/usr/local/mongodb/mongod.conf
Copy after login

5、每次手动都要加入长长的参数,不想写成一个mongo_start.sh,干脆配置为随系统自动启动。

vi ~/Library/LaunchAgents/org.mongodb.mongod.plist
Copy after login

输入

<?xml version="1.0" encoding="UTF-8"?>

<plist version="1.0">
<dict>
 <key>Label</key>
 <string>org.mongodb.mongod</string>
 <key>ProgramArguments</key>
 <array>
 <string>/usr/local/mongodb/bin/mongod</string>
 <string>--config=/usr/local/mongodb/mongod.conf</string>
 </array>
 <key>RunAtLoad</key>
 <true></true>
 <key>KeepAlive</key>
 <true></true>
</dict>
</plist>
Copy after login

然后注册到启动项

launchctl load -w ~/Library/LaunchAgents/org.mongodb.mongod.plist
Copy after login

从启动项取消,使用

launchctl unload -w ~/Library/LaunchAgents/org.mongodb.mongod.plist
Copy after login

完工!

参考资料:

http://mac-dev-env.patrickbougie.com/mongodb/

http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template