本Linux系统为 centos 7.x
1、去官网下载 rpm资源文件
https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.0/x86_64/RPMS/mongodb-org-server-4.0.18-1.el7.x86_64.rpm
https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.0/x86_64/RPMS/mongodb-org-shell-4.0.18-1.el7.x86_64.rpm
2、安装命令
rpm -ivh mongodb-org-server-4.0.18-1.el7.x86_64.rpm
rpm -ivh mongodb-org-shell-4.0.18-1.el7.x86_64.rpm
3、查看或修改配置
安装成功后,会产生一个配置文件:/etc/monogd.conf 文件
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
配置文件为 ymal 格式:
systemLog.path :mongoDB 的系统日志的路径
storage.dbPath :mongoDB 数据文件存放路径
processManagement.pidFilePath : mongoDB 运行时进程文件存放路径
net.port : mongodDB 网络端口号
net.bindIp : mongoDB 绑定的 ip 地址,默认为127.0.0.1 表示只允许本地连接,无法远程连接;修改成0.0.0.0则表示允许其他服务器远程连接到该mongodb服务
上述配置均可按需要做修改。
4、启动与停止
启动命令:
service mongod start
或
systemctl start mongod
或
/usr/bin/mongod -f /etc/mongod.conf
停止命令:
systemctl stop mongod
或
mongod --shutdown
或
ps -ef|grep mongo 查到到进程直接 kill -9