MongoDB 4.0 CentOS下YUM安装部署

使用tgz压缩包安装:
#wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.0.1.tgz
或者时候用RPM包:
1.配置软件仓库:
#cat /etc/yum.repos.d/mongodb-org-4.0.repo
[mongodb]
name=MongoDB
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
2.版本搜索:
# yum search mongodb-org --show-duplicate
...
====================================== N/S matched: mongodb-org =======================================
mongodb-org-4.0.0-1.el7.x86_64 : MongoDB open source document-oriented database system (metapackage)
mongodb-org-4.0.1-1.el7.x86_64 : MongoDB open source document-oriented database system (metapackage)
mongodb-org-mongos-4.0.0-1.el7.x86_64 : MongoDB sharded cluster query router
mongodb-org-mongos-4.0.1-1.el7.x86_64 : MongoDB sharded cluster query router
mongodb-org-server-4.0.0-1.el7.x86_64 : MongoDB database server
mongodb-org-server-4.0.1-1.el7.x86_64 : MongoDB database server
mongodb-org-shell-4.0.0-1.el7.x86_64 : MongoDB shell client
mongodb-org-shell-4.0.1-1.el7.x86_64 : MongoDB shell client
mongodb-org-tools-4.0.0-1.el7.x86_64 : MongoDB tools
mongodb-org-tools-4.0.1-1.el7.x86_64 : MongoDB tools

  Name and summary matches only, use "search all" for everything.

3.安装:
# yum -y install mongodb-org-4.0.1 mongodb-org-mongos-4.0.1 mongodb-org-server-4.0.1 mongodb-org-shell-4.0.1 mongodb-org-tools-4.0.1
...
Dependencies Resolved

=======================================================================================================
 Package                        Arch               Version                   Repository           Size
=======================================================================================================
Installing:
 mongodb-org                    x86_64             4.0.1-1.el7               mongodb             5.8 k
 mongodb-org-mongos             x86_64             4.0.1-1.el7               mongodb              12 M
 mongodb-org-server             x86_64             4.0.1-1.el7               mongodb              21 M
 mongodb-org-shell              x86_64             4.0.1-1.el7               mongodb              13 M
 mongodb-org-tools              x86_64             4.0.1-1.el7               mongodb              29 M

Transaction Summary
=======================================================================================================
Install  5 Packages

4.查看mongoDB的软件包位置:
# rpm -ql mongodb-org-server
/etc/mongod.conf
/lib/systemd/system/mongod.service
/usr/bin/mongod
/usr/share/doc/mongodb-org-server-4.0.1
/usr/share/doc/mongodb-org-server-4.0.1/GNU-AGPL-3.0
/usr/share/doc/mongodb-org-server-4.0.1/LICENSE-Community.txt
/usr/share/doc/mongodb-org-server-4.0.1/MPL-2
/usr/share/doc/mongodb-org-server-4.0.1/README
/usr/share/doc/mongodb-org-server-4.0.1/THIRD-PARTY-NOTICES
/usr/share/man/man1/mongod.1
/var/lib/mongo
/var/log/mongodb
/var/log/mongodb/mongod.log
/var/run/mongodb
通过上面的查询我们可以看到mongoDB的服务名为mongod.
5.启动:

# systemctl start mongod
6.登录:
# mongo
MongoDB shell version v4.0.1
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 4.0.1
Server has startup warnings: 
2018-08-14T15:21:54.945+0800 I CONTROL  [initandlisten] 
2018-08-14T15:21:54.945+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-08-14T15:21:54.945+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2018-08-14T15:21:54.945+0800 I CONTROL  [initandlisten] 
2018-08-14T15:21:54.945+0800 I CONTROL  [initandlisten] 
2018-08-14T15:21:54.945+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-08-14T15:21:54.945+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2018-08-14T15:21:54.948+0800 I CONTROL  [initandlisten] 
2018-08-14T15:21:54.948+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-08-14T15:21:54.948+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2018-08-14T15:21:54.949+0800 I CONTROL  [initandlisten] 
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---

> 
默认使用无认证的方式登录mongoDB。
7.操作系统的要求和设置:
7.1推荐使用xfs和ext4文件系统
7.2 SELinux:
若开启SELinux:
semanage port -a -t mongod_port_t -p tcp 27017
管理SELinux:
#cat /etc/selinux/config
SELINUX=disabled

8.MongoDB操作:
8.1关闭、启动、重启MongoDB
# service mongod restart
Redirecting to /bin/systemctl restart mongod.service
8.2 设置开启启动:
# service mongod restart
Redirecting to /bin/systemctl restart mongod.service

9.删除mongoDB:
#sudo service mongod stop
#sudo yum erase $(rpm -qa | grep mongodb-org)
#sudo rm -r /var/log/mongodb
#sudo rm -r /var/lib/mongo


 

你可能感兴趣的:(MongoDB)