博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CentOS 安装 MongoDB
阅读量:5036 次
发布时间:2019-06-12

本文共 7924 字,大约阅读时间需要 26 分钟。

 

从MongoDB3.0版起,其安装包比以前更细化,有的朋友可能不太了解区别,简单说明一下:
Linux 64-bit legacy 这个版本即mongodb-linux-x86_64-3.0.1.tgz 不推荐在正式环境使用,这个版本特点是没有连接ssl相关的库,并且可能缺少针对操作系统的一些性能优化,但是可以测试用,安装简单。推荐按相应操作系统版本选择对应的安装包如centos6 rhel6选择RHEL 6 Linux 64-bit,即mongodb-linux-x86_64-rhel62-3.0.1.tgz这个安装包。

根据服务器的硬盘情况,其中/home为固态盘,/data为固态盘 /storage为机械盘

[root@mail ~]# df -lh

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2       197G  1.6G  186G   1% /
tmpfs            63G     0   63G   0% /dev/shm
/dev/sda1       380M   70M  290M  20% /boot
/dev/sdb1       733G  197M  696G   1% /data
/dev/sda5       410G  235M  389G   1% /home
/dev/sdc1       9.0T   40M  8.5T   1% /storage

安装openssl
#yum install -y openssl-devel openssl
# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.0.1.tgz
# tar xzvf mongodb-linux-x86_64-rhel62-3.0.1.tgz
# mkdir -p /home/local/
# mv mongodb-linux-x86_64-rhel62-3.0.1 /home/local/mongodb
# mkdir -p /data/mongodb
# mkdir -p /data/logs/mongodb
# touch /data/logs/mongodb/mongodb.log
# chmod -R 777 /data/logs/mongodb/mongodb.log
设置ulimit -n和ulimit -u的值大于20000。如果ulimit的值设置过低的话,当MongoDB处于       频繁访问的状态下,将会产生错误,最终导致无法连接到MongoDB实例。
# ulimit -n 25000
# ulimit -u 25000
# cd /home/local/mongodb/bin/
# vi mongodb.conf
port=20000 #端口
dbpath= /data/mongodb #数据文件存放目录
logpath=/data/logs/mongodb/mongodb.log #日志文件存放目录
logappend=true #使用追加的方式写日志
fork=true #以守护程序的方式启用,即在后台运行
maxConns=5000 #最大同时连接数 默认2000
bind_ip=127.0.0.1,172.16.20.126 #只允许通过局域网IP:172.16.20.126及本机访问
noauth=true #不启用验证
nohttpinterface=true
rest=false
设置防火墙,以便局域网内的其它服务器可以访问
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 20000 -j ACCEPT
/etc/init.d/iptables restart

 

如果没有numactl命令,使用yum安装
yum install -y numactl
在proc中关闭NUMA
# echo 0 > /proc/sys/vm/zone_reclaim_mode  
# sysctl -w vm.zone_reclaim_mode=0
启动命令:
# numactl --interleave=all /home/local/mongodb/bin/mongod --config /home/local/mongodb/bin/mongodb.conf
# numactl --interleave=all /home/local/mongodb/bin/mongod -f /home/local/mongodb/bin/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 25071
child process started successfully, parent exiting
正常停止方法:
# ps aux | grep mongod
# kill  -2 PID
# /home/local/mongodb/bin/mongo -port 20000
> use  admin  
> db.shutdownServer();
2015-03-19T00:43:27.760+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2015-03-19T00:43:27.760+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
不重启服务器的情况下解决办法,在Linux下执行:
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
服务器重启后立即生效办法:
# 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
开机自动启动mongodb
# vi /etc/rc.d/rc.local
rm -rf /data/mongodb/mongod.lock
numactl --interleave=all /home/local/mongodb/bin/mongod -f /home/local/mongodb/bin/mongodb.conf
说明:启动时必须加numactl --interleave=all
 
 
二、MongoDB 3.0安装配置faq
 

MongoDB 3.0版本安装介质

MongoDB 3.0版本安装包比以前更细化,有的朋友可能不太了解区别,简单说明一下:
Linux 64-bit legacy 这个版本即mongodb-linux-x86_64-3.0.0.tgz 不推荐在正式环境使用,这个版本特点是没有连接ssl相关的库,并且可能缺少针对操作系统的一些性能优化,但是可以测试用,安装简单。
推荐按相应操作系统版本选择对应的安装包如centos6 rhel6选择RHEL 6 Linux 64-bit,即mongodb-linux-x86_64-rhel62-3.0.0.tgz这个安装包。
有朋友反应安装不上,因为还需要安装相应的依赖库如OpenSSL 相关的库。
如下所示,就是缺少OpenSSL 相关的库

