官网下载
https://www.mongodb.com/try/download/community
[root@centosa mongo]# tar -zxvf mongodb-linux-x86_64-rhel70-5.0.9.tgz
安装软件一般看 readme
[root@centosa mongodb-linux-x86_64-rhel70-5.0.9]# cat README
MongoDB README
Welcome to MongoDB!
COMPONENTS
mongod - The database server. //开启服务命令
mongos - Sharding router.
mongo - The database shell (uses interactive javascript). //接接使用
UTILITIES
install_compass - Installs MongoDB Compass for your platform. //使用指南
BUILDING
See docs/building.md.
RUNNING
For command line options invoke:
$ ./mongod --help
To run a single server database:
$ sudo mkdir -p /data/db
$ ./mongod
$
$ # The mongo javascript shell connects to localhost and test database by default:
$ ./mongo
> help
看下所有的配置 大概一些常用的写了下;
### 帮助命令查看可以使用的配置
[root@centosa bin]# ./mongod --help
Options:
--networkMessageCompressors arg (=snappy,zstd,zlib)
Comma-separated list of compressors to
use for network messages
General options:## 常用选项
-h [ --help ] Show this usage information
--version Show version information
-f [ --config ] arg Configuration file specifying ### 配置文件 指定其他的配置
additional options
--configExpand arg Process expansion directives in config
file (none, exec, rest)
--port arg Specify port number - 27017 by default ## 端口
--ipv6 Enable IPv6 support (disabled by
default)
--listenBacklog arg (=128) Set socket listen backlog size
--maxConns arg (=1000000) Max number of simultaneous connections ## 最大连接数
--pidfilepath arg Full path to pidfile (if not set, no ### pidfile 文件全路径
pidfile is created)
--timeZoneInfo arg Full path to time zone info directory, ##时区
e.g. /usr/share/zoneinfo
--nounixsocket Disable listening on unix sockets
--unixSocketPrefix arg Alternative directory for UNIX domain
sockets (defaults to /tmp)
--filePermissions arg Permissions to set on UNIX domain
socket file - 0700 by default
--fork Fork server process ## 是否后台运行
-v [ --verbose ] [=arg(=v)] Be more verbose (include multiple times
for more verbosity e.g. -vvvvv)
--quiet Quieter output
--logpath arg Log file to send write to instead of ## 日志文件 是一个文件不是目录
stdout - has to be a file, not
directory
--syslog Log to system's syslog facility instead ## 系统日志文件路径
of file or stdout
--syslogFacility arg syslog facility used for mongodb syslog
message
--logappend Append to logpath instead of ## 日志写入方式 追加代替覆盖
over-writing
--logRotate arg Set the log rotation behavior ## 设置日志轮换行为
(rename|reopen)
--timeStampFormat arg Desired format for timestamps in log ## 时间搓格式
messages. One of iso8601-utc or
iso8601-local
--setParameter arg Set a configurable parameter
--bind_ip arg Comma separated list of ip addresses to ## 绑定的ip
listen on - localhost by default
--bind_ip_all Bind to all ip addresses
--noauth Run without security ## 不进行登陆认证
--transitionToAuth For rolling access control upgrade.
Attempt to authenticate over outgoing
connections and proceed regardless of
success. Accept incoming connections
with or without authentication.
--slowms arg (=100) Value of slow for profile and console ## 慢查询 毫秒
log
--slowOpSampleRate arg (=1) Fraction of slow ops to include in the ## 慢查询 比例
profile and console log
--profileFilter arg Query predicate to control which
operations are logged and profiled
--auth Run with security ## 进行登陆认证
--clusterIpSourceAllowlist arg Network CIDR specification of permitted
origin for `__system` access
--profile arg 0=off 1=slow, 2=all ## 关闭 /慢查询 / 所有 日志
--cpu Periodically show cpu and iowait ## 定期显示 cpu 和 iowait 利用率
utilization
--sysinfo Print some diagnostic system
information
--noscripting Disable scripting engine
--notablescan Do not allow table scans
--shutdown Kill a running server (for init ### 关闭mongo
scripts)
--keyFile arg Private key for cluster authentication
--clusterAuthMode arg Authentication mode used for cluster
authentication. Alternatives are
(keyFile|sendKeyFile|sendX509|x509)
Replication options: ### 主从复制选项
--oplogSize arg Size to use (in MB) for replication op
log. default is 5% of disk space (i.e.
large is good)
Replica set options: ### 副本的一些配置
--replSet arg arg is <setname>[/<optionalseedhostlist
>]
--enableMajorityReadConcern [=arg(=1)] (=1)
Enables majority readConcern.
enableMajorityReadConcern=false is no
longer supported
Sharding options: ### 分片的一些配置
--configsvr Declare this is a config db of a
cluster; default port 27019; default
dir /data/configdb
--shardsvr Declare this is a shard db of a
cluster; default port 27018
Storage options: ### 存储的一些配置
--storageEngine arg What storage engine to use - defaults ###存储 引擎选择
to wiredTiger if no data files present
--dbpath arg Directory for datafiles - defaults to ### 数据库文件路径
/data/db
--directoryperdb Each database will be stored in a
separate directory
--syncdelay arg (=60) Seconds between disk syncs
--journalCommitInterval arg (=100) how often to group/batch commit (ms)
--upgrade Upgrade db if needed
--repair Run repair on all dbs
--journal Enable journaling
--nojournal Disable journaling (journaling is on by
default for 64 bit)
--oplogMinRetentionHours arg (=0) Minimum number of hours to preserve in
the oplog. Default is 0 (turned off).
Fractions are allowed (e.g. 1.5 hours)
Free Monitoring Options: ## 监控配置
--enableFreeMonitoring arg Enable Cloud Free Monitoring
(on|runtime|off)
--freeMonitoringTag arg Cloud Free Monitoring Tags
TLS Options: ## TLS配置 安全传输
--tlsOnNormalPorts Use TLS on configured ports
--tlsMode arg Set the TLS operation mode
(disabled|allowTLS|preferTLS|requireTLS
)
--tlsCertificateKeyFile arg Certificate and key file for TLS
--tlsCertificateKeyFilePassword arg Password to unlock key in the TLS
certificate key file
--tlsClusterFile arg Key file for internal TLS
authentication
--tlsClusterPassword arg Internal authentication key file
password
--tlsCAFile arg Certificate Authority file for TLS
--tlsClusterCAFile arg CA used for verifying remotes during
inbound connections
--tlsCRLFile arg Certificate Revocation List file for
TLS
--tlsDisabledProtocols arg Comma separated list of TLS protocols
to disable [TLS1_0,TLS1_1,TLS1_2,TLS1_3
]
--tlsAllowConnectionsWithoutCertificates
Allow client to connect without
presenting a certificate
--tlsAllowInvalidHostnames Allow server certificates to provide
non-matching hostnames
--tlsAllowInvalidCertificates Allow connections to servers with
invalid certificates
--tlsFIPSMode Activate FIPS 140-2 mode at startup
--tlsLogVersions arg Comma separated list of TLS protocols
to log on connect [TLS1_0,TLS1_1,TLS1_2
,TLS1_3]
AWS IAM Options:
--awsIamSessionToken arg AWS Session Token for temporary
credentials
WiredTiger options:
--wiredTigerCacheSizeGB arg Maximum amount of memory to allocate
for cache; Defaults to 1/2 of physical
RAM
--zstdDefaultCompressionLevel arg (=6)
Default compression level for zstandard
compressor
--wiredTigerJournalCompressor arg (=snappy)
Use a compressor for log records
[none|snappy|zlib|zstd]
--wiredTigerDirectoryForIndexes Put indexes and data in different
directories
--wiredTigerCollectionBlockCompressor arg (=snappy)
Block compression algorithm for
collection data [none|snappy|zlib|zstd]
--wiredTigerIndexPrefixCompression arg (=1)
Use prefix compression on row-store
leaf pages
我们现在用配置文件的形式来开启服务
port=27017
bind_ip=0.0.0.0
dbpath=/package/mongo/data ### 提前创建好目录
logpath=/package/mongo/logs/logs.log ### 提前创建好文件
fork=true
[root@centosa bin]# ./mongod -f mdb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 18988
child process started successfully, parent exiting
连接成功
[root@centosa bin]# ./mongo
MongoDB shell version v5.0.9
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("3fb88a9c-95d1-4907-b3ca-2bda3271570f") }
MongoDB server version: 5.0.9
================
Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in
an upcoming release.
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
https://community.mongodb.com
---
The server generated these startup warnings when booting:
2022-06-12T21:36:27.351+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
2022-06-12T21:36:27.351+08:00: You are running this process as the root user, which is not recommended
2022-06-12T21:36:27.352+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
2022-06-12T21:36:27.352+08:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
2022-06-12T21:36:27.352+08:00: Soft rlimits for open file descriptors too low
2022-06-12T21:36:27.352+08:00: currentValue: 1024
2022-06-12T21:36:27.352+08:00: recommendedMinimum: 64000
---
---
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()
---
> show databases;
admin 0.000GB
config 0.000GB
local 0.000GB
> use admin
switched to db admin