mongodb安装教程
-
下载源文件
下载地址(按需选择):https://www.mongodb.com/download-center/community
这里的试用地址:https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.11.tgz -
安装
tar -zxvf mongodb-linux-x86_64-3.6.11.tgz
mv mongodb-linux-x86_64-3.6.11 /usr/local
- 定义配置文件
storage:
dbPath: /var/data/mongodb
journal:
enabled: true
systemLog:
path: /var/log/mongodb/mongodb.log
destination: file
logAppend: true
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
net:
port: 27017
bindIpAll: true #所有ip都可以 方便远程访问
# bindIp: 127.0.0.1
security:
authorization: disabled #初始安装先关闭没得默认值
- 启动
/usr/local/mongodb-linux-x86_64-3.6.11/bin/mongod --config /etc/mongodb.conf
- 配置环境变量
vim /etc/profile
export /usr/local/mongodb-linux-x86_64-3.6.11/bin
source /etc/profile
- 制作systemctl启动
cd /lib/systemd/system
touch mongodb.service
vim mongodb.service
[Unit]
Description=mongodb
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/var/run/mongodb/mongod.pid
ExecStart=/usr/local/mongodb-linux-x86_64-3.6.11/bin/mongod --config /etc/mongodb.conf
ExecStop=/usr/local/mongodb-linux-x86_64-3.6.11/bin/mongod --shutdown --config /etc/mongodb.conf
PrivateTmp=false
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start mongodb
- 访问
mongo
show dbs #显示多有的数据库
use admin #使用哪个数据库
show collections #显示所有的集合(同数据库表)