ldd mongodb-linux-x86_64-rhel62-3.0.0/bin/mongodmongodb-linux-x86_64-rhel62-3.0.0/bin/mongod: /usr/lib64/libssl.so.10: no version information available (required by mongodb-linux-x86_64-rhel62-3.0.0/bin/mongod)mongodb-linux-x86_64-rhel62-3.0.0/bin/mongod: /usr/lib64/libcrypto.so.10: no version information available (required by mongodb-linux-x86_64-rhel62-3.0.0/bin/mongod)mongodb-linux-x86_64-rhel62-3.0.0/bin/mongod: /usr/lib64/libcrypto.so.10: no version information available (required by mongodb-linux-x86_64-rhel62-3.0.0/bin/mongod)linux-vdso.so.1 =>  (0x00007ffffd961000)libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003d5b600000)libssl.so.10 => /usr/lib64/libssl.so.10 (0x0000003d62e00000)libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x0000003d60e00000)librt.so.1 => /lib64/librt.so.1 (0x0000003d5be00000)libdl.so.2 => /lib64/libdl.so.2 (0x0000003d5ae00000)libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00000039bc800000)libm.so.6 => /lib64/libm.so.6 (0x0000003d5ba00000)libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003d5ce00000)libc.so.6 => /lib64/libc.so.6 (0x0000003d5b200000)/lib64/ld-linux-x86-64.so.2 (0x0000003d5aa00000)libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x0000003d61a00000)libkrb5.so.3 => /lib64/libkrb5.so.3 (0x0000003d60a00000)libcom_err.so.2 => /lib64/libcom_err.so.2 (0x0000003d5e200000)libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x0000003d60600000)libz.so.1 => /lib64/libz.so.1 (0x0000003d5c200000)libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x0000003d61e00000)libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x0000003d60200000)libresolv.so.2 => /lib64/libresolv.so.2 (0x0000003d5d600000)libselinux.so.1 => /lib64/libselinux.so.1 (0x0000003d5ca00000)

安装好后

[root[@ccj-sf](/user/ccj-sf) export]# ldd /export/mongodb/bin/mongodlinux-vdso.so.1 =>  (0x00007fff8f7ff000)libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f6e0d5a9000)libssl.so.10 => /usr/lib64/libssl.so.10 (0x00007f6e0d33d000)libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007f6e0cf59000)librt.so.1 => /lib64/librt.so.1 (0x00007f6e0cd51000)libdl.so.2 => /lib64/libdl.so.2 (0x00007f6e0cb4d000)libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007f6e0c846000)libm.so.6 => /lib64/libm.so.6 (0x00007f6e0c5c2000)libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f6e0c3ac000)libc.so.6 => /lib64/libc.so.6 (0x00007f6e0c017000)/lib64/ld-linux-x86-64.so.2 (0x00007f6e0d7cf000)libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f6e0bdd3000)libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f6e0baed000)libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f6e0b8e8000)libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f6e0b6bc000)libz.so.1 => /lib64/libz.so.1 (0x00007f6e0b4a6000)libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f6e0b29a000)libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f6e0b097000)libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f6e0ae7d000)libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f6e0ac5d000)

配置文件

mmapv1引擎,配置文件与2.x版本完全相同。如:

# cat mongod.cnf dbpath=/export/data/mongodb30/mongodlogpath=/export/data/mongodb30/log/mongod.logpidfilepath=/export/data/mongodb30/pid/mongod.piddirectoryperdb=truereplSet=a3logappend=truekeyFile=/export/data/mongodb30/keyport=20000fork=true

wireTiger引擎配置增加相关参数即可,以副本集为例,如:

# cat mongod.cnf dbpath=/export/data/mongodb30/mongodlogpath=/export/data/mongodb30/log/mongod.logpidfilepath=/export/data/mongodb30/pid/mongod.piddirectoryperdb=truereplSet=a3logappend=truekeyFile=/export/data/mongodb30/keyport=20000fork=truestorageEngine=wiredTigerwiredTigerCacheSizeGB=10wiredTigerStatisticsLogDelaySecs=0wiredTigerJournalCompressor=snappywiredTigerDirectoryForIndexes=truewiredTigerCollectionBlockCompressor=snappywiredTigerIndexPrefixCompression=1

YAML 格式配置文件:

2.6版本就引入,以上面副本集为例:

$ cat mongodb.cnf systemLog: destination: file path: /export/data/mongodb30/log/mongod.log logAppend: truestorage: journal:  enabled: true dbPath: /export/data/mongodb30/mongod directoryPerDB: true engine: wiredTiger wiredTiger:  engineConfig:   cacheSizeGB: 10   directoryForIndexes: true  collectionConfig:   blockCompressor: snappy  indexConfig:   prefixCompression: truenet: port: 20000replication: replSetName: a3 security: keyFile: /export/data/mongodb30/keyprocessManagement: pidFilePath: /export/data/mongodb30/pid/mongod.pid fork: true setParameter:   enableLocalhostAuthBypass: false

单机去掉replication及keyfile设置即可,分片增加一些参数,如:

mongod增加

sharding: clusterRole: shardsvr

configer server

sharding: clusterRole: configsvr

参考:

转载于:https://www.cnblogs.com/cy163/p/4439418.html

你可能感兴趣的文章
20162312 第十周学习总结
查看>>
POJ 3691 TRIE图+DP
查看>>
ES6初体验——(1)let和const命令
查看>>
for循环与forEach性能思考
查看>>
sys模块的初步认识
查看>>
多核cpu电脑运行多线程程序的问题
查看>>
创建带输入参数的存储过程
查看>>
正则 re
查看>>
线性规划与单纯形法学习笔记
查看>>
设计模式之-模版方法(Template Method Design Pattern)
查看>>
HTTPS Everywhere – 保障隐私和信息安全的利器
查看>>
A380上11万一张的机票什么享受?来看看
查看>>
Wordpress博客写完后段首无法空格怎么办?
查看>>
Ubuntu 下自定义shell
查看>>
sqlserver还原3101
查看>>
协同过滤算法之组合加权评分
查看>>
css3基础
查看>>
Motion Design for iOS
查看>>
成立仅8个月的个人网站,月收入几十万美金,很难做到吗?
查看>>
machine learning
查看>>