-
-
Save kob-aha/219233ed04cd5d160b4ed313d5dbeab7 to your computer and use it in GitHub Desktop.
Vagrant file to setup a 3-server mongo replica set and a script to intialize the mongod cluster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.vagrant/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NPTEGnxcMh0qtWAn9eYfEgb8z9IXFSM19NSiCgF2vHHyQhz7UHCJz7qE4kaKpljT | |
uzeCH727OKKXcBrQZy/MwW5NG8Bf9xjrYVlcNKwHAXfGf0sZ/ax3mo/XAgv5U5hK | |
8UyWGGnMpUE4C29mjdIIYhvZ0oHyCYyzQER4lvkMZn0VcjjihARCSSrhwFhcL98A | |
lNEvnAgRroapH077rWskA3ZLA8VyLdpu/OBkgzVndix4aKUBrtPtWFNiG062M/Zd | |
7b+nBB93lqOEXqF3m3EeIyOmpTkysM22k7UR5wxM/MBNbmv+AY8n/BcJAYDLSZBU | |
IQDM0cB0+r1tEajkSaKSAnyupunZHcQyL8nGzpJB3Ad7oTEgkA8sMfnEPMwjjha+ | |
5mV//jIaIom8XZP5WQA3KYrYmyURylZ5nAsUl/CCmggjB1277y80v7KKVRoiiBKO | |
fwXWWw6CQjMRqx4CyMy/Vev1m8Q2QbR+45UdZDB2ciO3/PLTTv0RfWacHXdo6Imt | |
BEMIOCnjTWQ3MLbvV4Gk4lugiWiUSCjfjItLph36+P5gRKFq6jnShgjSeR9uz6V/ | |
cvV1jfT+JfSDpDiSRCTv6elONe5kPlrQo7iQ/UzkiiRgXaaJ8+xISJ8Uv24IYyVo | |
b7kLhVXBGRYuYqOFCTvjm6YOUqWKnRmpeVYNg1kmsarKlan3YoNY+8u3Vp72oxpc | |
3inMnTAqt1qoH9pwefVKB8BfNOebuZQvL12x22Ist/zAqOJ71B1g7orZN2XIZXFq | |
8Ivxget3x5uVV/pjx0LjgHNmpYLQv4HMTtIQ3M7irV9QtB6x3cLCUh2nPY+3xl+e | |
S+rTEkuJ9tvqy3xdCQksGV1QL7KMhugJ2MxmJr2cZK7PGAuqlNf/dITKSsK7HXw/ | |
ohy8ja/fDZwragawP1BAuJPU4K0h7voqpDt7Qs/6UYxzoTRgDp2JvmoB8vbpFsV9 | |
js55eudFlhjxoHVSWpfiaGrj4g9IaBryP6EPa8xDvufEFNl9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mongo << 'EOF' | |
config = { _id: "bogus-replica-set", members:[ | |
{ _id : 0, host : "192.168.42.100:27017"}, | |
{ _id : 1, host : "192.168.42.110:27017"}, | |
{ _id : 2, host : "192.168.42.120:27017"} ] | |
}; | |
rs.initiate(config); | |
rs.status(); | |
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! | |
VAGRANTFILE_API_VERSION = "2" | |
$ipTablesScript = <<-"IPTABSCRIPT" | |
REPLICA_MEMBERS="$1" | |
iptables -t filter -A INPUT -s 127.0.0.1,${REPLICA_MEMBERS} -p tcp -m state --state NEW -m tcp --dport 27017 -j ACCEPT | |
iptables -t filter -I OUTPUT -d 127.0.0.1,${REPLICA_MEMBERS} -p tcp -m state --state NEW -m tcp --dport 27017 -j ACCEPT | |
iptables-save > /etc/sysconfig/iptables | |
service iptables restart | |
IPTABSCRIPT | |
$mongoInitScript = <<-"SCRIPT" | |
YUM_REPO_CONFIG_PATH="/etc/yum.repos.d/mongodb-org-3.6.repo" | |
tee $YUM_REPO_CONFIG_PATH <<-"EOF" | |
[mongodb-org-3.6] | |
name=MongoDB Repository | |
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/ | |
gpgcheck=1 | |
enabled=1 | |
gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc | |
EOF | |
yum -y install openssl openssl-devel mongodb-org | |
mkdir /etc/mongo | |
cp /vagrant/keyfile /etc/mongo/ && chmod 400 /etc/mongo/keyfile | |
MONGOD_CONF_FILE="/etc/mongod.conf" | |
tee -a $MONGOD_CONF_FILE <<-"EOF" | |
security: | |
keyFile: /etc/mongo/keyfile | |
replication: | |
oplogSizeMB: 64 | |
replSetName: bogus-replica-set | |
net: | |
bindIpAll: true | |
EOF | |
chown -R mongod:mongod /etc/mongo* | |
service mongod start | |
SCRIPT | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
# All Vagrant configuration is done here. The most common configuration | |
# options are documented and commented below. For a complete reference, | |
# please see the online documentation at vagrantup.com. | |
# Every Vagrant virtual environment requires a box to build off of. | |
config.vm.box = "centos64-x86_64-20171214" | |
config.vm.provider "virtualbox" do |v| | |
v.customize ["modifyvm", :id, "--cpus", "2"] | |
end | |
config.vm.define :mongo1 do |mongo1| | |
mongo1.vm.network :private_network, ip: "192.168.42.100" | |
mongo1.vm.provision "shell", inline: $mongoInitScript | |
mongo1.vm.provision "shell", inline: $ipTablesScript, args: ["192.168.42.110,192.168.42.120"] | |
end | |
config.vm.define :mongo2 do |mongo2| | |
mongo2.vm.network :private_network, ip: "192.168.42.110" | |
mongo2.vm.provision "shell", inline: $mongoInitScript | |
mongo2.vm.provision "shell", inline: $ipTablesScript, args: ["192.168.42.100,192.168.42.120"] | |
end | |
config.vm.define :mongo3 do |mongo3| | |
mongo3.vm.network :private_network, ip: "192.168.42.120" | |
mongo3.vm.provision "shell", inline: $mongoInitScript | |
mongo3.vm.provision "shell", inline: $ipTablesScript, args: ["192.168.42.100,192.168.42.110"] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment