Skip to content

Commit 53026c4

Browse files
committed
folder import
1 parent b50701a commit 53026c4

File tree

3 files changed

+174
-0
lines changed

3 files changed

+174
-0
lines changed

01_install/README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## INSTALL
2+
3+
**Import the public key used by the package management system**
4+
5+
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
6+
7+
**Create a list file for MongoDB**
8+
9+
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
10+
11+
**Reload local package database**
12+
13+
sudo apt-get update
14+
15+
**Install the MongoDB packages**
16+
17+
sudo apt-get install -y mongodb-org
18+
19+
## RUN
20+
21+
**START / STOP / RELOAD MONGODB**
22+
23+
service mongod start
24+
service mongod stop
25+
service mongod restart
26+
27+

02_replicaset/README.md

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Deploy Replica Set
2+
3+
A replica set in **MongoDB** is a group of mongod processes that maintain the same data set. Replica sets provide redundancy and high availability, and are the basis for all production deployments. This section provides tutorials for common tasks related to replica sets.
4+
5+
## Requirements
6+
7+
Before you can deploy a replica set, you must install MongoDB on each system that will be part of your replica set (we meed at least 3 instances). If you have not already installed MongoDB, see the [installation tutorials](https://docs.mongodb.org/manual/installation/#tutorial-installation "Installation").
8+
9+
All members of a replica set must be able to connect to every other member of the set to support replication. Always verify connections in both “directions.” Networking topologies and firewall configurations can prevent normal and required connectivity, which can block replication.
10+
11+
To configure the network bind edit the mongo config file (/etc/mongod.conf under Unix systems):
12+
13+
# network interfaces
14+
net:
15+
port: 27017
16+
bindIp: PRIVATE-IP
17+
18+
Be sure to setup internal DNS name to reach all the different nodes from one virtual machine to an other. You can simply modify the **/etc/hosts** file and add your DNS resolution, for example:
19+
20+
192.168.0.1 mongo1.alexcomu
21+
192.168.0.2 mongo2.alexcomu
22+
192.168.0.3 mongo3.alexcomu
23+
24+
So, to check the bidirectional test of networking try from **mongo1**:
25+
26+
`mongo --host mongo2.alexcomu --port 27017`
27+
`mongo --host mongo3.alexcomu --port 27017`
28+
29+
From **mongo2**:
30+
31+
`mongo --host mongo1.alexcomu --port 27017`
32+
`mongo --host mongo3.alexcomu --port 27017`
33+
34+
From **mongo3**:
35+
36+
`mongo --host mongo1.alexcomu --port 27017`
37+
`mongo --host mongo2.alexcomu --port 27017`
38+
39+
If any connection, in any direction fails, check your networking and firewall configuration and reconfigure your environment to allow these connections.
40+
41+
## Configuration Procedure
42+
43+
The following procedure outlines the steps to deploy a replica set when access control is disabled.
44+
45+
### 1 - Start each member of the replica set with appropriate options
46+
47+
For each member, start a **mongod** and specify the replica set option (**replSet**). If the application connects to more than one replica set, each set should have a dinstict name. In our case we'll use the same replica set name, for instance:
48+
49+
mongod --replSet "rs0"
50+
51+
We can also specify the replica set name in the configuration file (be careful, YAML syntax does not support indentation, use space!):
52+
53+
replication:
54+
oplogSizeMB: <int>
55+
replSetName: <string>
56+
secondaryIndexPrefetch: <string>
57+
enableMajorityReadConcern: <boolean>
58+
59+
### 2 - Connect a mongo shell to a replica set member
60+
61+
Connect your shell to Mongo:
62+
63+
mongo --host 192.168.0.1 --port 27017
64+
65+
### 3 - Initiate the replica set
66+
67+
On one and one only member of the replica set, use **rs.initiate()** to initiates a set that consists of the current member and that uses the default replica set configuration.
68+
69+
rs.initiate()
70+
71+
### 4 - Verify the initial replica set configuration
72+
73+
Use **rs.status** to display the replica set configuration object:
74+
75+
rs.status()
76+
77+
The replica set configuration object will looks like:
78+
79+
rs1:PRIMARY> rs.conf()
80+
{
81+
_id" : "rs1",
82+
"version" : 1,
83+
"protocolVersion" : NumberLong(1),
84+
"members" : [
85+
{
86+
"_id" : 0,
87+
"host" : "192.168.0.1:27017",
88+
"arbiterOnly" : false,
89+
"buildIndexes" : true,
90+
"hidden" : false,
91+
"priority" : 1,
92+
"tags" : {
93+
},
94+
"slaveDelay" : NumberLong(0),
95+
"votes" : 1
96+
}
97+
]
98+
}
99+
100+
### 5 - Add the remaining members to the replica set.
101+
102+
We have to add the remaining members to our replica set using **rs.add()**. You must be connected to the **primary** member to add the others, in our case is **mongo1.alexcomu** instance.
103+
104+
rs.add("mongo2.alexcomu")
105+
rs.add("mongo3.alexcomu")
106+
107+
Check the status to identify the primary in replica set. And we're done! Congrats!
108+
109+
### 5 Enable read-mode.
110+
111+
From a secondary node is possible to enable the read mode using this simple command:
112+
113+
rs.slaveOk()
114+
115+

03_arbiter/README.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Arbiter on Replica Set
2+
3+
Arbiters are **mongod** instances that are part of a replica set but do not hold data. Arbiters participate in elections in order to break ties. If a replica set has an even number of members, add an arbiter.
4+
5+
Arbiters have minimal resource requirements and do not require dedicated hardware. You can deploy an arbiter on an application server or a monitoring host.
6+
7+
**IMPORTANT** Do not run an arbiter on the same system as a member of the replica set.
8+
9+
10+
## Add an arbiter on a new machine
11+
12+
Sequence of operation to configure a new arbiter for our replica sets.
13+
14+
### 1 - Create data directory
15+
16+
Create a data directory for the arbiter. The mongod instance uses the directory for configuration data, will not hold the data set.
17+
18+
mkdir /data/arb
19+
20+
### 3 - Start the Arbiter
21+
22+
Start the arbiter specifying the data directory and the replica set name. In our case:
23+
24+
mongod --port 30000 --dbpath /data/arb --replSet rs0
25+
26+
### 4 - Add the arbiter to the set
27+
28+
Connect to the primay node and add the arbiter to the replica set using **rs.addArb()**:
29+
30+
rs.addArb("arbiter1.alexcomu:30000")
31+
32+

0 commit comments

Comments
 (0)