mongodb-linux-x86_64-4.0.2.tgz
生产上安装mongodb
操作系统为 centos6.5
第一步 执行优化脚本 初始化脚本
第二步:上传mongodb的二进制安装包
[[email protected] opt]# ll
total 69368
-rw-r--r-- 1 root root 71023715 Aug 28 2018 mongodb-linux-x86_64-4.0.2.tgz
drwxr-xr-x. 2 root root 4096 Nov 22 2013 rh
drwxr-xr-x 2 root root 4096 Apr 25 2019 scripts
[[email protected] opt]# tar zxvf mongodb-linux-x86_64-4.0.2.tgz -C /usr/local/
[[email protected] local]# mv mongodb-linux-x86_64-4.0.2/ mongodb
第三步验证是否安装成功
[[email protected] local]# /usr/local/mongodb/bin/mongod --version
db version v4.0.2
git version: fc1573ba18aee42f97a3bb13b67af7d837826b47
allocator: tcmalloc
modules: none
build environment:
distarch: x86_64
target_arch: x86_64
第五步设置变量环境
[[email protected] local]# echo ‘export PATH=/usr/local/mongodb/bin:$PATH‘ >> /etc/profile
[[email protected] local]# source /etc/profile
第六步 创建相关的目录
[[email protected] local]# mkdir /ivargo
[[email protected] local]# cd /ivargo/
[[email protected] ivargo]# mkdir app data log
[[email protected] ivargo]# ll
total 12
drwxr-xr-x 2 root root 4096 Apr 25 15:31 app
drwxr-xr-x 2 root root 4096 Apr 25 15:31 data
drwxr-xr-x 2 root root 4096 Apr 25 15:31 log
[[email protected] ivargo]# mkdir -p /ivargo/app/mongodb/conf
[[email protected] data]# pwd
/ivargo/data
[[email protected] data]# mkdir mdb mongodb //我们发现,线上环境 /ivargo/data/mongodb里面存放的数据是老的配置文件存放的,没有用了,这个可以不创建了
第七步 上传配置文件
[[email protected] conf]# pwd
/ivargo/app/mongodb/conf
[[email protected] conf]# ll
total 4
-rw-r--r-- 1 root root 853 Nov 15 16:36 mongo.conf
第八步:启动mongodb
[[email protected] conf]# mongod -f /ivargo/app/mongodb/conf/mongo.conf
about to fork child process, waiting until server is ready for connections.
forked process: 1741
child process started successfully, parent exiting
[[email protected] conf]# netstat -lntup
Active 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
[[email protected] conf]# ps -ef|grep mongo
root 1741 1 1 15:38 ? 00:00:01 mongod -f /ivargo/app/mongodb/conf/mongo.conf
root 1788 1767 0 15:39 pts/1 00:00:00 tailf /ivargo/log/mongod.log
root 1792 1661 0 15:40 pts/0 00:00:00 grep --color=auto mongo
第九步:查看日志进行验证优化
[[email protected] ~]# 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-f082893aeebe
2019-04-25T15:38:47.243+0800 I COMMAND [initandlisten] setting featureCompatibilityVersion to 4.0
2019-04-25T15:38:47.245+0800 I STORAGE [initandlisten] createCollection: local.startup_log with generated UUID: 5dc96bfe-8c7e-4c51-be83-79b28f4be7ba
2019-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 27017
2019-04-25T15:38:47.268+0800 I STORAGE [LogicalSessionCacheRefresh] createCollection: config.system.sessions with generated UUID: 8c578d12-96d1-4c84-b47b-86c5941c5e34
2019-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 RAM
2019-04-25T15:38:47.293+0800 I INDEX [LogicalSessionCacheRefresh] build index done. scanned 0 total records. 0 secs
温柔的关闭mongodb
[[email protected] conf]# mongo 127.0.0.1:27017 //先进入
MongoDB shell version v4.0.2
connecting to: mongodb://127.0.0.1:27017/test
MongoDB server version: 4.0.2
Welcome 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-user
Server 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 engine
2019-04-25T15:38:46.567+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-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-wt
2019-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 admin
switched to db admin
> db.shutdownServer()
server should be down...
//
mongo客户端提供一个正确关闭mongodb服务器的方法
use admin
db.shutdownServer()
优化
在/etc/security/limits.conf 添加如下
[[email protected] ivargo]# vim /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
ulimit -n 65535
ulimit -u 65535
mongod soft nofile 64000
mongod hard nofile 64000
mongod soft nproc 32000
mongod hard nproc 32000
[[email protected] ~]# 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 改成 65535
root soft nproc unlimited
[[email protected] ~]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 14735
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 65535
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 14735
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
我们需要修改的2个参数为pending signals 和 max user processes
最后,我们在/etc/profile下
执行
ulimit -u 65535
ulimit -i 65535
ok报警解除
** WARNING: You are running this process as the root user, which is not recommended.
//警告:您以root用户身份运行此进程,不建议使用此进程。 我们忽略
原文地址:https://blog.51cto.com/12445535/2385346
时间: 2024-10-21 05:34:43