Ubuntu16.04安裝mongodb

先更換軟件源爲阿里源
vi /etc/apt/ sources.list
 
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
 
1. .導入軟件源的公鑰
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
 
2.爲mongodb建立軟件源list文件
ubuntu12.04:
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.04:
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.更新軟件源並安裝mongodb:
sudo apt-get update
sudo apt-get install -y mongodb-org
若是想要安裝特定的版本,使用下面命令:
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文件,並寫入下面內容:
[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的徹底卸載
先中止運行mongodb
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*||"`
相關文章
相關標籤/搜索