Ubuntu16.04安裝mongodb

Ubuntu16.04安裝mongodbphp

copy from: http://blog.csdn.net/zhushh/article/details/52451441git

1.導入軟件源的公鑰github

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927

2.爲mongodb建立軟件源list文件
ubuntu12.04mongodb

echo "deb http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list

ubuntu14.04shell

echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list

ubuntu16.04數據庫

echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list

3.更新軟件源並安裝mongodbubuntu

sudo apt-get update sudo apt-get install -y mongodb-org

若是想要安裝特定的版本,使用下面命令:bash

sudo apt-get install -y mongodb-org=3.2.9 mongodb-org-server=3.2.9 mongodb-org-shell=3.2.9 mongodb-org-mongos=3.2.9 mongodb-org-tools=3.2.9

4.配置啓動文件
若是是ubuntu16.04的版本,須要手動新建/lib/systemd/system/mongod.service文件,並寫入下面內容:markdown

[Unit] Description=High-performance, schema-free document-oriented database After=network.target Documentation=https://docs.mongodb.org/manual [Service] User=mongodb Group=mongodb ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf [Install] WantedBy=multi-user.target
5.啓動、重啓和關閉命令
sudo service mongod start sudo service mongod restart sudo service mongod stop

6.mongodb的徹底卸載
先中止運行mongodbui

sudo service mongod stop

再卸載軟件

sudo apt-get purge mongodb-org*

刪除數據庫和日誌文件

sudo rm -r /var/log/mongodb sudo rm -r /var/lib/mongodb

7.添加php的mongodb擴展

# pecl install mongodb # echo "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
參考連接:

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
http://mongodb.github.io/mongo-php-driver/

相關文章
相關標籤/搜索