千家信息网

生产上安装mongodb全过程

发表于:2024-12-12 作者:千家信息网编辑
千家信息网最后更新 2024年12月12日,mongodb-linux-x86_64-4.0.2.tgz生产上安装mongodb操作系统为 centos6.5第一步 执行优化脚本 初始化脚本第二步:上传mongodb的二进制安装包[root@p
千家信息网最后更新 2024年12月12日生产上安装mongodb全过程

mongodb-linux-x86_64-4.0.2.tgz
生产上安装mongodb
操作系统为 centos6.5

第一步 执行优化脚本 初始化脚本

第二步:上传mongodb的二进制安装包

[root@prd3-mongodb-10-182 opt]# lltotal 69368-rw-r--r--  1 root root 71023715 Aug 28  2018 mongodb-linux-x86_64-4.0.2.tgzdrwxr-xr-x. 2 root root     4096 Nov 22  2013 rhdrwxr-xr-x  2 root root     4096 Apr 25  2019 scripts[root@prd3-mongodb-10-182 opt]# tar zxvf mongodb-linux-x86_64-4.0.2.tgz -C /usr/local/[root@prd3-mongodb-10-182 local]# mv mongodb-linux-x86_64-4.0.2/ mongodb
第三步验证是否安装成功[root@prd3-mongodb-10-182 local]# /usr/local/mongodb/bin/mongod --versiondb version v4.0.2git version: fc1573ba18aee42f97a3bb13b67af7d837826b47allocator: tcmallocmodules: nonebuild environment:    distarch: x86_64    target_arch: x86_64
第五步设置变量环境[root@prd3-mongodb-10-182 local]# echo 'export PATH=/usr/local/mongodb/bin:$PATH' >> /etc/profile[root@prd3-mongodb-10-182 local]# source /etc/profile
第六步 创建相关的目录[root@prd3-mongodb-10-182 local]# mkdir /ivargo[root@prd3-mongodb-10-182 local]# cd /ivargo/[root@prd3-mongodb-10-182 ivargo]# mkdir app data log [root@prd3-mongodb-10-182 ivargo]# lltotal 12drwxr-xr-x 2 root root 4096 Apr 25 15:31 appdrwxr-xr-x 2 root root 4096 Apr 25 15:31 datadrwxr-xr-x 2 root root 4096 Apr 25 15:31 log[root@prd3-mongodb-10-182 ivargo]# mkdir -p /ivargo/app/mongodb/conf[root@prd3-mongodb-10-182 data]# pwd/ivargo/data[root@prd3-mongodb-10-182 data]# mkdir mdb 
第七步 上传配置文件[root@prd3-mongodb-10-182 conf]# pwd/ivargo/app/mongodb/conf[root@prd3-mongodb-10-182 conf]# lltotal 4-rw-r--r-- 1 root root 853 Nov 15 16:36 mongo.conf
第八步:启动mongodb[root@prd3-mongodb-10-182 conf]# mongod -f /ivargo/app/mongodb/conf/mongo.conf about to fork child process, waiting until server is ready for connections.forked process: 1741child process started successfully, parent exiting[root@prd3-mongodb-10-182 conf]# netstat -lntupActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1515/sshd           tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1591/master         tcp        0      0 0.0.0.0:27017               0.0.0.0:*                   LISTEN      1741/mongod         tcp        0      0 :::22                       :::*                        LISTEN      1515/sshd           tcp        0      0 ::1:25                      :::*                        LISTEN      1591/master  [root@prd3-mongodb-10-182 conf]# ps -ef|grep mongoroot       1741      1  1 15:38 ?        00:00:01 mongod -f /ivargo/app/mongodb/conf/mongo.confroot       1788   1767  0 15:39 pts/1    00:00:00 tailf /ivargo/log/mongod.logroot       1792   1661  0 15:40 pts/0    00:00:00 grep --color=auto mongo
第九步:查看日志进行验证优化[root@prd3-mongodb-10-182 ~]# tailf /ivargo/log/mongod.log   2019-04-25T15:38:47.238+0800 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 14735 processes, 65535 files. Number of processes should be at least 32767.5 : 0.5 times number of files.2019-04-25T15:38:47.239+0800 I STORAGE  [initandlisten] createCollection: admin.system.version with provided UUID: 3a1c2d18-feb1-43cb-b528-f082893aeebe2019-04-25T15:38:47.243+0800 I COMMAND  [initandlisten] setting featureCompatibilityVersion to 4.02019-04-25T15:38:47.245+0800 I STORAGE  [initandlisten] createCollection: local.startup_log with generated UUID: 5dc96bfe-8c7e-4c51-be83-79b28f4be7ba2019-04-25T15:38:47.267+0800 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/ivargo/data/mdb/diagnostic.data'2019-04-25T15:38:47.268+0800 I NETWORK  [initandlisten] waiting for connections on port 270172019-04-25T15:38:47.268+0800 I STORAGE  [LogicalSessionCacheRefresh] createCollection: config.system.sessions with generated UUID: 8c578d12-96d1-4c84-b47b-86c5941c5e342019-04-25T15:38:47.293+0800 I INDEX    [LogicalSessionCacheRefresh] build index on: config.system.sessions properties: { v: 2, key: { lastUse: 1 }, name: "lsidTTLIndex", ns: "config.system.sessions", expireAfterSeconds: 1800 }2019-04-25T15:38:47.293+0800 I INDEX    [LogicalSessionCacheRefresh]     building index using bulk method; build may temporarily use up to 500 megabytes of RAM2019-04-25T15:38:47.293+0800 I INDEX    [LogicalSessionCacheRefresh] build index done.  scanned 0 total records. 0 secs
温柔的关闭mongodb[root@prd3-mongodb-10-182 conf]# mongo 127.0.0.1:27017   //先进入MongoDB shell version v4.0.2connecting to: mongodb://127.0.0.1:27017/testMongoDB server version: 4.0.2Welcome to the MongoDB shell.For interactive help, type "help".For more comprehensive documentation, see        http://docs.mongodb.org/Questions? Try the support group        http://groups.google.com/group/mongodb-userServer has startup warnings: 2019-04-25T15:38:46.567+0800 I STORAGE  [initandlisten] 2019-04-25T15:38:46.567+0800 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine2019-04-25T15:38:46.567+0800 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem2019-04-25T15:38:46.567+0800 I STORAGE  [initandlisten] 2019-04-25T15:38:46.567+0800 I STORAGE  [initandlisten] ** WARNING: The configured WiredTiger cache size is more than 80% of available RAM.2019-04-25T15:38:46.567+0800 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/faq-memory-diagnostics-wt2019-04-25T15:38:47.238+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.2019-04-25T15:38:47.238+0800 I CONTROL  [initandlisten] 2019-04-25T15:38:47.238+0800 I CONTROL  [initandlisten] 2019-04-25T15:38:47.238+0800 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 14735 processes, 65535 files. Number of processes should be at least 32767.5 : 0.5 times number of files.> use adminswitched to db admin> db.shutdownServer()server should be down...//mongo客户端提供一个正确关闭mongodb服务器的方法use admindb.shutdownServer()

优化

在/etc/security/limits.conf 添加如下[root@mongodb-01-85-50 ivargo]# vim /etc/security/limits.conf* soft nofile 65535* hard nofile 65535ulimit -n 65535ulimit -u 65535mongod soft nofile 64000mongod hard nofile 64000mongod soft nproc 32000mongod hard nproc 32000
[root@prd3-mongodb-10-182 ~]# cat /etc/security/limits.d/90-nproc.conf   # Default limit for number of user's processes to prevent# accidental fork bombs.# See rhbz #432903 for reasoning.*          soft    nproc     1024 改成 65535root       soft    nproc     unlimited
[root@prd3-mongodb-10-182 ~]# ulimit  -acore file size          (blocks, -c) 0data seg size           (kbytes, -d) unlimitedscheduling priority             (-e) 0file size               (blocks, -f) unlimitedpending signals                 (-i) 14735max locked memory       (kbytes, -l) 64max memory size         (kbytes, -m) unlimitedopen files                      (-n) 65535pipe size            (512 bytes, -p) 8POSIX message queues     (bytes, -q) 819200real-time priority              (-r) 0stack size              (kbytes, -s) 10240cpu time               (seconds, -t) unlimitedmax user processes              (-u) 14735virtual memory          (kbytes, -v) unlimitedfile locks                      (-x) unlimited我们需要修改的2个参数为pending signals 和 max user processes最后,我们在/etc/profile下执行ulimit -u 65535ulimit -i 65535ok报警解除** WARNING: You are running this process as the root user, which is not recommended.//警告:您以root用户身份运行此进程,不建议使用此进程。 我们忽略
0