一、MongoDB是一款NoSql数据库
二、部署单实例MongoDB
1.安装环境:
(1)系统:Centos7.2
(2)MongoDB:Percona的MongoDB3.4
2.配置yum源
percona官方文档【https://www.percona.com/doc/percona-repo-config/yum-repo.html】
# yum -y install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm
3.yum安装MongoDB
percona官网文档【https://www.percona.com/doc/percona-server-for-mongodb/3.6/install/yum.html#yum】
# yum install Percona-Server-MongoDB-34
4.创建MongoDB服务目录
# mkdir -p /opt/mongo/{mongo_data,mongo_log}# chown -R mongod.mongod /opt/mongo/# usermod -d /opt/mongo mongod
5.优化配置文件
# vim /etc/mongod.conf
修改以下标红部分配置
storage:
dbPath: /opt/mongo/mongo_data/
systemLog:
destination: file
logAppend: true
path: /opt/mongo/mongo_log/mongod.log
net:
port: 27017
bindIp: 本机内网IP
6.修改systemd相关配置
# vim /usr/lib/systemd/system/mongod.service
修改
PIDFile=/opt/mongo/mongo_log/mongod.pid
# vim /etc/sysconfig/mongod
STDOUT="/opt/mongo/mongo_log/mongod.stdout"
STDERR="/opt/mongo/mongo_log/mongod.stderr"# systemctl daemon-reload
7.启动MongoDB实例
# systemctl enable mongod #开机自启
# systemctl start mongod #启动MongoDB
8.登录MongoDB
# mongo --host 10.140.0.4 --port 27017
Percona Server for MongoDB shell version v3.4.14-2.12
connecting to: mongodb://10.140.0.4:27017/
Percona Server for MongoDB server version: v3.4.14-2.12
Server has startup warnings:
2018-05-08T03:00:19.574+0800 I CONTROL [initandlisten]
2018-05-08T03:00:19.574+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-05-08T03:00:19.574+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-05-08T03:00:19.574+0800 I CONTROL [initandlisten] ** You can use percona-server-mongodb-enable-auth.sh to fix it.
2018-05-08T03:00:19.574+0800 I CONTROL [initandlisten]