Skip to content

Instantly share code, notes, and snippets.

@wizact
Created January 16, 2016 11:48
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save wizact/dd22f66f3a62287db5ad to your computer and use it in GitHub Desktop.
Preparing and running an aws instance for Mongo
#!/bin/bash
set -e
install_mongo() {
sudo yum -y update
echo "[MongoDB]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0
enabled=1" | sudo tee -a /etc/yum.repos.d/mongodb.repo
sudo yum install -y mongodb-org-server mongodb-org-shell mongodb-org-tools
}
mount_volumes() {
sudo mkdir /data /log /journal
sudo mkfs.ext4 /dev/xvdf
sudo mkfs.ext4 /dev/xvdg
sudo mkfs.ext4 /dev/xvdh
sudo echo '/dev/xvdf /data ext4 defaults,auto,noatime,noexec 0 0
/dev/xvdg /journal ext4 defaults,auto,noatime,noexec 0 0
/dev/xvdh /log ext4 defaults,auto,noatime,noexec 0 0' | tee -a /etc/fstab
sudo mount /data
sudo mount /journal
sudo mount /log
sudo chown mongod:mongod /data /journal /log
sudo ln -s /journal /data/journal
}
update_limits() {
echo "soft nofile 64000
hard nofile 64000
soft nproc 32000
hard nproc 32000" | sudo tee -a /etc/security/limits.conf
sudo "soft nproc 32000
hard nproc 32000" | sudo tee -a /etc/security/limits.d/90-nproc.conf
}
optimize_read() {
sudo blockdev --setra 32 /dev/xvdf
sudo blockdev --setra 32 /dev/xvdg
sudo blockdev --setra 32 /dev/xvdh
echo 'ACTION=="add", KERNEL=="xvdf", ATTR{bdi/read_ahead_kb}="16"
ACTION=="add", KERNEL=="xvdg", ATTR{bdi/read_ahead_kb}="16"
ACTION=="add", KERNEL=="xvdh", ATTR{bdi/read_ahead_kb}="16"' | sudo tee -a /etc/udev/rules.d/85-ebs.rules
}
set_locale() {
echo LC_ALL="en_US.UTF-8" | sudo tee -a /etc/environment
}
install_mongo
mount_volumes
update_limits
optimize_read
set_locale
sudo service mongod start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment