`
sillycat
  • 浏览: 2550705 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

MongoDB 2019(1)Install 4.2.1 Single and Cluster

 
阅读更多
MongoDB 2019(1)

Follow this https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat-tarball/
Prepare the package for mongodb
> sudo yum install libcurl openssl

Select Version 4.2.1 current release version, OS RHEL 7.0 Linux 64-bit x64 for my CentOS7, Package TGZ
> wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.1.tgz

> tar -zxvf mongodb-linux-x86_64-rhel70-4.2.1.tgz
> mv mongodb-linux-x86_64-rhel70-4.2.1 ~/tool/mongodb-4.2.1

Prepare the directory and add to PATH
> sudo ln -s /home/carl/tool/mongodb-4.2.1 /opt/mongodb-4.2.1
> sudo ln -s /opt/mongodb-4.2.1 /opt/mongodb

> vi ~/.bash_profile
PATH=$PATH:/opt/mongodb/bin
> . ~/.bash_profile

Check version
> mongod -version
db version v4.2.1
git version: edf6d45851c0b9ee15548f0f847df141764a317e
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
    distmod: rhel70
    distarch: x86_64
    target_arch: x86_64

Follow the document, it should use
/var/lib/mongo —> Data Directory
/var/log/mongodb —> Log Directory
> sudo mkdir -p /var/lib/mongo
> sudo mkdir -p /var/log/mongodb

Add User mongod
> sudo adduser mongod
Set Up password
> sudo passwd mongod
> sudo usermod -aG wheel mongod

Set Up the permission for the directories
> sudo chown -R mongod:mongod /var/lib/mongo
> sudo chown -R mongod:mongod /var/log/mongodb

Try to start it
> cd /opt/mongodb
> mkdir conf
> cat conf/mongodb.conf
bind_ip=0.0.0.0
port=27017

It failed to start with command
> mongod -f conf/mongodb.conf
Data directory /data/db not found
Check the Configuration and prepare the directories
> cat conf/mongodb.conf
fork=true
bind_ip=0.0.0.0
port=27017
quiet=true
dbpath=/data/db/mongodb
logpath=/var/log/mongodb/mongod.log
logappend=true
journal=true

> sudo mkdir -p /data/db/mongodb
> sudo mkdir -p /var/log/mongodb

> sudo chown -R mongod:mongod /data/db/mongodb
> sudo chown -R mongod:mongod /var/log/mongodb

> sudo touch /var/log/mongodb/mongod.log
> sudo chown -R mongod:mongod /var/log/mongodb/mongod.log

I am using user carl, so change all these command to user carl. It works.
> mongod -f conf/mongodb.conf

Check the process
> ps -ef | grep mongo

Try to connect
> mongo -host 127.0.0.1 -port 27017

Some warnings, I may deal with them later
2019-11-10T10:07:27.754-0600 I  CONTROL  [initandlisten]
2019-11-10T10:07:27.754-0600 I  CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-11-10T10:07:27.754-0600 I  CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-11-10T10:07:27.754-0600 I  CONTROL  [initandlisten]
2019-11-10T10:07:27.755-0600 I  CONTROL  [initandlisten]
2019-11-10T10:07:27.755-0600 I  CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-11-10T10:07:27.755-0600 I  CONTROL  [initandlisten] **        We suggest setting it to 'never'
2019-11-10T10:07:27.755-0600 I  CONTROL  [initandlisten]
2019-11-10T10:07:27.755-0600 I  CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2019-11-10T10:07:27.755-0600 I  CONTROL  [initandlisten] **        We suggest setting it to 'never'
2019-11-10T10:07:27.755-0600 I  CONTROL  [initandlisten]
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).
The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.
To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---

Test the current things
> db.test.save({a:1,b:2})
WriteResult({ "nInserted" : 1 })
> db.test.find()
{ "_id" : ObjectId("5dc836add99ae664c7d5bf69"), "a" : 1, "b" : 2 }
> exit
bye

Let me try to do another new installation on rancher-master
> sudo yum install libcurl openssl
> wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.1.tgz
> tar zxvf mongodb-linux-x86_64-rhel70-4.2.1.tgz
> mv mongodb-linux-x86_64-rhel70-4.2.1 ~/tool/mongodb-4.2.1
Prepare the directory and add to PATH
> sudo ln -s /home/carl/tool/mongodb-4.2.1 /opt/mongodb-4.2.1
> sudo ln -s /opt/mongodb-4.2.1 /opt/mongodb

> vi ~/.bash_profile
PATH=$PATH:/opt/mongodb/bin
> . ~/.bash_profile

Check version
>  mongod -version
db version v4.2.1
git version: edf6d45851c0b9ee15548f0f847df141764a317e
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
    distmod: rhel70
    distarch: x86_64
    target_arch: x86_64

> sudo mkdir -p /data/db/mongodb
> sudo mkdir -p /var/log/mongodb

> sudo chown -R carl:carl /data/db/mongodb
> sudo chown -R carl:carl /var/log/mongodb

> cd /opt/mongodb
> mkdir conf
> cat conf/mongodb.conf
fork=true
bind_ip=0.0.0.0
port=27017
quiet=true
dbpath=/data/db/mongodb
logpath=/var/log/mongodb/mongod.log
logappend=true
journal=true

Start the Service
> mongod -f conf/mongodb.conf

Try to connect
> mongo -host 127.0.0.1 -port 27017

Test the current things
> db.test.save({a:1,b:2})
WriteResult({ "nInserted" : 1 })
> db.test.find()
{ "_id" : ObjectId("5dc836add99ae664c7d5bf69"), "a" : 1, "b" : 2 }
> exit
bye

Do the smilier installation on rancher-worker2

Set Up Replication on 3 Nodes
On all the services
> vi conf/mongodb.conf
replSet=sillycat

Start all the services on 3 nodes
> mongod -f conf/mongodb.conf
> mongod -f conf/mongodb.conf
> mongod -f conf/mongodb.conf

On the master machine, rancher-home, do this as follow:
> mongo -host rancher-home -port 27017

Check status
> rs.status()
> rs.in
> rs.initiate()

sillycat:PRIMARY> rs.conf()
{
"_id" : "sillycat",
"version" : 1,
"protocolVersion" : NumberLong(1),
"writeConcernMajorityJournalDefault" : true,
"members" : [
{
"_id" : 0,
"host" : "rancher-home:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {

},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : -1,
"catchUpTakeoverDelayMillis" : 30000,
"getLastErrorModes" : {

},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("5dc8788113bce2f21790db39")
}
}

Add the worker1 to the Cluster
sillycat:PRIMARY> rs.add("rancher-worker1:27017")
{
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1573419389, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"operationTime" : Timestamp(1573419389, 1)
}

Add the Second Worker to the Cluster
sillycat:PRIMARY> rs.add("rancher-worker2:27017")
{
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1573419409, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"operationTime" : Timestamp(1573419409, 1)
}

We can check the status, I think it runs well.
On the primary
sillycat:PRIMARY> db.users.insert({name:"Carl", age:31})
sillycat:PRIMARY> db.users.find();
{ "_id" : ObjectId("5dc87a3b872719ffb1b50d26"), "name" : "Carl", "age" : 31 }

On the worker machine
> mongo -host rancher-worker1 -port 27017

sillycat:SECONDARY> rs.slaveOk();
sillycat:SECONDARY> db.users.find();
{ "_id" : ObjectId("5dc87a3b872719ffb1b50d26"), "name" : "Carl", "age" : 31 }

We can do some proxy on top of that
2. Configure the HA Proxy in front of Mongo Servers
My mongo servers are running as follow:

rancher-home 27017
rancher-worker1 27017
rancher-worker2 27017

The configuration should be as follow:
listen mongodb_local_cluster 127.0.0.1:27010
       #配置TCP模式
       mode      tcp
       #balance url_param userid
       #balance url_param session_id check_post 64
       #balance hdr(User-Agent)
       #balance hdr(host)
       #balance hdr(Host) use_domain_only
       #balance rdp-cookie
       #balance leastconn
       #balance source  //ip
       #简单的轮询
       balance roundrobin
       #集群节点配置
       server mongo1  127.0.0.1:27017 check inter 5000 rise 2 fall 2
       server mongo2  127.0.0.1:27018 check inter 5000 rise 2 fall 2
       server mongo3  127.0.0.1:27019 check inter 5000 rise 2 fall 2


References:
https://juejin.im/post/5d525b1af265da03b31bc2d5
https://learnku.com/articles/31096
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat-tarball/
https://zeppelin.apache.org/docs/0.8.2/setup/storage/storage.html






分享到:
评论

相关推荐

    Studio_3T_for_MongoDB_v2019.3.0x64.rar

    Studio 3T for MongoDB 2019概述 Studio 3T for MongoDB 2019是一个令人印象深刻的应用程序,它拥有处理数据库任务和进程的功能和工具。 它为您提供了连接到MongoDB服务器和管理其中的数据库所需的所有工具。 它是...

    mongodb-linux-x86_64-rhel70-4.2.1.tgz

    在这个特定的案例中,我们关注的是`mongodb-linux-x86_64-rhel70-4.2.1.tgz`文件,这是为Red Hat Enterprise Linux 7.0(RHEL 7.0)系统定制的64位版本的MongoDB 4.2.1。 MongoDB 4.2.1是MongoDB的一个重要版本,...

    Linux下Mongodb的分布式分片群集shardingcluster配置.pdf

    MongoDB的分布式分片群集(Sharding Cluster)是一种针对大数据量场景的高效扩展解决方案。在MongoDB中,分片(Sharding)是通过将数据分布在多台服务器上来实现水平扩展,以处理海量数据和高并发请求。这种架构通常...

    MongoDB&VS2019.zip

    在VS2019中配置MongoDB,可以让你直接在IDE内进行MongoDB相关的开发工作,而无需手动编译c-driver和c++-driver,这极大地提高了开发效率。 首先,你需要确保已安装了VS2019和MongoDB的相关开发库。VS2019可以通过...

    mongodb-linux-x86_64-rhel70-4.2.1安装包.zip

    mongodb-linux-x86_64-rhel70-4.2.1安装包.zip

    MongoDB and Python Patterns and processes

    ### MongoDB与Python模式及流程详解 #### 一、引言 在当今的数据处理领域,MongoDB作为一种流行的文档导向型数据库,因其灵活性、可扩展性以及高性能而受到广泛欢迎。结合Python这一强大的编程语言,可以实现高效...

    MongoDB and Python

    Python MongoDB 应用开发,构建高效稳定数据库应用系统

    mongodb-win32-x86_64-2012plus-4.2.1-signed.msi

    windows 64 mongo,mongodb-win32-x86_64-2012plus-4.2.1-signed

    Practical MongoDB - Architecting, Developing, and Administering

    根据提供的文件信息,本书《Practical MongoDB - Architecting, Developing, and Administering》由Shakuntala Gupta Edward和Navin Sabharwal合著,旨在为读者提供MongoDB的全面指南,涵盖架构、开发和管理等方面。...

    深入学习MongoDB:Scaling MongoDB && 50 Tips and Tricks for MongoDB Developers

    深入学习MongoDB:Scaling MongoDB && 50 Tips and Tricks for MongoDB Developers深入学习MongoDB中文版Scaling MongoDB英文版50 Tips and Tricks for MongoDB Developers英文版高清完整目录3本打包合集

    window版MongoDB-64位-4.0.1安装包

    2018.8.17号MongoDB官网发布的window free版MongoDB-64位-4.0.1安装包

    JavaScript Applications with Node.js, React, React Native and MongoDB

    JavaScript Applications with Node.js, React, React Native and MongoDB: Design, code, test, deploy and manage in Amazon AWS By 作者: Eric Bush ISBN-10 书号: 0997196661 ISBN-13 书号: 9780997196665 出版...

    mongodb1067错误解决1

    mongod.exe --config E:\ruanjian\MongoDB\mongod.cfg --install ``` 5. **重新启动MongoDB服务**:通过服务管理器或命令行重新启动MongoDB服务。 **注意事项:** - 在修改配置文件之前,请确保对原文件进行...

    mongodb-win32-x86_64-enterprise-windows-64-4.2.1-signed.msi

    mongodb-win32-x86_64-enterprise-windows-64-4.2.1-signed.msi mongodb windows 版本,官网下载的

    MongoDB Services Install

    1. **下载MongoDB安装包**:首先,你需要从MongoDB官网下载适用于你操作系统的安装包。这通常是一个.msi或.zip文件,包含了MongoDB服务器的所有组件。 2. **安装MongoDB**:运行下载的.msi文件,按照安装向导的提示...

Global site tag (gtag.js) - Google Analytics