Skip to content

Instantly share code, notes, and snippets.

@braz
Created May 5, 2021 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save braz/85061497d82f103153241dcb51299b43 to your computer and use it in GitHub Desktop.
Save braz/85061497d82f103153241dcb51299b43 to your computer and use it in GitHub Desktop.
Python PIP SNI fix for MDBU M312 vagrant provisioning script
#!/usr/bin/env bash
#
# Bash script for provisioning the MongoDB instances
set -e
set -x
function config(){
export CLIENT_IP_ADDR=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}' | tail -1`
export CLIENT_FQDN=`hostname`
export CLIENT_NAME=`hostname | cut -d. -f 1 | tr '[:upper:]' '[:lower:]'`
echo "Configuring /etc/hosts ..."
echo "127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4" > /etc/hosts
echo "::1 localhost localhost.localdomain localhost6 localhost6.localdomain6" >> /etc/hosts
echo "$CLIENT_IP_ADDR $CLIENT_FQDN $CLIENT_NAME" >> /etc/hosts
}
function install_mongod(){
echo "Install MongoDB Enterprise"
wget -q -O mongodb-linux-x86_64-enterprise-ubuntu1404-3.4.2.tgz https://downloads.mongodb.com/linux/mongodb-linux-x86_64-enterprise-ubuntu1404-3.4.2.tgz?jmp=university
tar xvf mongodb-linux-x86_64-enterprise-ubuntu1404-3.4.2.tgz
sudo mv -f mongodb-linux-x86_64-enterprise-ubuntu1404-3.4.2/bin/* /usr/bin
rm -r mongodb-linux-x86_64-enterprise-ubuntu1404-3.4.2/
rm mongodb-linux-x86_64-enterprise-ubuntu1404-3.4.2.tgz
sudo sh -c "killall mongod; true"
sudo sh -c "sudo su;"
mkdir -p /data
chmod -R 777 /data
chown -R vagrant:vagrant /data
sudo sh -c "exit;"
mkdir -p /data/db
mkdir -p /home/vagrant/data
chmod -R 777 /home/vagrant/data
mkdir -p /home/vagrant/data/authdb
echo "Set LC_ALL=C to .profile"
sudo echo "export LC_ALL=C" >> /home/vagrant/.profile
}
function install_updated_python(){
sudo apt-get install -y build-essential checkinstall
sudo apt-get install -y libreadline-gplv2-dev libncursesw5-dev libssl-dev libffi-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev -y
sudo apt-get install -y wget
sudo apt-get build-dep python2.7 -y
wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
sudo tar xzf Python-2.7.18.tgz
cd Python-2.7.18/
sudo ./configure --enable-optimizations --with-zlib
sudo make
sudo make install
cd ..
sudo ln -fs /usr/local/bin/python /usr/bin/python
curl -o get-pip.py https://bootstrap.pypa.io/pip/2.6/get-pip.py
sudo python get-pip.py
sudo pip install --upgrade pip
}
function install_python_dependencies(){
sudo apt-get install -y python-dev
sudo apt-get install -y python-pip
sudo apt-get install python-setuptools
sudo pip install pymongo --upgrade
sudo pip install docopt --upgrade
sudo pip install faker==3.0.1
sudo apt-get install python-psutil
sudo pip install setuptools==44.1.1
sudo pip install psutil==5.7.2
sudo pip install mtools==1.5.3
}
function update_repo(){
echo "Install MongoDB Enterprise Repository"
echo "deb http://repo.mongodb.com/apt/ubuntu "$(lsb_release -sc)"/mongodb-enterprise/3.3 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-enterprise.list
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
echo "Update Repositoryies"
sudo apt-get update -y
echo "Installing MongoDB Enterprise Dependencies"
sudo apt-get install -y libgssapi-krb5-2 libsasl2-2 libssl1.0.0 libstdc++6 snmp
}
function config(){
sudo su
# disable THP
echo -e "never" > /sys/kernel/mm/transparent_hugepage/enabled
echo -e "never" > /sys/kernel/mm/transparent_hugepage/defrag
# disable mongod upstart service
echo 'manual' | sudo tee /etc/init/mongod.override
}
config
update_repo
install_mongod
install_updated_python
install_python_dependencies
echo "DONE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment