mongodb 安装

从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为机械盘

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 ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is ‘always’.
2015-03-19T00:43:27.760+0800 I CONTROL ** 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
http://webprox.redstonesrv.fr/browse.php/qU6OBihY/_2BTWuWx/rLZNRESq/MIu7der5/ISEOTGe5/jncv4QuE/LSbDvehs/W0d3g_3D/b29/

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(/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=truewireTiger引擎配置增加相关参数即可,以副本集为例,如:

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=1YAML 格式配置文件:

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: shardsvrconfiger server
sharding: clusterRole: configsvr参考:
http://www.cnblogs.com/browse.php/qU6OBjJU/826tGhve/bJ9SC7wT/v7cG_2B8/xWQLvQPJ/u3IupC7k/TRcm7Xic/DtI2mMYX/oRXv4UQO/FTlYV5BH/E_3D/b29/

分类: http://www.cnblogs.com/cy163/category/674910.html