[关闭]
@JunQiu 2018-09-18T11:20:33.000000Z 字数 4025 阅读 1090

mongo_proprofilter,slowQuery、docker_挂载、127.0.0.1/0.0.0.0、netstat,lsof(-i)

summary_2018/07 mongodb docker net linux


1、日常工作

1.1、mongodb分析器:profiler,慢查询
1.2、docker挂载本地目录/文件实现文件共享
1.3、127.0.0.1/0.0.0.0及http服务中的区别

2、技术学习

2.1、mongodb分析器:profilter
  1. ## profiling Levels
  2. Level Description
  3. 0 The profiler is off and does not collect any data. This is the default profiler level.
  4. 1 The profiler collects data for operations that take longer than the value of slowms.(仅记录慢查询)
  5. 2 The profiler collects data for all operations.
  6. ## set Level
  7. // Set the value of slowms using the profile command or db.setProfilingLevel() shell helper method.
  8. db.setProfilingLevel(level)
  9. // Set the value of --slowms from the command line at startup.
  10. // Set the value of slowOpThresholdMs in a configuration file.
  11. ## For development purposes in testing environments, you can enable database profiling for an entire mongod instance.
  12. mongod --profile 1 --slowms 15 --slowOpSampleRate 0.5
  13. ## get Level
  14. // db.getProfilingStatus()
  15. // db.getProfilingLevel()
  16. ## View Profiler Data:query system.profile collection
  17. ## Profiler Overhead(花销)
  18. When enabled, profiling has a minor effect on performance. The system.profile collection is a capped collection with a default size of 1 megabyte.(capped 有操作限制,但效率更高)
  19. ## Change Size of system.profile Collection
  20. // on the Primary 主节点
  21. Disable profiling.
  22. Drop the system.profile collection.
  23. Create a new system.profile collection.
  24. Re-enable profiling.
  25. Example
  26. db.setProfilingLevel(0)
  27. db.system.profile.drop()
  28. db.createCollection( "system.profile", { capped: true, size:4000000 } )
  29. db.setProfilingLevel(1)
  30. // on a Secondary 子节点
  31. you must stop the secondary, run it as a standalone, and then perform the steps above. When done, restart the standalone as a member of the replica set.
  32. 关闭子节点->独立运行->运行上面的操作->作为子节点加上去
  33. // Example
  34. db.system.profile.find( {} ).limit(1).pretty()
  35. {
  36. "op" : "command", # 操作类型
  37. "ns" : "test.col", # 集合
  38. "command" : {
  39. "collStats" : "col",
  40. "scale" : 1,
  41. "$db" : "test",
  42. "lsid" : {
  43. "id" : UUID("d2634aa9-f9d0-420b-9587-bef043d83960")
  44. },
  45. "$readPreference" : {
  46. "mode" : "primaryPreferred"
  47. }
  48. },
  49. "numYield" : 0,
  50. "locks" : { # 锁的类型
  51. "Global" : {
  52. "acquireCount" : {
  53. "r" : NumberLong(2)
  54. }
  55. },
  56. "Database" : {
  57. "acquireCount" : {
  58. "r" : NumberLong(1)
  59. }
  60. },
  61. "Collection" : {
  62. "acquireCount" : {
  63. "r" : NumberLong(1)
  64. }
  65. }
  66. },
  67. "responseLength" : 13813,
  68. "protocol" : "op_msg",
  69. "millis" : 1,
  70. "ts" : ISODate("2018-07-25T03:25:58.781Z"),
  71. "client" : "127.0.0.1",
  72. "allUsers" : [ ],
  73. "user" : ""
  74. }
  75. # 一些比较重要的字段
  76. nscannedThe number of index keys that MongoDB scanned in order to carry out the operation.,3.2以前叫keysExamined
  77. //一般来说,如果远远高于nreturned,则数据库会扫描许多索引键以查找结果文档。考虑创建或调整索引以提高查询性能。
  78. docsExaminedThe number of documents in the collection that MongoDB scanned in order to carry out the operation.
  79. fromMultiPlannerA boolean that indicates whether the query planner evaluated multiple plans before choosing the winning execution plan for the query.
  80. locks:锁的类型,锁花费的时间
  81. nreturnedThe number of documents returned by the operation.(如果远大于扫描的数量,可以考虑加索引)
  82. responseLengthThe length in bytes of the operations result document. A large responseLength can affect performance. (大小过大可以考虑,减少字段,或者limit(),batchSize())
  83. millis:所花费的时间(毫秒)
  84. ts:操作的时间戳
2.2、docker挂载本地目录/目录实现文件共享
  1. Example:挂载/test目录到容器的/soft目录
  2. docker run -v /test:/soft
  3. Tips:
  4. 1、容器目录不可以为相对路径
  5. 2、宿主机目录如果不存在,则会自动生成
  6. 3、如果宿主主机为相对目录,则会在/var/lib/docker/volumes/下(可以使用docker inspect查看image内的"Mounts"部分)
2.3、127.0.0.1/0.0.0.0及http服务中的区别
  1. ### 在计算机网络中,按照IP地址分类标准:
  2. 一些特殊IP地址:
  3. // 127.0.0.1 回环地址,一般本地域名localhsot
  4. // 0.0.0.0 网络号和主机号都全部为0,表示“本网络上的本主机”,只能用作源地址(在路由中,0.0.0.0表示的是默认路由)
  5. // 255.255.255.255 广播地址,用于本网络的广播(同一个广播域)
  6. Tips:{127,}:即网络号为127的任意ip地址。都是内部主机回环地址(loopback),永远都不能出现在主机外部的网络中。(mac只保留了127.0.01作环回地址)
  7. ### 在服务器中listen
  8. // 0.0.0.0 指的是本机上的所有IPV4地址,如果一个主机有两个IP地址,都会监听
  9. // 127.0.0.1 一个环回地址。注意并不表示“本机”,用作测试(相当于仅监听了这张虚拟网卡(loopback)的地址:127.0.0.1)(而且可以监听0.0.0.0????,应该是被回送到了127.0.0.1)
  10. ### 检测端口占用情况
  11. // netstat用来查看系统当前系统网络状态信息,包括端口,连接情况等
  12. -t : 指明显示TCP端口
  13. -u : 指明显示UDP端口
  14. -l : 仅显示监听套接字(LISTEN状态的套接字)
  15. -p : 显示进程标识符和程序名称,每一个套接字/端口都属于一个程序
  16. -n : 不进行DNS解析
  17. -a 显示所有连接的端口
  18. Tips:可以结合grep使用netstat -tunlp | grep 22
  19. // lsof的作用是列出当前系统打开文件(list open files),不过通过-i参数也能查看端口的连接情况
  20. lsof -i:22(不推荐,只能查看部分)

虚拟网卡loopback:

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注