企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
在CentOS7上源码安装MongoDB 3.6.3.md 环境准备 groupadd mongodb useradd mongodb -g mongodb # 创建用户 passwd mongodb # 设置密码 mkdir -p /data0/mongodb #创建数据存放目录 chown -R mongodb:mongodb /data0/mongodb/ # 修改权限 使用mongodb mkdir /home/mongodb/apps/ #创建MongoDB程序存放目录 curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.6.3.tgz 安装 tar -xf mongodb-linux-x86_64-rhel70-3.6.3.tgz mv mongodb-linux-x86_64-rhel70-3.6.3 /home/mongodb/apps/mongodb-3.6.3 ln -s /home/mongodb/apps/mongodb-3.6.3 /home/mongodb/apps/mongodb mkdir -p /home/mongodb/apps/mongodb/logs/ #创建日志存放目录 为了便于命令启动,需要编辑全局变量PATH vim ~/.bash_profile export PATH=$PATH:/home/mongodb/apps/mongodb/bin source ~/.bash_profile 启动服务 首先查看mongod的帮助信息 [root@snails ~]# pwd /root/mongodb/bin [root@snails ~]# vi /etc/profile.d/mongo.sh [root@snails ~]# source /etc/profile [root@snails ~]# mongod --help 创建服务文件 在mongodb/conf目录下创建配置文件mongodb.conf mkdir /home/mongodb/apps/mongodb/conf cd /home/mongodb/apps/mongodb/conf vim mongodb.conf # mongod.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: /home/mongodb/apps/mongodb/logs/mongodb.log # Where and how to store data. storage: dbPath: /data0/mongodb journal: enabled: true # engine: # mmapv1: # wiredTiger: # how the process runs processManagement: fork: true # fork and run in background pidFilePath: /data0/mongodb/mongodb.pid # location of pidfile #timeZoneInfo: /usr/share/zoneinfo # network interfaces net: port: 27017 bindIp: 0.0.0.0 # Listen to local interface only, comment to listen on all interfaces. #security: #operationProfiling: #replication: #sharding: ## Enterprise-Only Options #auditLog: #snmp: 配置参考链接 启动服务 [root@snails bin]# mongod --dbpath=/data/mongodata --logpath=/data/log/mongolog/mongodb.log --logappend --fork #通过配置文件启动 [root@snails bin]# /home/mongodb/apps/mongodb/bin/mongod -f /home/mongodb/apps/mongodb/conf/mongodb.conf netstat -tnlp | grep mongod tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 18093/mongod 测试 [root@snails bin]# mongo MongoDB shell version: 3.2.7 connecting to: test Server has startup warnings: 2016-07-07T20:38:09.623+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 2016-07-07T20:38:09.624+0800 I CONTROL [initandlisten] 2016-07-07T20:38:09.624+0800 I CONTROL [initandlisten] 2016-07-07T20:38:09.624+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 2016-07-07T20:38:09.624+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2016-07-07T20:38:09.624+0800 I CONTROL [initandlisten] 2016-07-07T20:38:09.624+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2016-07-07T20:38:09.624+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2016-07-07T20:38:09.624+0800 I CONTROL [initandlisten] 2016-07-07T20:38:09.624+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 15084 processes, 65535 files. Number of processes should be at least 32767.5 : 0.5 times number of files. 2016-07-07T20:38:09.624+0800 I CONTROL [initandlisten] > show dbs local 0.000GB > quit() 消除警告 [root@snails bin]# vi /etc/rc.local if test -f /sys/kernel/mm/transparent_hugepage/enabled; then echo never > /sys/kernel/mm/transparent_hugepage/enabled fi if test -f /sys/kernel/mm/transparent_hugepage/defrag; then echo never > /sys/kernel/mm/transparent_hugepage/defrag fi ulimit -u 65535 [root@snails bin]# echo never > /sys/kernel/mm/transparent_hugepage/enabled [root@snails bin]# echo never > /sys/kernel/mm/transparent_hugepage/defrag Tip: 如果发现加入到/etc/rc.local中的内容在重启后没有生效,检查下rc.local的权限及当前系统运行等级 [root@snails ~]# runlevel [root@snails ~]# chmod +x /etc/rc.local 文件限制数调整 修改配置文件 /etc/security/limits.conf,添加配置信息: * soft nofile 65535 * hard nofile 65535 * soft nproc 32000 * hard nproc 32000 停止mongodb 正常停止方法: kill -2 PID >use admin >db.shutdownServer(); 再次验证 [root@snails bin]# mongod -f /root/mongodb/bin/mongodb.conf about to fork child process, waiting until server is ready for connections. forked process: 18229 child process started successfully, parent exiting [root@snails bin]# mongo MongoDB shell version: 3.2.7 connecting to: test Server has startup warnings: 2016-07-07T21:06:53.798+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 2016-07-07T21:06:53.798+0800 I CONTROL [initandlisten] > exit bye 服务化 [root@snails data]# cat > /usr/lib/systemd/system/mongod.service << EOF [Unit] Description=High-performance, schema-free document-oriented database After=network.target Documentation=https://docs.mongodb.org/manual [Service] User=mongo Group=mongo Environment="OPTIONS=-f /home/mongo/apps/mongodb/conf/mongod.conf" ExecStart=/home/mongo/apps/mongodb/bin/mongod $OPTIONS ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb PermissionsStartOnly=true PIDFile=/var/run/mongodb/mongod.pid Type=forking # file size LimitFSIZE=infinity # cpu time LimitCPU=infinity # virtual memory size LimitAS=infinity # open files LimitNOFILE=64000 # processes/threads LimitNPROC=64000 # locked memory LimitMEMLOCK=infinity # total threads (user+kernel) TasksMax=infinity TasksAccounting=false # Recommended limits for for mongod as specified in # http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings [Install] WantedBy=multi-user.target EOF [root@snails data]# systemctl enable systemd-mongodb