环境 centos8
1.下载程序包
- wget https://repo.mongodb.org/yum/redhat/8/mongodb-org/4.4/x86_64/RPMS/mongodb-org-server-4.4.1-1.el8.x86_64.rpm
- wget https://fastdl.mongodb.org/tools/db/mongodb-database-tools-rhel80-x86_64-100.1.1.rpm
2.安装程序
dnf install ./mongodb-database-tools-rhel80-x86_64-100.1.1.rpm ./mongodb-org-server-4.4.1-1.el8.x86_64.rpm -y
3.修改配置文件,修改默认存储路径和日志路径
- vim /etc/mongod.conf
-
-
- systemLog:
- destination: file
- logAppend: true
- path: /data/log/mongodb/mongod.log
-
- # Where and how to store data.
- storage:
- dbPath: /data/mongodb
- journal:
- enabled: true
- mkdir -pv /data/logs/mongodb
- mkdir -pv /data/mongodb
-
- chown mongod.mongod -R /data/logs/mongodb /data/mongodb
4.启动服务,并设置开机启动
- systemctl start mongod
- systemctl enable mongod
5.备份导入命令
- haoduogames 为库的名字
- #导出
- mongodump --port=17017 -d haoduogames -o aaaa/
-
- #恢复
- mongorestore --drop -d haoduogames aaaa/
docker-compose.yml
- version: '3.2'
-
-
- services:
- mongodb:
- image: bitnami/mongodb:5.0.8
- container_name: mongodb
- restart: always
- environment:
- - ALLOW_EMPTY_PASSWORD=yes
- - MONGODB_SYSTEM_LOG_VERBOSITY=3
- volumes:
- - /data/mongodb:/bitnami/mongodb/data/db
- - /data/logs/mongodb:/opt/bitnami/mongodb/logs
- ports:
- - 27017:27017
-
- # mongo-express:
- # image: mongo-express
- # restart: always
- # networks:
- # - fungame
- # ports:
- # - 8081:8081
- # environment:
- # ME_CONFIG_MONGODB_ADMINUSERNAME: root
- # ME_CONFIG_MONGODB_ADMINPASSWORD: root
- # ME_CONFIG_MONGODB_URL: mongodb://root:root@mongo:27017/
容器操作
- docker-compose up
-
- # 后台运行
- docker-compose up -d
-
- # 停止并删除
- docker-compose down