• 企业架构LNMP学习笔记55


    MongoDB的安装和配置:

    1、安装方式介绍:

    yum安装方式:

    手动通用安装方式:

    2、二进制可执行安装:

    下载路径:Download MongoDB Community Server | MongoDB

     下载mongodb的源码包进行安装。

    1)解压到安装目录并移动:

    1. shell > tar xvf mongodb-linux-x86_64-rhel62-3.6.5.tgz
    2. shell > mv mongodb-linux-x86_64-rhel62-3.6.5 /usr/local/mongodb
    3. [root@server10 soft]# tar -zxvf mongodb-linux-x86_64-rhel62-3.6.5.tgz
    4. mongodb-linux-x86_64-rhel62-3.6.5/README
    5. mongodb-linux-x86_64-rhel62-3.6.5/THIRD-PARTY-NOTICES
    6. mongodb-linux-x86_64-rhel62-3.6.5/MPL-2
    7. mongodb-linux-x86_64-rhel62-3.6.5/GNU-AGPL-3.0
    8. mongodb-linux-x86_64-rhel62-3.6.5/bin/mongodump
    9. mongodb-linux-x86_64-rhel62-3.6.5/bin/mongorestore
    10. mongodb-linux-x86_64-rhel62-3.6.5/bin/mongoexport
    11. mongodb-linux-x86_64-rhel62-3.6.5/bin/mongoimport
    12. mongodb-linux-x86_64-rhel62-3.6.5/bin/mongostat
    13. mongodb-linux-x86_64-rhel62-3.6.5/bin/mongotop
    14. mongodb-linux-x86_64-rhel62-3.6.5/bin/bsondump
    15. mongodb-linux-x86_64-rhel62-3.6.5/bin/mongofiles
    16. mongodb-linux-x86_64-rhel62-3.6.5/bin/mongoreplay
    17. mongodb-linux-x86_64-rhel62-3.6.5/bin/mongoperf
    18. mongodb-linux-x86_64-rhel62-3.6.5/bin/mongod
    19. mongodb-linux-x86_64-rhel62-3.6.5/bin/mongos
    20. mongodb-linux-x86_64-rhel62-3.6.5/bin/mongo
    21. mongodb-linux-x86_64-rhel62-3.6.5/bin/install_compass
    22. [root@server10 soft]# ll
    23. total 98236
    24. drwxr-xr-x 3 root root 91 Sep 16 20:05 mongodb-linux-x86_64-rhel62-3.6.5
    25. -rw-r--r-- 1 root root 100589678 Sep 16 20:04 mongodb-linux-x86_64-rhel62-3.6.5.tgz
    26. [root@server10 soft]#
    27. [root@server10 soft]# mv mongodb-linux-x86_64-rhel62-3.6.5 /usr/local/mongodb

    2)创建数据存储目录和日志目录:

    1. shell > cd /usr/local/mongodb
    2. shell > mkdir data
    3. shell > mkdir logs

    3)启动mongod服务:

    1. shell > cd /usr/local/mongodb/bin
    2. shell > ./mongod --dbpath=/usr/local/mongodb/data --logpath=/usr/local/mongodb/logs/log.txt --fork
    3. #可以通过进程和端口的方式检测是否启动成功
    4. shell > ps aux|grep mongod
    5. shell > netstat -lntp|grep mongod

     端口是27017,为什么是127.0.0.1是本地,是为了安全。

    1. [root@server10 bin]# ./mongod --help
    2. Options:
    3. General options:
    4. -h [ --help ] show this usage information
    5. --version show version information
    6. -f [ --config ] arg configuration file specifying
    7. additional options
    8. -v [ --verbose ] [=arg(=v)] be more verbose (include multiple times
    9. for more verbosity e.g. -vvvvv)
    10. --quiet quieter output
    11. --port arg specify port number - 27017 by default
    12. --bind_ip arg comma separated list of ip addresses to
    13. listen on - localhost by default
    14. --bind_ip_all bind to all ip addresses
    15. --ipv6 enable IPv6 support (disabled by
    16. default)
    17. --listenBacklog arg (=128) set socket listen backlog size
    18. --maxConns arg max number of simultaneous connections
    19. - 1000000 by default
    20. --logpath arg log file to send write to instead of
    21. stdout - has to be a file, not
    22. directory
    23. --syslog log to system's syslog facility instead
    24. of file or stdout
    25. --syslogFacility arg syslog facility used for mongodb syslog
    26. message
    27. --logappend append to logpath instead of
    28. over-writing
    29. --logRotate arg set the log rotation behavior
    30. (rename|reopen)
    31. --timeStampFormat arg Desired format for timestamps in log
    32. messages. One of ctime, iso8601-utc or
    33. iso8601-local
    34. --pidfilepath arg full path to pidfile (if not set, no
    35. pidfile is created)
    36. --timeZoneInfo arg full path to time zone info directory,
    37. e.g. /usr/share/zoneinfo
    38. --keyFile arg private key for cluster authentication
    39. --noauth run without security
    40. --setParameter arg Set a configurable parameter
    41. --transitionToAuth For rolling access control upgrade.
    42. Attempt to authenticate over outgoing
    43. connections and proceed regardless of
    44. success. Accept incoming connections
    45. with or without authentication.
    46. --clusterAuthMode arg Authentication mode used for cluster
    47. authentication. Alternatives are
    48. (keyFile|sendKeyFile|sendX509|x509)
    49. --nounixsocket disable listening on unix sockets
    50. --unixSocketPrefix arg alternative directory for UNIX domain
    51. sockets (defaults to /tmp)
    52. --filePermissions arg permissions to set on UNIX domain
    53. socket file - 0700 by default
    54. --fork fork server process
    55. --networkMessageCompressors [=arg(=disabled)] (=snappy)
    56. Comma-separated list of compressors to
    57. use for network messages
    58. --auth run with security
    59. --clusterIpSourceWhitelist arg Network CIDR specification of permitted
    60. origin for `__system` access.
    61. --slowms arg (=100) value of slow for profile and console
    62. log
    63. --slowOpSampleRate arg (=1) fraction of slow ops to include in the
    64. profile and console log
    65. --profile arg 0=off 1=slow, 2=all
    66. --cpu periodically show cpu and iowait
    67. utilization
    68. --sysinfo print some diagnostic system
    69. information
    70. --noIndexBuildRetry don't retry any index builds that were
    71. interrupted by shutdown
    72. --noscripting disable scripting engine
    73. --notablescan do not allow table scans
    74. --shutdown kill a running server (for init
    75. scripts)
    76. Replication options:
    77. --oplogSize arg size to use (in MB) for replication op
    78. log. default is 5% of disk space (i.e.
    79. large is good)
    80. Master/slave options (old; use replica sets instead):
    81. --master master mode
    82. --slave slave mode
    83. --source arg when slave: specify master as
    84. --only arg when slave: specify a single database
    85. to replicate
    86. --slavedelay arg specify delay (in seconds) to be used
    87. when applying master ops to slave
    88. --autoresync automatically resync if slave data is
    89. stale
    90. Replica set options:
    91. --replSet arg arg is [/
    92. >]
    93. --replIndexPrefetch arg specify index prefetching behavior (if
    94. secondary) [none|_id_only|all]
    95. --enableMajorityReadConcern [=arg(=1)] (=1)
    96. enables majority readConcern
    97. Sharding options:
    98. --configsvr declare this is a config db of a
    99. cluster; default port 27019; default
    100. dir /data/configdb
    101. --shardsvr declare this is a shard db of a
    102. cluster; default port 27018
    103. SSL options:
    104. --sslOnNormalPorts use ssl on configured ports
    105. --sslMode arg set the SSL operation mode
    106. (disabled|allowSSL|preferSSL|requireSSL
    107. )
    108. --sslPEMKeyFile arg PEM file for ssl
    109. --sslPEMKeyPassword arg PEM file password
    110. --sslClusterFile arg Key file for internal SSL
    111. authentication
    112. --sslClusterPassword arg Internal authentication key file
    113. password
    114. --sslCAFile arg Certificate Authority file for SSL
    115. --sslCRLFile arg Certificate Revocation List file for
    116. SSL
    117. --sslDisabledProtocols arg Comma separated list of TLS protocols
    118. to disable [TLS1_0,TLS1_1,TLS1_2]
    119. --sslWeakCertificateValidation allow client to connect without
    120. presenting a certificate
    121. --sslAllowConnectionsWithoutCertificates
    122. allow client to connect without
    123. presenting a certificate
    124. --sslAllowInvalidHostnames Allow server certificates to provide
    125. non-matching hostnames
    126. --sslAllowInvalidCertificates allow connections to servers with
    127. invalid certificates
    128. --sslFIPSMode activate FIPS 140-2 mode at startup
    129. Storage options:
    130. --storageEngine arg what storage engine to use - defaults
    131. to wiredTiger if no data files present
    132. --dbpath arg directory for datafiles - defaults to
    133. /data/db
    134. --directoryperdb each database will be stored in a
    135. separate directory
    136. --noprealloc disable data file preallocation - will
    137. often hurt performance
    138. --nssize arg (=16) .ns file size (in MB) for new databases
    139. --quota limits each database to a certain
    140. number of files (8 default)
    141. --quotaFiles arg number of files allowed per db, implies
    142. --quota
    143. --smallfiles use a smaller default file size
    144. --syncdelay arg (=60) seconds between disk syncs (0=never,
    145. but not recommended)
    146. --upgrade upgrade db if needed
    147. --repair run repair on all dbs
    148. --repairpath arg root directory for repair files -
    149. defaults to dbpath
    150. --journal enable journaling
    151. --nojournal disable journaling (journaling is on by
    152. default for 64 bit)
    153. --journalOptions arg journal diagnostic options
    154. --journalCommitInterval arg how often to group/batch commit (ms)
    155. WiredTiger options:
    156. --wiredTigerCacheSizeGB arg maximum amount of memory to allocate
    157. for cache; defaults to 1/2 of physical
    158. RAM
    159. --wiredTigerJournalCompressor arg (=snappy)
    160. use a compressor for log records
    161. [none|snappy|zlib]
    162. --wiredTigerDirectoryForIndexes Put indexes and data in different
    163. directories
    164. --wiredTigerCollectionBlockCompressor arg (=snappy)
    165. block compression algorithm for
    166. collection data [none|snappy|zlib]
    167. --wiredTigerIndexPrefixCompression arg (=1)
    168. use prefix compression on row-store
    169. leaf pages

     学会使用./mongod --help 查看选项。

    1. 参数介绍:
    2. dbpath 数据存储路径
    3. logpath 日志存储路径 指向到一个文件
    4. fork 后台启动
    5. auth 权限开启
    6. bind_ip 指定绑定网卡ip

    fork是后台启动。这个要记住的。

    目录不在不会创建,文件不在是需要创建的。

    配置下环境变量:

    vim /etc/profile

    然后再source /etc/profile操作下。

    命令行客户端操作:

    ./mongo

    1. [root@server10 bin]# ./mongo
    2. MongoDB shell version v3.6.5
    3. connecting to: mongodb://127.0.0.1:27017
    4. MongoDB server version: 3.6.5
    5. Welcome to the MongoDB shell.
    6. For interactive help, type "help".
    7. For more comprehensive documentation, see
    8. http://docs.mongodb.org/
    9. Questions? Try the support group
    10. http://groups.google.com/group/mongodb-user
    11. Server has startup warnings:
    12. 2023-09-16T20:07:07.975+0800 I CONTROL [initandlisten]
    13. 2023-09-16T20:07:07.975+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
    14. 2023-09-16T20:07:07.975+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
    15. 2023-09-16T20:07:07.975+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
    16. 2023-09-16T20:07:07.975+0800 I CONTROL [initandlisten]
    17. 2023-09-16T20:07:07.975+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
    18. 2023-09-16T20:07:07.975+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
    19. 2023-09-16T20:07:07.975+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip
      to specify which IP
    20. 2023-09-16T20:07:07.975+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
    21. 2023-09-16T20:07:07.975+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
    22. 2023-09-16T20:07:07.975+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
    23. 2023-09-16T20:07:07.975+0800 I CONTROL [initandlisten]
    24. 2023-09-16T20:07:07.975+0800 I CONTROL [initandlisten]
    25. 2023-09-16T20:07:07.975+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
    26. 2023-09-16T20:07:07.975+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
    27. 2023-09-16T20:07:07.975+0800 I CONTROL [initandlisten]
    28. 2023-09-16T20:07:07.975+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
    29. 2023-09-16T20:07:07.975+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
    30. 2023-09-16T20:07:07.975+0800 I CONTROL [initandlisten]
    31. >

    输入help检查相关信息。 

  • 相关阅读:
    数字IC笔试千题解--单选题篇(二)
    【数据链路层】封装成帧和透明传输和差错控制
    软件测试为什么外包更好?权威软件测试外包公司应该具备的资质
    【iOS】UI学习——cell的复用及自定义cell
    c++builder 6.0中OnCliked= fun实现的原理
    emq Neuron工业协议采集使用
    MFC 绘图
    【洛谷】P2082 区间覆盖(加强版)
    Linux进程概念
    竞赛 机器视觉人体跌倒检测系统 - opencv python
  • 原文地址:https://blog.csdn.net/chang_chunhua/article/details/132921028