因工作测试需要,特此笔录
1.下载“下载工具”
sudo apt install curl
2.添加mongodb下载页的公共密钥
curl https://www.mongodb.org/static/pgp/server-4.0.asc | sudo apt-key add -
3.添加源
sudo nano /etc/apt/sources.list.d/mongodb-org-4.0.list
deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/4.0 main
4.更新源并安装
sudo apt update
sudo apt-get install mongodb-org
5.启动服务
sudo systemctl enable mongod
sudo systemctl start mongod
6.检查服务以及数据库
sudo systemctl status mongod
如果看到如下信息
Output● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2018-11-29 17:59:56 UTC; 3s ago
Docs: https://docs.mongodb.org/manual
Main PID: 1827 (mongod)
Tasks: 26
CGroup: /system.slice/mongod.service
└─4321 /usr/bin/mongod --config /etc/mongod.conf
证明数据库服务启动了
执行
mongo --eval 'db.runCommand({ connectionStatus: 1 })'
输出
OutputMongoDB shell version v4.0.2
connecting to: mongodb://127.0.0.1:27017
`````````````````(省略)
可以查看版本,端口等信息
配置文件位置/etc/mongod.conf
7.管理Mongodb服务
查看状态
sudo systemctl status mongod
停止服务
sudo systemctl stop mongod
开始服务
sudo systemctl start mongod
重启服务
sudo systemctl restart mongod
禁用自动启动服务
sudo systemctl disable mongod
启动服务
sudo systemctl enable mongod
8.调整防火墙
sudo ufw allow from your_other_server_ip/32 to any port 27017
查看防火墙状态
sudo ufw status
结果
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
27017 ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
27017 (v6) ALLOW Anywhere (v6)
Reference:
https://www.jianshu.com/p/f79be2ef5ece