標籤(空格分隔): mongodbmongodb
參考資料
mongodb 官方文檔數據庫
Import the public key used by the package management system.ubuntu
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
Create a list file for MongoDB.¶vim
Create the /etc/apt/sources.list.d/mongodb-org-3.4.list list file using the command appropriate for your version of Ubuntu:數組
執行如下命令:添加包的源安全
echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
若是是阿里雲的app
deb [ arch=amd64,arm64 ] http://mirrors.aliyun.com/mongodb/apt/ubuntu xenial/mongodb-org/3.4 multiverse
Reload local package database.tcp
Issue the following command to reload the local package database:工具
執行如下命令:更新ubuntu的包測試
sudo apt-get update
Install the MongoDB packages.
Install the latest stable version of MongoDB.
Issue the following command:
sudo apt-get install -y mongodb-org
Run MongoDB Community Edition
開啓mongod 服務
sudo service mongod start
中止mongod 服務
sudo service mongod stop
重啓mongod服務
sudo service mongod restart
sudo service mongod stop
sudo apt-get purge mongodb-org*
移除mongodb數據庫和日誌文件
sudo rm -r /var/log/mongodb sudo rm -r /var/lib/mongodb
修改/etc/mongod.conf
vim /etc/mongod.conf
# mongod.conf # for documentation of all options, see: # http://docs.mongodb.org/manual/reference/configuration-options/ # Where and how to store data. storage: dbPath: /var/lib/mongodb journal: enabled: true # engine: # mmapv1: # wiredTiger: # where to write logging data. systemLog: destination: file logAppend: true path: /var/log/mongodb/mongod.log # network interfaces net: port: 27017 bindIp: [127.0.0.1,59.110.143.210] #processManagement: #security: #operationProfiling: #replication: #sharding: ## Enterprise-Only Options: #auditLog: #snmp:
修改爲下面的方式
net: port: 27017 #bindIp: [127.0.0.1,59.110.143.210] # 注意這個ip 是這個主機 的ip 2017年10月30日修改,不須要這樣作了 bindIp: # 把這ip去掉
怎麼查看主機的ip:ifconfig
坑:記得格式不是 加空格 也不是加逗號,以數組的方式
ok
sudo service mongod restart
vim /etc/iptables.rules
-A INPUT -s 127.0.0.1 -p tcp --destination-port 27017 -m state --state NEW,ESTABLISHED -j ACCEPT -A INPUT -s 59.110.143.210 -p tcp --destination-port 27017 -m state --state NEW,ESTABLISHED -j ACCEPT -A OUTPUT -d 127.0.0.1 -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT -A OUTPUT -d 59.110.143.210 -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT
iptables-restore < /etc/iptables.rules
能夠在window 或 mac上下載 mongobooster gui工具鏈接