MongoDB-linux-x86_64-4.0.2.tgz
生產(chǎn)上安裝mongodb
操作系統(tǒng)為 centos6.5
創(chuàng)新互聯(lián),為您提供成都網(wǎng)站建設(shè)、網(wǎng)站制作公司、網(wǎng)站營(yíng)銷推廣、網(wǎng)站開發(fā)設(shè)計(jì),對(duì)服務(wù)陽(yáng)光房等多個(gè)行業(yè)擁有豐富的網(wǎng)站建設(shè)及推廣經(jīng)驗(yàn)。創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司成立于2013年,提供專業(yè)網(wǎng)站制作報(bào)價(jià)服務(wù),我們深知市場(chǎng)的競(jìng)爭(zhēng)激烈,認(rèn)真對(duì)待每位客戶,為客戶提供賞心悅目的作品。 與客戶共同發(fā)展進(jìn)步,是我們永遠(yuǎn)的責(zé)任!
第一步 執(zhí)行優(yōu)化腳本 初始化腳本
第二步:上傳mongodb的二進(jìn)制安裝包
[root@prd3-mongodb-10-182 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
[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
第三步驗(yàn)證是否安裝成功
[root@prd3-mongodb-10-182 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
第五步設(shè)置變量環(huán)境
[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
第六步 創(chuàng)建相關(guān)的目錄
[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]# 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
[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]# ll
total 4
-rw-r--r-- 1 root root 853 Nov 15 16:36 mongo.conf
第八步:?jiǎn)?dòng)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: 1741
child process started successfully, parent exiting
[root@prd3-mongodb-10-182 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
[root@prd3-mongodb-10-182 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
第九步:查看日志進(jìn)行驗(yàn)證優(yōu)化
[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-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
溫柔的關(guān)閉mongodb
[root@prd3-mongodb-10-182 conf]# mongo 127.0.0.1:27017 //先進(jìn)入
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客戶端提供一個(gè)正確關(guān)閉mongodb服務(wù)器的方法
use admin
db.shutdownServer()
優(yōu)化
在/etc/security/limits.conf 添加如下
[root@mongodb-01-85-50 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
[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 改成 65535
root soft nproc unlimited
[root@prd3-mongodb-10-182 ~]# 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個(gè)參數(shù)為pending signals 和 max user processes
最后,我們?cè)?etc/profile下
執(zhí)行
ulimit -u 65535
ulimit -i 65535
ok報(bào)警解除
** WARNING: You are running this process as the root user, which is not recommended.
//警告:您以root用戶身份運(yùn)行此進(jìn)程,不建議使用此進(jìn)程。 我們忽略