一.环境介绍
1.机器信息
10.40.6.68
10.40.6.108
10.40.6.110
软件环境为centos 6.x
2.mongodb 下载链接地址
https://www.mongodb.org/dl/linux/x86_64-rhel62?_ga=2.137326704.1914689897.1499321739-372422474.1499321739
使用二进制文件包安装,版本选择的是mongodb 3.2.15
二.完整步骤
1.下载安装包解压
tar -zxf mongodb-linux-x86_64-rhel62-3.2..tgz -C /usr/local/
mv /usr/local/mongodb-linux-x86_64-rhel62-3.2./ /usr/local/mongodb-3.2
ln -s /usr/local/mongodb-3.2/bin/* /usr/local/bin/
2.创建用户和相关的文件夹
useradd mongodb
mkdir -p /data/mongodb/data/
mkdir -p /data/mongodb/log/ chown -R mongodb:mongodb /data/mongodb/
3.编辑配置文件,mongo的启动可以直接用命令行启动,或者指定配置文件启动
vim /etc/mongodb.conf
systemLog:
destination: file
path: "/data/mongodb/log/mongod.log"
logAppend: true
storage:
dbPath: "/data/mongodb/data/"
directoryPerDB: true
journal:
enabled: true
processManagement:
fork: true
#security:
# authorization: "enabled"
net:
port: 27017
replication:
oplogSizeMB: 50
replSetName: "repl_test"
secondaryIndexPrefetch: "all"
至此,mongo的安装基本完成了。启动mongdb
mongodb -f /etc/mongodb.conf &
常见的3个warning 问题
WARNING: You are running this process as the root user, which is not recommended.
要用mongodb用户启动
su mongodb
mongod -f /etc/mongodb.conf &
WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'
禁用大的内存页
echo never >> /sys/kernel/mm/transparent_hugepage/enabled
echo never >> /sys/kernel/mm/transparent_hugepage/defrag
WARNING: You are running on a NUMA machine.
numactl --interleave=all mongod -f /etc/mongodb.conf &
4.初始化集群
config = { _id:"repl_test", members:[{_id:0,host:"10.40.6.68:27017"},{_id:1,host:"10.40.6.108:27017"},{_id:2,host:"10.40.6.110:27017"}]}
rs.initiate(config);
5.查看集群状态
rs.status();
db.testdb.insert({"test1":"testval1"})
db.getMongo().setSlaveOk();
参考链接地址:http://www.lanceyan.com/tech/mongodb/mongodb_repset1.html
http://www.cnblogs.com/zhoujinyi/p/3554010.html