参考文章:http://www.cnblogs.com/kevingrace/p/5685486.html
下载mongodb并解压

https://www.mongodb.com/download-center/enterprise/releases
tar -zxvf mongodb-linux-x86_64-enterprise-rhel70-3.6.5.tgz

重命名

mv mongodb-linux-x86_64-enterprise-rhel70-3.6.5 mongo1

设置环境变量

echo -e "# append mongodb_env\nexport PATH=$PATH:/software/mongo1/bin" >> /etc/profile

立即生效

source /etc/profile

切换到mongo1目录创建数据存放目录

mkdir data
mkdir logs
touch keyfile
chmod 666 keyfile

进入logs目录创建日志文件

touch m.log

安装net-snmp

yum install net-snmp

启动服务

./mongod --dbpath /software/mongo1/data --logpath /software/mongo1/log/m.log --port 27017 --fork --smallfiles

停止mongo进程

pkill -9 mongo

复制mongo2、mongo3

cp -rf mongo1 mongo2
cp -rf mongo1 mongo3

分别启动三个服务

./mongod --dbpath /software/mongo1/data --logpath /software/mongo1/log/m.log --bind_ip 0.0.0.0 --port 27017 --fork --smallfiles --replSet rs01
./mongod --dbpath /software/mongo2/data --logpath /software/mongo2/log/m.log --bind_ip 0.0.0.0 --port 27018 --fork --smallfiles --replSet rs01
./mongod --dbpath /software/mongo3/data --logpath /software/mongo3/log/m.log --bind_ip 0.0.0.0 --port 27019 --fork --smallfiles --replSet rs01

配置副本集,初始化副本集

#登录任何一台机器
[root@study bin]# ./mongo 10.0.117.129:27017
MongoDB shell version v3.6.5
connecting to: mongodb://10.0.117.129:27017/test
MongoDB server version: 3.6.5
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: 
2018-06-21T13:25:52.561+0800 I CONTROL  [initandlisten] 
2018-06-21T13:25:52.561+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-06-21T13:25:52.561+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2018-06-21T13:25:52.561+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-06-21T13:25:52.561+0800 I CONTROL  [initandlisten] 
2018-06-21T13:25:52.561+0800 I CONTROL  [initandlisten] 
2018-06-21T13:25:52.561+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-06-21T13:25:52.561+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2018-06-21T13:25:52.561+0800 I CONTROL  [initandlisten] 
2018-06-21T13:25:52.561+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-06-21T13:25:52.561+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2018-06-21T13:25:52.561+0800 I CONTROL  [initandlisten] 

切换到admin数据库

MongoDB Enterprise > use admin
switched to db admin
#配置副本集
MongoDB Enterprise > var rsconf={ _id:"rs01", members:[ {"_id" : 0, "host" : "10.0.117.129:27017"}, {"_id" : 1, "host" : "10.0.117.129:27018"}, {"_id" : 2, "host" : "10.0.117.129:27019"} ] }
#初始化副本集
MongoDB Enterprise > rs.initiate(rsconf)
{
    "ok" : 1,
    "operationTime" : Timestamp(1529559644, 1),
    "$clusterTime" : {
        "clusterTime" : Timestamp(1529559644, 1),
        "signature" : {
            "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
            "keyId" : NumberLong(0)
        }
    }
}