1、创建mongodb源仓库
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo CentOS-Media.repo
CentOS-CR.repo CentOS-Sources.repo
CentOS-Debuginfo.repo CentOS-Vault.repo
CentOS-fasttrack.repo
[root@localhost yum.repos.d]# vim mongodb-org.repo
[mongodb-org]
name=MongoDB Repository
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
[root@localhost yum.repos.d]# yum list #更新安装列表
2、安装mongodb
[root@localhost yum.repos.d]# yum install -y mongodb-org
3、更改配置文件
vi /etc/mongod.conf
port: 27017 #监听端口
bindIp: 0.0.0.0 #监听地址
systemctl start mongod.service
[root@localhost yum.repos.d]# netstat -natp | grep 27017
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 14849/mongod
/usr/bin/mongo #进入数据库
> show dbs #查看数据文件
admin 0.000GB
config 0.000GB
local 0.000GB
> db.version() #查看版本号
4.0.23
> db.getMongo() #查看当前数据库机器的连接地址
connection to 127.0.0.1:27017
4、关闭防火墙
[root@localhost yum.repos.d]# systemctl stop firewalld
[root@localhost yum.repos.d]# setenforce 0
[root@localhost yum.repos.d]# systemctl disable firewalld.service
5、多实例创建
[root@localhost yum.repos.d]# cd /etc/
[root@localhost etc]# cp -p mongod.conf mongod2.conf
[root@localhost etc]# vim mongod2.conf
systemLog:
destination: file
logAppend: true
path: /data/mongodb/mongod2.log #修改日志存放路径
storage:
dbPath: /data/mongodb/mongo #修改数据存放路径
journal:
enabled: true
net:
port: 27018 #修改端口号
bindIp: 0.0.0.0
[root@localhost etc]# mkdir -p /data/mongodb
[root@localhost etc]# cd /data/mongodb/
[root@localhost mongodb]# mkdir mongo
[root@localhost mongodb]# touch mongod2.log
[root@localhost mongodb]# chmod 777 mongod2.log
[root@localhost mongodb]# mongod -f /etc/mongod2.conf
about to fork child process, waiting until server is ready for connections.
forked process: 15257
child process started successfully, parent exiting
[root@localhost mongodb]# mongo --port 27018 #进入指定的27018端口的mongodb数据库